1 // RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu 2 // RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu 3 // RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu 4 // RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu 5 // RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda 6 7 #include <cstdio> 8 #include <cstdlib> 9 10 #define NUM 1024 11 12 class C { 13 public: 14 int *a; 15 }; 16 17 #pragma omp declare mapper(id: C s) map(s.a[0:NUM]) 18 main()19int main() { 20 C c; 21 c.a = (int*) malloc(sizeof(int)*NUM); 22 for (int i = 0; i < NUM; i++) { 23 c.a[i] = 1; 24 } 25 #pragma omp target data map(mapper(id),tofrom: c) 26 { 27 #pragma omp target teams distribute parallel for 28 for (int i = 0; i < NUM; i++) { 29 ++c.a[i]; 30 } 31 } 32 int sum = 0; 33 for (int i = 0; i < NUM; i++) { 34 sum += c.a[i]; 35 } 36 // CHECK: Sum = 2048 37 printf("Sum = %d\n", sum); 38 return 0; 39 } 40 41