Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / depend-2.c
blob2fe867e2c83f0aa11f8435c560c1df94506f982e
1 #include <omp.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 void
6 test (int ifval)
8 int a[8], b[8], i;
9 omp_depend_t d1, d2;
10 #pragma omp depobj (d1) depend(inout: omp_all_memory)
11 #pragma omp depobj (d2) depend(out: omp_all_memory)
12 for (i = 0; i < 8; i++)
14 a[i] = i;
15 b[i] = 2 * i;
17 #pragma omp parallel
18 #pragma omp single
20 #pragma omp task shared(a) depend(in: a[0])
22 usleep (5000);
23 a[0] = 42;
25 #pragma omp task shared(a) depend(out: a[1])
27 usleep (5000);
28 a[1] = 43;
30 #pragma omp task shared(a) depend(inout: a[2])
32 usleep (5000);
33 a[2] = 44;
35 #pragma omp task shared(a) depend(mutexinoutset: a[3])
37 usleep (5000);
38 a[3] = 45;
40 #pragma omp task shared(a)
42 usleep (15000);
43 a[4] = 46;
45 #pragma omp task shared(b) depend(in: b[0])
47 usleep (5000);
48 b[0] = 47;
50 #pragma omp task shared(b) depend(in: b[4])
52 usleep (5000);
53 b[4] = 48;
55 #pragma omp task shared(b) depend(inoutset: b[5])
57 usleep (5000);
58 b[5] = 49;
60 /* None of the above tasks depend on each other.
61 The following task depends on all but the a[4] = 46; one. */
62 #pragma omp task shared(a, b) depend(depobj: d1) private(i) if(ifval)
64 if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45
65 || a[5] != 5 || a[6] != 6 || a[7] != 7
66 || b[0] != 47 || b[1] != 2 || b[2] != 4 || b[3] != 6
67 || b[4] != 48 || b[5] != 49 || b[6] != 12 || b[7] != 14)
68 abort ();
69 for (i = 0; i < 8; ++i)
70 if (i != 4)
71 a[i] = 3 * i + 7;
72 for (i = 0; i < 8; ++i)
73 b[i] = 4 * i - 7;
75 /* The following task depends on both b[0] = 47; and
76 above omp_all_memory tasks, but as the latter depends on
77 the former, effectively it is dependent just on the omp_all_memory
78 task. */
79 #pragma omp task shared(b) depend(inout: b[0])
81 usleep (5000);
82 b[0] = 49;
84 /* The following task depends on all the above except a[4] = 46; one,
85 but it can be reduced to dependency on the above omp_all_memory
86 one and b[0] = 49; one. */
87 #pragma omp task shared(a, b) depend(inout: b[6]) depend(depobj: d2) \
88 depend(out: b[7]) private(i) if(ifval)
90 for (i = 0; i < 8; ++i)
91 if (i != 4)
93 if (a[i] != 3 * i + 7)
94 abort ();
95 a[i] = 5 * i + 50;
97 if (b[0] != 49)
98 abort ();
99 b[0] = 6 * i + 57;
100 for (i = 1; i < 8; ++i)
102 if (b[i] != 4 * i - 7)
103 abort ();
104 b[i] = 6 * i + 57;
107 #pragma omp taskwait
108 if (a[4] != 46)
109 abort ();
111 #pragma omp depobj (d2) destroy
112 #pragma omp depobj (d1) destroy
116 main ()
118 test (1);
119 test (0);
120 return 0;