1 #include <stdlib.h>
2 #include <unistd.h>
3
4 int
main()5 main ()
6 {
7 int x = 0, y = 0, z = 0, err;
8 int shared_mem = 0;
9 #pragma omp target map(to: shared_mem)
10 shared_mem = 1;
11 #pragma omp parallel
12 #pragma omp single
13 {
14 #pragma omp task depend(in: x)
15 {
16 usleep (5000);
17 x = 1;
18 }
19 #pragma omp task depend(in: x)
20 {
21 usleep (6000);
22 y = 2;
23 }
24 #pragma omp task depend(out: z)
25 {
26 usleep (7000);
27 z = 3;
28 }
29 #pragma omp target enter data map(to: x, y, z) depend(inout: x, z) nowait
30 #pragma omp task depend(inout: x, z)
31 {
32 x++; y++; z++;
33 }
34 #pragma omp target update to(x, y) depend(inout: x) nowait
35 #pragma omp target enter data map(always, to: z) depend(inout: z) nowait
36 #pragma omp target map (alloc: x, y, z) map (from: err) depend(inout: x, z)
37 {
38 err = x != 2 || y != 3 || z != 4;
39 x = 5; y = 6; z = 7;
40 }
41 #pragma omp task depend(in: x)
42 {
43 usleep (5000);
44 if (!shared_mem)
45 x = 1;
46 }
47 #pragma omp task depend(in: x)
48 {
49 usleep (6000);
50 if (!shared_mem)
51 y = 2;
52 }
53 #pragma omp task depend(out: z)
54 {
55 usleep (3000);
56 if (!shared_mem)
57 z = 3;
58 }
59 #pragma omp target exit data map(release: z) depend(inout: z) nowait
60 #pragma omp target exit data map(from: x, y) depend(inout: x) nowait
61 #pragma omp target exit data map(from: z) depend(inout: z) nowait
62 #pragma omp taskwait
63 if (err || x != 5 || y != 6 || z != 7)
64 abort ();
65 }
66 return 0;
67 }
68