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 
19 int 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 enter data map(mapper(id),to: c)
26   #pragma omp target teams distribute parallel for
27   for (int i = 0; i < NUM; i++) {
28     ++c.a[i];
29   }
30   #pragma omp target exit data map(mapper(id),from: c)
31   int sum = 0;
32   for (int i = 0; i < NUM; i++) {
33     sum += c.a[i];
34   }
35   // CHECK: Sum = 2048
36   printf("Sum = %d\n", sum);
37   return 0;
38 }
39 
40