aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/taskloop-7.C
blob: b9a3c81e381fcf0467ea403c3284c53ac16d6dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// { dg-do run }

#include <vector>
#include <cstdlib>

template <typename T>
class J
{
public:
  typedef typename std::vector<T>::const_iterator const_iterator;
  J(const const_iterator &x, const const_iterator &y) : b (x), e (y) {}
  const const_iterator &begin ();
  const const_iterator &end ();
private:
  const_iterator b, e;
};

template <typename T>
const typename std::vector<T>::const_iterator &J<T>::begin () { return b; }
template <typename T>
const typename std::vector<T>::const_iterator &J<T>::end () { return e; }

int results[2000];

template <typename T>
void
baz (T &i)
{
  if (*i < 0 || *i >= 2000)
    std::abort ();
  results[*i]++;
}

void
f1 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (std::vector<int>::const_iterator i = x; i <= y; i += 6)
    baz (i);
}

void
f2 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
  std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop private(i)
  for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
    baz (i);
}

template <typename T>
void
f3 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (std::vector<int>::const_iterator i = x; i <= y; i = i + 9 - 8)
    baz (i);
}

template <typename T>
void
f4 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
  std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x + 2000 - 64; i > y + 10; --i)
    baz (i);
}

void
f5 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (std::vector<int>::const_iterator i = x + 2000 - 64; i > y + 10; i -= 10)
    baz (i);
}

template <int N>
void
f6 (const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (std::vector<int>::const_iterator i = x + 2000 - 64;
       i > y + 10; i = i - 12 + 2)
    {
      std::vector<int>::const_iterator j = i + N;
      baz (j);
    }
}

template <int N>
void
f7 (std::vector<int>::const_iterator i,
    const std::vector<int>::const_iterator &x,
    const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (i = x - 10; i <= y + 10; i += N)
    baz (i);
}

template <int N>
void
f8 (J<int> j)
{
  std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (i = j.begin (); i <= j.end () + N; i += 2)
    baz (i);
}

template <typename T, int N>
void
f9 (const typename std::vector<T>::const_iterator &x,
    const typename std::vector<T>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (typename std::vector<T>::const_iterator i = x; i <= y; i = i + N)
    baz (i);
}

template <typename T, int N>
void
f10 (const typename std::vector<T>::const_iterator &x,
     const typename std::vector<T>::const_iterator &y)
{
  typename std::vector<T>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (i = x; i > y; i = i + N)
    baz (i);
}

template <typename T>
void
f11 (const T &x, const T &y)
{
#pragma omp parallel
  {
#pragma omp single nowait
#pragma omp taskloop nogroup
    for (T i = x; i <= y; i += 3)
      baz (i);
#pragma omp single nowait
    {
      T j = y + 3;
      baz (j);
    }
  }
}

template <typename T>
void
f12 (const T &x, const T &y)
{
  T i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
  for (i = x; i > y; --i)
    baz (i);
}

template <int N>
struct K
{
  template <typename T>
  static void
  f13 (const T &x, const T &y)
  {
#pragma omp parallel
#pragma omp single
#pragma omp taskloop
    for (T i = x; i <= y + N; i += N)
      baz (i);
  }
};

std::vector<int>::const_iterator
f14 (const std::vector<int>::const_iterator &x,
     const std::vector<int>::const_iterator &y)
{
  std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
    baz (i);
  return i;
}

template <typename T>
std::vector<int>::const_iterator
f15 (const std::vector<int>::const_iterator &x,
     const std::vector<int>::const_iterator &y)
{
  std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x + 2000 - 64; i > y + 10; --i)
    baz (i);
  return i;
}

template <int N>
std::vector<int>::const_iterator
f16 (std::vector<int>::const_iterator i,
     const std::vector<int>::const_iterator &x,
     const std::vector<int>::const_iterator &y)
{
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x - 10; i <= y + 10; i += N)
    baz (i);
  return i;
}

template <int N>
std::vector<int>::const_iterator
f17 (J<int> j)
{
  static std::vector<int>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = j.begin (); i <= j.end () + N; i += 2)
    baz (i);
  return i;
}

template <typename T, int N>
typename std::vector<T>::const_iterator
f18 (const typename std::vector<T>::const_iterator &x,
     const typename std::vector<T>::const_iterator &y)
{
  static typename std::vector<T>::const_iterator i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x; i > y; i = i + N)
    baz (i);
  return i;
}

