1 #include <stdlib.h>
2 #include <unistd.h>
3 
main()4 int main ()
5 {
6   int a = 0, b = 0, c = 0, d[7];
7 
8   #pragma omp parallel
9   #pragma omp single
10   {
11     #pragma omp task depend(out: d[0])
12       a = 2;
13 
14     #pragma omp target enter data nowait map(to: a,b,c) depend(in: d[0]) depend(out: d[1])
15 
16     #pragma omp target nowait map(alloc: a) depend(in: d[1]) depend(out: d[2])
17       a++;
18 
19     #pragma omp target nowait map(alloc: b) depend(in: d[2]) depend(out: d[3])
20     {
21       usleep (1000);
22       #pragma omp atomic update
23       b |= 4;
24     }
25 
26     #pragma omp target nowait map(alloc: b) depend(in: d[2]) depend(out: d[4])
27     {
28       usleep (5000);
29       #pragma omp atomic update
30       b |= 1;
31     }
32 
33     #pragma omp target nowait map(alloc: c) depend(in: d[3], d[4]) depend(out: d[5])
34     {
35       usleep (5000);
36       #pragma omp atomic update
37       c |= 8;
38     }
39 
40     #pragma omp target nowait map(alloc: c) depend(in: d[3], d[4]) depend(out: d[6])
41     {
42       usleep (1000);
43       #pragma omp atomic update
44       c |= 2;
45     }
46 
47     #pragma omp target exit data map(always,from: a,b,c) depend(in: d[5], d[6])
48   }
49 
50   if (a != 3 || b != 5 || c != 10)
51     abort ();
52 
53   return 0;
54 }
55