1 | // RUN: %libomptarget-compile-run-and-check-generic |
2 | |
3 | #include <cstdio> |
4 | #include <cstdlib> |
5 | |
6 | #define NUM 1024 |
7 | |
8 | class C { |
9 | public: |
10 | int *a; |
11 | }; |
12 | |
13 | #pragma omp declare mapper(id : C s) map(s.a[0 : NUM]) |
14 | |
15 | int main() { |
16 | C c; |
17 | c.a = (int *)malloc(size: sizeof(int) * NUM); |
18 | for (int i = 0; i < NUM; i++) { |
19 | c.a[i] = 1; |
20 | } |
21 | #pragma omp target teams distribute parallel for map(mapper(id), tofrom : c) |
22 | for (int i = 0; i < NUM; i++) { |
23 | ++c.a[i]; |
24 | } |
25 | int sum = 0; |
26 | for (int i = 0; i < NUM; i++) { |
27 | sum += c.a[i]; |
28 | } |
29 | // CHECK: Sum = 2048 |
30 | printf(format: "Sum = %d\n" , sum); |
31 | return 0; |
32 | } |
33 | |