Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / monotonic-1.c
blobc3c0100f052d1039095427ab043edc1bb9dac9f2
1 /* { dg-do run } */
3 #ifndef MONOTONIC_TYPE
4 #include <omp.h>
5 #include <stdlib.h>
6 #define MONOTONIC_TYPE int
7 #define MONOTONIC_UNDEF -1
8 #define MONOTONIC_END(n) n
9 #endif
11 int
12 main ()
14 MONOTONIC_TYPE i;
15 #pragma omp parallel
17 int cnt = omp_get_num_threads ();
18 int thr = omp_get_thread_num ();
19 MONOTONIC_TYPE l = MONOTONIC_UNDEF;
20 int c = 0;
21 int n = 0;
22 #pragma omp for nowait schedule(static, 5)
23 for (i = 0; i < MONOTONIC_END (73); i++)
25 if (l == MONOTONIC_UNDEF)
27 n = 1;
28 c++;
30 else if (l == i - 1)
31 n++;
32 else
34 if (l >= i)
35 abort ();
36 if (cnt == 1)
37 abort ();
38 if (n != 5)
39 abort ();
40 n = 1;
41 c++;
43 if (n == 1)
45 if ((i % 5) != 0)
46 abort ();
47 if ((i / 5) % cnt != thr)
48 abort ();
50 l = i;
52 if (cnt == 1)
54 if (n != 73 || l != 73 - 1 || c != 1)
55 abort ();
57 else if (thr > 73 / 5)
59 if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
60 abort ();
62 else if (thr == 73 / 5)
64 if (l != 73 - 1 || c != 1 || n != 73 % 5)
65 abort ();
67 else if (c == 0)
68 abort ();
69 else if (l == 73 - 1)
71 if (thr != (73 / 5) % cnt || n != 73 % 5)
72 abort ();
74 else if ((n % 5) != 0)
75 abort ();
76 l = MONOTONIC_UNDEF;
77 c = 0;
78 n = 0;
79 #pragma omp for schedule( monotonic: static, 7) nowait
80 for (i = 0; i < MONOTONIC_END (73); i++)
82 if (l == MONOTONIC_UNDEF)
84 n = 1;
85 c++;
87 else if (l == i - 1)
88 n++;
89 else
91 if (l >= i)
92 abort ();
93 if (cnt == 1)
94 abort ();
95 if (n != 7)
96 abort ();
97 n = 1;
98 c++;
100 if (n == 1)
102 if ((i % 7) != 0)
103 abort ();
104 if ((i / 7) % cnt != thr)
105 abort ();
107 l = i;
109 if (cnt == 1)
111 if (n != 73 || l != 73 - 1 || c != 1)
112 abort ();
114 else if (thr > 73 / 7)
116 if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
117 abort ();
119 else if (thr == 73 / 7)
121 if (l != 73 - 1 || c != 1 || n != 73 % 7)
122 abort ();
124 else if (c == 0)
125 abort ();
126 else if (l == 73 - 1)
128 if (thr != (73 / 7) % cnt || n != 73 % 7)
129 abort ();
131 else if ((n % 7) != 0)
132 abort ();
133 l = MONOTONIC_UNDEF;
134 c = 0;
135 n = 0;
136 #pragma omp for nowait schedule(static)
137 for (i = 0; i < MONOTONIC_END (73); i++)
139 if (l == MONOTONIC_UNDEF)
141 n = 1;
142 c++;
144 else if (l == i - 1)
145 n++;
146 else
147 abort ();
148 l = i;
150 if (c > 1)
151 abort ();
152 l = MONOTONIC_UNDEF;
153 c = 0;
154 n = 0;
155 #pragma omp for nowait schedule(monotonic,simd:static)
156 for (i = 0; i < MONOTONIC_END (73); i++)
158 if (l == MONOTONIC_UNDEF)
160 n = 1;
161 c++;
163 else if (l == i - 1)
164 n++;
165 else
166 abort ();
167 l = i;
169 if (c > 1)
170 abort ();
171 l = MONOTONIC_UNDEF;
172 c = 0;
173 n = 0;
174 #pragma omp for schedule(monotonic : dynamic, 5) nowait
175 for (i = 0; i < MONOTONIC_END (73); i++)
177 if (l == MONOTONIC_UNDEF)
179 n = 1;
180 c++;
182 else if (l == i - 1)
183 n++;
184 else
186 if (l >= i)
187 abort ();
188 if ((n % 5) != 0 || n == 0)
189 abort ();
190 n = 1;
191 c++;
193 l = i;
195 if (l == 73 - 1)
197 if (n % 5 != 73 % 5)
198 abort ();
200 else if (l == MONOTONIC_UNDEF)
202 if (n != 0 || c != 0)
203 abort ();
205 else if ((n % 5) != 0 || n == 0)
206 abort ();
207 l = MONOTONIC_UNDEF;
208 c = 0;
209 n = 0;
210 #pragma omp for nowait schedule(dynamic, 7) ordered(1)
211 for (i = 0; i < MONOTONIC_END (73); i++)
213 if (l == MONOTONIC_UNDEF)
215 n = 1;
216 c++;
218 else if (l == i - 1)
219 n++;
220 else
222 if (l >= i)
223 abort ();
224 if ((n % 7) != 0 || n == 0)
225 abort ();
226 n = 1;
227 c++;
229 #pragma omp ordered depend(source)
230 if (MONOTONIC_UNDEF > 0)
232 #pragma omp ordered depend(sink: i)
234 else
236 #pragma omp ordered depend(sink: i - 1)
238 l = i;
240 if (l == 73 - 1)
242 if (n % 7 != 73 % 7)
243 abort ();
245 else if (l == MONOTONIC_UNDEF)
247 if (n != 0 || c != 0)
248 abort ();
250 else if ((n % 7) != 0 || n == 0)
251 abort ();
252 l = MONOTONIC_UNDEF;
253 c = 0;
254 n = 0;
255 #pragma omp for schedule (monotonic :guided , 7) nowait
256 for (i = 0; i < MONOTONIC_END (73); i++)
258 if (l == MONOTONIC_UNDEF)
260 n = 1;
261 c++;
263 else if (l == i - 1)
264 n++;
265 else
267 if (l >= i)
268 abort ();
269 if (n < 7)
270 abort ();
271 n = 1;
272 c++;
274 l = i;
276 l = MONOTONIC_UNDEF;
277 c = 0;
278 n = 0;
279 #pragma omp for nowait schedule(guided, 7) ordered
280 for (i = 0; i < MONOTONIC_END (73); i++)
282 if (l == MONOTONIC_UNDEF)
284 n = 1;
285 c++;
287 else if (l == i - 1)
288 n++;
289 else
291 if (l >= i)
292 abort ();
293 if (n < 7)
294 abort ();
295 n = 1;
296 c++;
298 #pragma omp ordered
299 l = i;
302 return 0;