Update concepts branch to revision 131834
[official-gcc.git] / libgomp / testsuite / libgomp.c / loop-6.c
blob9029e181bd245e161b06baaf4882293cfe39eedc
1 /* { dg-do run } */
3 #include <omp.h>
5 extern void abort (void);
7 #define LLONG_MAX __LONG_LONG_MAX__
8 #define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
9 #define INT_MAX __INT_MAX__
11 int arr[6 * 5];
13 void
14 set (int loopidx, int idx)
16 #pragma omp atomic
17 arr[loopidx * 5 + idx]++;
20 #define check(var, val, loopidx, idx) \
21 if (var == (val)) set (loopidx, idx); else
22 #define test(loopidx, count) \
23 for (idx = 0; idx < 5; idx++) \
24 if (arr[loopidx * 5 + idx] != idx < count) \
25 abort (); \
26 else \
27 arr[loopidx * 5 + idx] = 0
29 int
30 test1 (void)
32 int e = 0, idx;
34 #pragma omp parallel reduction(+:e)
36 long long i;
37 unsigned long long j;
38 #pragma omp for schedule(dynamic,1) nowait
39 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
41 check (i, LLONG_MAX - 30001, 0, 0)
42 check (i, LLONG_MAX - 20001, 0, 1)
43 check (i, LLONG_MAX - 10001, 0, 2)
44 e = 1;
46 #pragma omp for schedule(dynamic,1) nowait
47 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
49 check (i, -LLONG_MAX + 30000, 1, 0)
50 check (i, -LLONG_MAX + 20000, 1, 1)
51 check (i, -LLONG_MAX + 10000, 1, 2)
52 e = 1;
54 #pragma omp for schedule(dynamic,1) nowait
55 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
57 check (j, 20, 2, 0)
58 e = 1;
60 #pragma omp for schedule(dynamic,1) nowait
61 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
63 check (j, ULLONG_MAX - 3, 3, 0)
64 e = 1;
66 #pragma omp for schedule(dynamic,1) nowait
67 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
69 check (j, LLONG_MAX - 20000ULL, 4, 0)
70 check (j, LLONG_MAX - 10000ULL, 4, 1)
71 check (j, LLONG_MAX, 4, 2)
72 check (j, LLONG_MAX + 10000ULL, 4, 3)
73 e = 1;
75 #pragma omp for schedule(dynamic,1) nowait
76 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
78 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
79 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
80 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
81 check (i, -20000LL + 600LL, 5, 3)
82 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
83 e = 1;
86 if (e)
87 abort ();
88 test (0, 3);
89 test (1, 3);
90 test (2, 1);
91 test (3, 1);
92 test (4, 4);
93 test (5, 5);
94 return 0;
97 int
98 test2 (void)
100 int e = 0, idx;
102 #pragma omp parallel reduction(+:e)
104 long long i;
105 unsigned long long j;
106 #pragma omp for schedule(guided,1) nowait
107 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
109 check (i, LLONG_MAX - 30001, 0, 0)
110 check (i, LLONG_MAX - 20001, 0, 1)
111 check (i, LLONG_MAX - 10001, 0, 2)
112 e = 1;
114 #pragma omp for schedule(guided,1) nowait
115 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
117 check (i, -LLONG_MAX + 30000, 1, 0)
118 check (i, -LLONG_MAX + 20000, 1, 1)
119 check (i, -LLONG_MAX + 10000, 1, 2)
120 e = 1;
122 #pragma omp for schedule(guided,1) nowait
123 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
125 check (j, 20, 2, 0)
126 e = 1;
128 #pragma omp for schedule(guided,1) nowait
129 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
131 check (j, ULLONG_MAX - 3, 3, 0)
132 e = 1;
134 #pragma omp for schedule(guided,1) nowait
135 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
137 check (j, LLONG_MAX - 20000ULL, 4, 0)
138 check (j, LLONG_MAX - 10000ULL, 4, 1)
139 check (j, LLONG_MAX, 4, 2)
140 check (j, LLONG_MAX + 10000ULL, 4, 3)
141 e = 1;
143 #pragma omp for schedule(guided,1) nowait
144 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
146 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
147 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
148 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
149 check (i, -20000LL + 600LL, 5, 3)
150 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
151 e = 1;
154 if (e)
155 abort ();
156 test (0, 3);
157 test (1, 3);
158 test (2, 1);
159 test (3, 1);
160 test (4, 4);
161 test (5, 5);
162 return 0;
166 test3 (void)
168 int e = 0, idx;
170 #pragma omp parallel reduction(+:e)
172 long long i;
173 unsigned long long j;
174 #pragma omp for schedule(static) nowait
175 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
177 check (i, LLONG_MAX - 30001, 0, 0)
178 check (i, LLONG_MAX - 20001, 0, 1)
179 check (i, LLONG_MAX - 10001, 0, 2)
180 e = 1;
182 #pragma omp for schedule(static) nowait
183 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
185 check (i, -LLONG_MAX + 30000, 1, 0)
186 check (i, -LLONG_MAX + 20000, 1, 1)
187 check (i, -LLONG_MAX + 10000, 1, 2)
188 e = 1;
190 #pragma omp for schedule(static) nowait
191 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
193 check (j, 20, 2, 0)
194 e = 1;
196 #pragma omp for schedule(static) nowait
197 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
199 check (j, ULLONG_MAX - 3, 3, 0)
200 e = 1;
202 #pragma omp for schedule(static) nowait
203 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
205 check (j, LLONG_MAX - 20000ULL, 4, 0)
206 check (j, LLONG_MAX - 10000ULL, 4, 1)
207 check (j, LLONG_MAX, 4, 2)
208 check (j, LLONG_MAX + 10000ULL, 4, 3)
209 e = 1;
211 #pragma omp for schedule(static) nowait
212 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
214 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
215 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
216 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
217 check (i, -20000LL + 600LL, 5, 3)
218 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
219 e = 1;
222 if (e)
223 abort ();
224 test (0, 3);
225 test (1, 3);
226 test (2, 1);
227 test (3, 1);
228 test (4, 4);
229 test (5, 5);
230 return 0;
234 test4 (void)
236 int e = 0, idx;
238 #pragma omp parallel reduction(+:e)
240 long long i;
241 unsigned long long j;
242 #pragma omp for schedule(static,1) nowait
243 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
245 check (i, LLONG_MAX - 30001, 0, 0)
246 check (i, LLONG_MAX - 20001, 0, 1)
247 check (i, LLONG_MAX - 10001, 0, 2)
248 e = 1;
250 #pragma omp for schedule(static,1) nowait
251 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
253 check (i, -LLONG_MAX + 30000, 1, 0)
254 check (i, -LLONG_MAX + 20000, 1, 1)
255 check (i, -LLONG_MAX + 10000, 1, 2)
256 e = 1;
258 #pragma omp for schedule(static,1) nowait
259 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
261 check (j, 20, 2, 0)
262 e = 1;
264 #pragma omp for schedule(static,1) nowait
265 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
267 check (j, ULLONG_MAX - 3, 3, 0)
268 e = 1;
270 #pragma omp for schedule(static,1) nowait
271 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
273 check (j, LLONG_MAX - 20000ULL, 4, 0)
274 check (j, LLONG_MAX - 10000ULL, 4, 1)
275 check (j, LLONG_MAX, 4, 2)
276 check (j, LLONG_MAX + 10000ULL, 4, 3)
277 e = 1;
279 #pragma omp for schedule(static,1) nowait
280 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
282 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
283 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
284 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
285 check (i, -20000LL + 600LL, 5, 3)
286 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
287 e = 1;
290 if (e)
291 abort ();
292 test (0, 3);
293 test (1, 3);
294 test (2, 1);
295 test (3, 1);
296 test (4, 4);
297 test (5, 5);
298 return 0;
302 test5 (void)
304 int e = 0, idx;
306 #pragma omp parallel reduction(+:e)
308 long long i;
309 unsigned long long j;
310 #pragma omp for schedule(runtime) nowait
311 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
313 check (i, LLONG_MAX - 30001, 0, 0)
314 check (i, LLONG_MAX - 20001, 0, 1)
315 check (i, LLONG_MAX - 10001, 0, 2)
316 e = 1;
318 #pragma omp for schedule(runtime) nowait
319 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
321 check (i, -LLONG_MAX + 30000, 1, 0)
322 check (i, -LLONG_MAX + 20000, 1, 1)
323 check (i, -LLONG_MAX + 10000, 1, 2)
324 e = 1;
326 #pragma omp for schedule(runtime) nowait
327 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
329 check (j, 20, 2, 0)
330 e = 1;
332 #pragma omp for schedule(runtime) nowait
333 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
335 check (j, ULLONG_MAX - 3, 3, 0)
336 e = 1;
338 #pragma omp for schedule(runtime) nowait
339 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
341 check (j, LLONG_MAX - 20000ULL, 4, 0)
342 check (j, LLONG_MAX - 10000ULL, 4, 1)
343 check (j, LLONG_MAX, 4, 2)
344 check (j, LLONG_MAX + 10000ULL, 4, 3)
345 e = 1;
347 #pragma omp for schedule(runtime) nowait
348 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
350 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
351 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
352 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
353 check (i, -20000LL + 600LL, 5, 3)
354 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
355 e = 1;
358 if (e)
359 abort ();
360 test (0, 3);
361 test (1, 3);
362 test (2, 1);
363 test (3, 1);
364 test (4, 4);
365 test (5, 5);
366 return 0;
370 main (void)
372 if (2 * sizeof (int) != sizeof (long long))
373 return 0;
374 test1 ();
375 test2 ();
376 test3 ();
377 test4 ();
378 omp_set_schedule (omp_sched_static, 0);
379 test5 ();
380 omp_set_schedule (omp_sched_static, 3);
381 test5 ();
382 omp_set_schedule (omp_sched_dynamic, 5);
383 test5 ();
384 omp_set_schedule (omp_sched_guided, 2);
385 test5 ();
386 return 0;