1 /* { dg-do run } */
2
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
10
11 int
12 main ()
13 {
14 MONOTONIC_TYPE i;
15 #pragma omp parallel
16 {
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++)
24 {
25 if (l == MONOTONIC_UNDEF)
26 {
27 n = 1;
28 c++;
29 }
30 else if (l == i - 1)
31 n++;
32 else
33 {
34 if (l >= i)
35 abort ();
36 if (cnt == 1)
37 abort ();
38 if (n != 5)
39 abort ();
40 n = 1;
41 c++;
42 }
43 if (n == 1)
44 {
45 if ((i % 5) != 0)
46 abort ();
47 if ((i / 5) % cnt != thr)
48 abort ();
49 }
50 l = i;
51 }
52 if (cnt == 1)
53 {
54 if (n != 73 || l != 73 - 1 || c != 1)
55 abort ();
56 }
57 else if (thr > 73 / 5)
58 {
59 if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
60 abort ();
61 }
62 else if (thr == 73 / 5)
63 {
64 if (l != 73 - 1 || c != 1 || n != 73 % 5)
65 abort ();
66 }
67 else if (c == 0)
68 abort ();
69 else if (l == 73 - 1)
70 {
71 if (thr != (73 / 5) % cnt || n != 73 % 5)
72 abort ();
73 }
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++)
81 {
82 if (l == MONOTONIC_UNDEF)
83 {
84 n = 1;
85 c++;
86 }
87 else if (l == i - 1)
88 n++;
89 else
90 {
91 if (l >= i)
92 abort ();
93 if (cnt == 1)
94 abort ();
95 if (n != 7)
96 abort ();
97 n = 1;
98 c++;
99 }
100 if (n == 1)
101 {
102 if ((i % 7) != 0)
103 abort ();
104 if ((i / 7) % cnt != thr)
105 abort ();
106 }
107 l = i;
108 }
109 if (cnt == 1)
110 {
111 if (n != 73 || l != 73 - 1 || c != 1)
112 abort ();
113 }
114 else if (thr > 73 / 7)
115 {
116 if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
117 abort ();
118 }
119 else if (thr == 73 / 7)
120 {
121 if (l != 73 - 1 || c != 1 || n != 73 % 7)
122 abort ();
123 }
124 else if (c == 0)
125 abort ();
126 else if (l == 73 - 1)
127 {
128 if (thr != (73 / 7) % cnt || n != 73 % 7)
129 abort ();
130 }
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++)
138 {
139 if (l == MONOTONIC_UNDEF)
140 {
141 n = 1;
142 c++;
143 }
144 else if (l == i - 1)
145 n++;
146 else
147 abort ();
148 l = i;
149 }
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++)
157 {
158 if (l == MONOTONIC_UNDEF)
159 {
160 n = 1;
161 c++;
162 }
163 else if (l == i - 1)
164 n++;
165 else
166 abort ();
167 l = i;
168 }
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++)
176 {
177 if (l == MONOTONIC_UNDEF)
178 {
179 n = 1;
180 c++;
181 }
182 else if (l == i - 1)
183 n++;
184 else
185 {
186 if (l >= i)
187 abort ();
188 if ((n % 5) != 0 || n == 0)
189 abort ();
190 n = 1;
191 c++;
192 }
193 l = i;
194 }
195 if (l == 73 - 1)
196 {
197 if (n % 5 != 73 % 5)
198 abort ();
199 }
200 else if (l == MONOTONIC_UNDEF)
201 {
202 if (n != 0 || c != 0)
203 abort ();
204 }
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++)
212 {
213 if (l == MONOTONIC_UNDEF)
214 {
215 n = 1;
216 c++;
217 }
218 else if (l == i - 1)
219 n++;
220 else
221 {
222 if (l >= i)
223 abort ();
224 if ((n % 7) != 0 || n == 0)
225 abort ();
226 n = 1;
227 c++;
228 }
229 #pragma omp ordered depend(source)
230 if (MONOTONIC_UNDEF > 0)
231 {
232 #pragma omp ordered depend(sink: i)
233 }
234 else
235 {
236 #pragma omp ordered depend(sink: i - 1)
237 }
238 l = i;
239 }
240 if (l == 73 - 1)
241 {
242 if (n % 7 != 73 % 7)
243 abort ();
244 }
245 else if (l == MONOTONIC_UNDEF)
246 {
247 if (n != 0 || c != 0)
248 abort ();
249 }
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++)
257 {
258 if (l == MONOTONIC_UNDEF)
259 {
260 n = 1;
261 c++;
262 }
263 else if (l == i - 1)
264 n++;
265 else
266 {
267 if (l >= i)
268 abort ();
269 if (n < 7)
270 abort ();
271 n = 1;
272 c++;
273 }
274 l = i;
275 }
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++)
281 {
282 if (l == MONOTONIC_UNDEF)
283 {
284 n = 1;
285 c++;
286 }
287 else if (l == i - 1)
288 n++;
289 else
290 {
291 if (l >= i)
292 abort ();
293 if (n < 7)
294 abort ();
295 n = 1;
296 c++;
297 }
298 #pragma omp ordered
299 l = i;
300 }
301 }
302 return 0;
303 }