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