template <typename T>
T
f19 (const T &x, const T &y)
{
  T i;
#pragma omp parallel
  {
#pragma omp single nowait
#pragma omp taskloop nogroup lastprivate(i)
    for (i = x; i <= y; i += 3)
      baz (i);
#pragma omp single nowait
    {
      T j = y + 3;
      baz (j);
    }
  }
  return i;
}

template <typename T>
T
f20 (const T &x, const T &y)
{
  T i;
#pragma omp parallel
#pragma omp single
#pragma omp taskloop lastprivate(i)
  for (i = x; i > y; --i)
    baz (i);
  return i;
}

#define check(expr) \
  for (int i = 0; i < 2000; i++)			\
    if (expr)						\
      {							\
	if (results[i] != 1)				\
	  std::abort ();				\
	results[i] = 0;					\
      }							\
    else if (results[i])				\
      std::abort ()

int
main ()
{
  std::vector<int> a(2000);
  std::vector<long> b(2000);
  for (int i = 0; i < 2000; i++)
    {
      a[i] = i;
      b[i] = i;
    }
  f1 (a.begin () + 10, a.begin () + 1990);
  check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
  f2 (a.begin () + 0, a.begin () + 1999);
  check (i < 1998 && (i & 1) == 0);
  f3<char> (a.begin () + 20, a.begin () + 1837);
  check (i >= 20 && i <= 1837);
  f4<int> (a.begin () + 0, a.begin () + 30);
  check (i > 40 && i <= 2000 - 64);
  f5 (a.begin () + 0, a.begin () + 100);
  check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  f6<-10> (a.begin () + 10, a.begin () + 110);
  check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  f7<6> (std::vector<int>::const_iterator (), a.begin () + 12,
	 a.begin () + 1800);
  check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
  f8<121> (J<int> (a.begin () + 14, a.begin () + 1803));
  check (i >= 14 && i <= 1924 && (i & 1) == 0);
  f9<int, 7> (a.begin () + 33, a.begin () + 1967);
  check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
  f10<int, -7> (a.begin () + 1939, a.begin () + 17);
  check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  f11<std::vector<int>::const_iterator > (a.begin () + 16, a.begin () + 1981);
  check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  f12<std::vector<int>::const_iterator > (a.begin () + 1761, a.begin () + 37);
  check (i > 37 && i <= 1761);
  K<5>::f13<std::vector<int>::const_iterator > (a.begin () + 1,
						a.begin () + 1935);
  check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
  if (f14 (a.begin () + 0, a.begin () + 1999) != a.begin () + 1998)
    std::abort ();
  check (i < 1998 && (i & 1) == 0);
  if (f15<int> (a.begin () + 0, a.begin () + 30) != a.begin () + 40)
    std::abort ();
  check (i > 40 && i <= 2000 - 64);
  if (f16<6> (std::vector<int>::const_iterator (), a.begin () + 12,
	      a.begin () + 1800) != a.begin () + 1814)
    std::abort ();
  check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
  if (f17<121> (J<int> (a.begin () + 14, a.begin () + 1803)) != a.begin () + 1926)
    std::abort ();
  check (i >= 14 && i <= 1924 && (i & 1) == 0);
  if (f18<int, -7> (a.begin () + 1939, a.begin () + 17) != a.begin () + 14)
    std::abort ();
  check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  if (f19<std::vector<int>::const_iterator > (a.begin () + 16, a.begin () + 1981)
      != a.begin () + 1984)
    std::abort ();
  check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  if (f20<std::vector<int>::const_iterator > (a.begin () + 1761, a.begin () + 37)
      != a.begin () + 37)
    std::abort ();
  check (i > 37 && i <= 1761);
  f9<long, 7> (b.begin () + 33, b.begin () + 1967);
  check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
  f10<long, -7> (b.begin () + 1939, b.begin () + 17);
  check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  f11<std::vector<long>::const_iterator > (b.begin () + 16, b.begin () + 1981);
  check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  f12<std::vector<long>::const_iterator > (b.begin () + 1761, b.begin () + 37);
  check (i > 37 && i <= 1761);
  K<5>::f13<std::vector<long>::const_iterator > (b.begin () + 1,
						 b.begin () + 1935);
  check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
  if (f18<long, -7> (b.begin () + 1939, b.begin () + 17) != b.begin () + 14)
    std::abort ();
  check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  if (f19<std::vector<long>::const_iterator > (b.begin () + 16, b.begin () + 1981)
      != b.begin () + 1984)
    std::abort ();
  check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  if (f20<std::vector<long>::const_iterator > (b.begin () + 1761, b.begin () + 37)
      != b.begin () + 37)
    std::abort ();
  check (i > 37 && i <= 1761);
}