xref: /llvm-project/offload/test/mapping/firstprivate_aligned.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
2 
3 #include <stdio.h>
4 
5 // CHECK: rx: 16, ry: 16;
6 // CHECK: rx: 16, ry: 16;
7 // CHECK: rx: 16, ry: 16;
8 // CHECK: rx: 16, ry: 16;
9 
test()10 template <bool Aligned> void test() {
11   printf("Test %saligned firstprivate\n", Aligned ? "" : "non-");
12   char z1[3 + Aligned], z2[3 + Aligned];
13   int x[4];
14   int y[4];
15   y[0] = y[1] = y[2] = y[3] = 4;
16   x[0] = x[1] = x[2] = x[3] = 4;
17   int rx = -1, ry = -1;
18 #pragma omp target firstprivate(z1, y, z2) map(from : ry, rx) map(to : x)
19   {
20     ry = (y[0] + y[1] + y[2] + y[3]);
21     rx = (x[0] + x[1] + x[2] + x[3]);
22   }
23   printf(" rx:%i, ry:%i\n", rx, ry);
24 #pragma omp target firstprivate(z1, y, z2) map(from : ry, rx) map(to : x)
25   {
26     z1[2] += 5;
27     ry = (y[0] + y[1] + y[2] + y[3]);
28     rx = (x[0] + x[1] + x[2] + x[3]);
29     z2[2] += 7;
30   }
31   printf(" rx:%i, ry:%i\n", rx, ry);
32 }
33 
main()34 int main() {
35   test<true>();
36   test<false>();
37 }
38