Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ruixin_L_
Beginner
21 Views

Problem of offloading 2-D Array

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    int* p1[10];
    int* p2[10];
    int start[10];
    int len[10];
    for(int i=0;i<10;i++)
    {
        p1=new int[(i+1)*1000];
        p2=new int[(i+1)*1000];
        len=(i+1)*1000;
        start=0;
    }
    /*
        #pragma offload target(mic)\
        nocopy(p1[0:10]:\
        extent(start[0:10]:len[0:10]) alloc_if(1) free_if(0))\
        nocopy(p2[0:10]:\
        extent(start[0:10]:len[0:10]) alloc_if(1) free_if(0))
        {
            ;
        }
    */
    printf("init \n");
    
    int count=0;
    while(true)
    {
        #pragma offload target(mic)\
        in(p1[0:10]:\
        extent(start[0:10]:len[0:10]) alloc_if(1) free_if(1))\
        out(p2[0:10]:\
        extent(start[0:10]:len[0:10]) alloc_if(1) free_if(1))
        {
            
            for(int i=0;i<10;i++)
            {
                memcpy(p2,p1,(i+1)*1000*sizeof(int));
            }
            
        }
        printf("%d\n",count++);
    }
    
    return 0;
}

 

I try to offload 2-D Array and copy the memory.But it crash at 

memcpy(p2,p1,(i+1)*1000*sizeof(int));

I have no idea why it crash.

By the way,In another program ,some times the program will stuck at a very simple offload statement and it seems to sleep forever.

0 Kudos
0 Replies