1

I have an array of struct A that has arrays and int variables. How can I map them to the target

Strcut A{
    int **a;
    int *x;
    int *y;  
    int ny;
    int nx;
}A;
A arrayA = (A*)malloc(sizeof(A)*MaxSize);
for(int i=0; i<MaxSize; i++){
    arrayA[i].a = (int**)(malloc(sizeof(int*)*arrayA[i].nx);
    for(int j=0; j< arrayA[i].nx; j++)
       arrayA[i].a[j] = (int*)(malloc(sizeof(int)*arrayA[i].ny); 
    arrayA[i].x = (int*)(malloc(sizeof(int)*arrayA[i].ny);
    arrayA[i].y = (int*)(malloc(sizeof(int)*arrayA[i].ny);
}
#pragma omp target data map(from:arrayA[i].y) map(to:arrayA[i].x,arrayA[i].a, arrayA[i].ny,arrayA[i].nx)
#pragma omp target teams distribute parallel for
 for(i=0;i<MaxSize; i++){
    methodA(arrayA[i].x,arrayA[i].a, arrayA[i].ny,arrayA[i].nx, arrayA[i].y);
}

However, this does not work. What is the best way to pass the arrayA?

I am using gcc 8.3

Taghreed
  • 11
  • 1
  • Can you be more specific with your statement "this does not work"? What exactly is not working? – Z boson Nov 01 '18 at 08:38
  • The error is error: expected ‘)’ before ‘.’ token #pragma omp target data map(tofrom:dataCPU[i].n, – Taghreed Nov 02 '18 at 16:39

1 Answers1

0

Simply using

map(tofrom:arrayA)

should do the trick.

If this doesn't work please supply us with the errors you receive.

Do you have the target's software installed correctly (nvcc - Nvidia compiler)? Refer to this question to ensure that it is set up. If not, download the toolkit from here.

EDIT:

The code below compiled:

typedef struct{
    int **a;
    int *x;
    int *y;  
    int ny;
    int nx;
} A;
A *arrayA = (A*)malloc(sizeof(A) * maxSize);
for(int i=0; i<maxSize; i++){
    arrayA[i].a = (int**)(malloc(sizeof(int*)*arrayA[i].nx));
    for(int j=0; j< arrayA[i].nx; j++)
        arrayA[i].a[j] = (int*)(malloc(sizeof(int)*arrayA[i].ny)); 
    arrayA[i].x = (int*)(malloc(sizeof(int)*arrayA[i].ny));
    arrayA[i].y = (int*)(malloc(sizeof(int)*arrayA[i].ny));
}
#pragma omp target data map(tofrom:arrayA)
#pragma omp target teams distribute parallel for
for(int i=0;i<maxSize; i++){
    methodA(arrayA[i].x,arrayA[i].a, arrayA[i].ny,arrayA[i].nx, arrayA[i].y);
}
CYBERCAV
  • 151
  • 6
  • The error is expected ‘)’ before ‘.’ token #pragma omp target data map(tofrom:arrayA[i].n – Taghreed Nov 02 '18 at 16:43
  • Oh right, you're supposed to only give the reference to the array. Thus `map(tofrom:arrayA)`. – CYBERCAV Nov 02 '18 at 17:05
  • It did compile, but it does not work correctly in the device. It gave this error: libgomp: cuCtxSynchronize error: an illegal memory access was encountered libgomp: cuMemFreeHost error: an illegal memory access was encountered – Taghreed Nov 12 '18 at 18:03