How do I map an array of pointers using array notation

Hi,
As this

int *a[1024];
#pragma omp target parallel for map(tofrom: a[0:1024][0:1])

does not compile. How do I move data to the device properly?

You have to “enter data” for each element of the array. Something like:

#pragma omp target enter data map(alloc: a[0:1024])

for(int i=0; i<1024; i++)

#pragma omp target enter data map(to: a[i][0:1])

#pragma omp target map(alloc: a)

{

}

for(int i=0; i<1024; i++)

#pragma omp target exit data map(from: a[i][0:1])

#pragma omp target exit data map(alloc: a[0:1024])

George

I am getting:
$ cat t1.cpp#include
int main() {
int *a[1024];

#pragma omp target enter data map(alloc: a[0:1024])
for (int i=0;i<1024;i++)
#pragma omp target enter data map(to: a[i][0:1])

#pragma omp target map(alloc: a)
{

}

}
t1.cpp:8:27: error: ‘#pragma omp target enter data’ cannot be an immediate substatement
#pragma omp target enter data map(to: a[i][0:1])
^
1 error generated.

Use brackets:

#pragma omp target enter data map(alloc: a[0:1024])

for(int i=0; i<1024; i++) {

#pragma omp target enter data map(to: a[i][0:1])

}

George

Enclose it in braces

Best regards,
Alexey Bataev