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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
// { dg-do run }
// { dg-additional-options "-std=c++17" }
typedef __PTRDIFF_TYPE__ ptrdiff_t;
extern "C" void abort ();
namespace std {
template<typename T> struct tuple_size;
template<int, typename> struct tuple_element;
}
template <typename T>
class I
{
public:
typedef ptrdiff_t difference_type;
I ();
~I ();
I (T *);
I (const I &);
T &operator * ();
T *operator -> ();
T &operator [] (const difference_type &) const;
I &operator = (const I &);
I &operator ++ ();
I operator ++ (int);
I &operator -- ();
I operator -- (int);
I &operator += (const difference_type &);
I &operator -= (const difference_type &);
I operator + (const difference_type &) const;
I operator - (const difference_type &) const;
template <typename S> friend bool operator == (I<S> &, I<S> &);
template <typename S> friend bool operator == (const I<S> &, const I<S> &);
template <typename S> friend bool operator < (I<S> &, I<S> &);
template <typename S> friend bool operator < (const I<S> &, const I<S> &);
template <typename S> friend bool operator <= (I<S> &, I<S> &);
template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
template <typename S> friend bool operator > (I<S> &, I<S> &);
template <typename S> friend bool operator > (const I<S> &, const I<S> &);
template <typename S> friend bool operator >= (I<S> &, I<S> &);
template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
private:
T *p;
};
template <typename T> I<T>::I () : p (0) {}
template <typename T> I<T>::~I () {}
template <typename T> I<T>::I (T *x) : p (x) {}
template <typename T> I<T>::I (const I &x) : p (x.p) {}
template <typename T> T &I<T>::operator * () { return *p; }
template <typename T> T *I<T>::operator -> () { return p; }
template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
template <typename T>
class J
{
public:
J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
const I<T> &begin ();
const I<T> &end ();
private:
I<T> b, e;
};
template <typename T> const I<T> &J<T>::begin () { return b; }
template <typename T> const I<T> &J<T>::end () { return e; }
struct K
{
template <int N> int &get () { if (N == 0) return c; else if (N == 1) return b; return a; }
int a, b, c;
};
template <> struct std::tuple_size<K> { static constexpr int value = 3; };
template <int N> struct std::tuple_element<N, K> { using type = int; };
struct L
{
int a, b, c;
};
int a[2000];
long b[40];
short c[50];
int d[1024];
K e[1089];
L f[1093];
int results[2000];
template <typename T>
void
baz (I<T> &i)
{
if (*i < 0 || *i >= 2000)
abort ();
results[*i]++;
}
void
baz (int i)
{
if (i < 0 || i >= 2000)
abort ();
results[i]++;
}
void
f1 ()
{
#pragma omp distribute parallel for default(none) shared(a)
for (auto i : a)
baz (i);
}
void
f2 ()
{
#pragma omp distribute parallel for default(none) shared(a)
for (auto &i : a)
if (&i != &a[i])
abort ();
else
baz (i);
}
void
f3 ()
{
#pragma omp distribute parallel for collapse(3) default(none) shared(b, c)
for (auto &i : b)
for (int j = 9; j < 10; j++)
for (auto k : c)
if (&i != &b[i] || i < 0 || i >= 40 || j != 9 || k < 0 || k >= 50)
abort ();
else
baz (i * 50 + k);
}
void
f4 (J<int> j)
{
#pragma omp distribute parallel for default(none) shared(j, a)
for (auto &i : j)
if (&i != &a[i])
abort ();
else
baz (i);
}
void
f5 ()
{
#pragma omp distribute parallel for simd default(none) shared(d, results)
for (auto i : d)
results[i % 1024] += 2 * ((unsigned) i >> 10) + 1;
}
void
f6 (J<K> j)
{
#pragma omp distribute parallel for default(none) shared(j, e)
for (auto & [k, l, m] : j)
if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
abort ();
else
baz (m);
}
void
f7 (J<L> j)
{
#pragma omp distribute parallel for default(none) shared(j, f)
for (auto & [k, l, m] : j)
if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
abort ();
else
baz (k);
}
void
f8 (J<K> j)
{
#pragma omp distribute parallel for default(none) shared(j)
for (auto [k, l, m] : j)
if (k != m * 3 || l != m * 2)
abort ();
else
baz (m);
}
void
f9 (J<L> j)
{
#pragma omp distribute parallel for default(none) shared(j)
for (auto [k, l, m] : j)
if (l != k * 4 || m != k * 5)
abort ();
else
baz (k);
}
template <int N>
void
f10 ()
{
#pragma omp distribute parallel for default(none) shared(a)
for (auto i : a)
baz (i);
}
template <int N>
void
f11 ()
{
#pragma omp distribute parallel for default(none) shared(a)
for (auto &i : a)
if (&i != &a[i])
abort ();
else
baz (i);
}
template <int N>
void
f12 ()
{
#pragma omp distribute parallel for collapse(3) default(none) shared(a, b, c)
for (auto &i : b)
for (I<int> j = I<int> (&a[9]); j < I<int> (&a[10]); j++)
for (auto k : c)
if (&i != &b[i] || i < 0 || i >= 40 || *j != 9 || k < 0 || k >= 50)
abort ();
else
baz (i * 50 + k);
}
template <typename T>
void
f13 (J<T> j)
{
#pragma omp distribute parallel for default(none) shared(j, a)
for (auto &i : j)
if (&i != &a[i])
abort ();
else
baz (i);
}
template <int N>
void
f14 ()
{
#pragma omp distribute parallel for simd default(none) shared(d, results)
for (auto i : d)
results[i % N] += 2 * ((unsigned) i >> 10) + 1;
}
template <typename T>
void
f15 (J<T> j)
{
#pragma omp distribute parallel for default(none) shared(j, e)
for (auto & [k, l, m] : j)
if (&k != &e[m].c || &l != &e[m].b || &m != &e[m].a || k != m * 3 || l != m * 2)
abort ();
else
baz (m);
}
template <typename T>
void
f16 (J<T> j)
{
#pragma omp distribute parallel for default(none) shared(j, f)
for (auto & [k, l, m] : j)
if (&k != &f[k].a || &l != &f[k].b || &m != &f[k].c || l != k * 4 || m != k * 5)
abort ();
else
baz (k);
}
template <int N>
void
f17 (J<K> j)
{
#pragma omp distribute parallel for default(none) shared(j)
for (auto [k, l, m] : j)
if (k != m * 3 || l != m * 2)
abort ();
else
baz (m);
}
template <int N>
void
f18 (J<L> j)
{
#pragma omp distribute parallel for default(none) shared(j)
for (auto [k, l, m] : j)
if (l != k * 4 || m != k * 5)
abort ();
else
baz (k);
}
#define check(expr) \
for (int i = 0; i < 2000; i++) \
if (expr) \
{ \
if (results[i] != 1) \
abort (); \
results[i] = 0; \
} \
else if (results[i]) \
abort ()
int
main ()
{
for (int i = 0; i < 2000; i++)
a[i] = i;
for (int i = 0; i < 40; i++)
b[i] = i;
for (int i = 0; i < 50; i++)
c[i] = i;
for (int i = 0; i < 1024; i++)
d[i] = i;
for (int i = 0; i < 1089; i++)
{
e[i].a = i;
e[i].b = 2 * i;
e[i].c = 3 * i;
}
for (int i = 0; i < 1093; i++)
{
f[i].a = i;
f[i].b = 4 * i;
f[i].c = 5 * i;
}
#pragma omp teams
f1 ();
check (1);
#pragma omp teams
f2 ();
check (1);
#pragma omp teams
f3 ();
check (1);
#pragma omp teams
f4 (J<int> (&a[14], &a[1803]));
check (i >= 14 && i < 1803);
#pragma omp teams
f5 ();
check (i >= 0 && i < 1024);
#pragma omp teams
f6 (J<K> (&e[19], &e[1029]));
check (i >= 19 && i < 1029);
#pragma omp teams
f7 (J<L> (&f[15], &f[1091]));
check (i >= 15 && i < 1091);
#pragma omp teams
f8 (J<K> (&e[27], &e[1037]));
check (i >= 27 && i < 1037);
#pragma omp teams
f9 (J<L> (&f[1], &f[1012]));
check (i >= 1 && i < 1012);
#pragma omp teams
f10 <0> ();
check (1);
#pragma omp teams
f11 <1> ();
check (1);
#pragma omp teams
f12 <2> ();
check (1);
#pragma omp teams
f13 (J<int> (&a[24], &a[1703]));
check (i >= 24 && i < 1703);
#pragma omp teams
f14 <1024> ();
check (i >= 0 && i < 1024);
#pragma omp teams
f15 (J<K> (&e[39], &e[929]));
check (i >= 39 && i < 929);
#pragma omp teams
f16 (J<L> (&f[17], &f[1071]));
check (i >= 17 && i < 1071);
#pragma omp teams
f17 <3> (J<K> (&e[7], &e[1017]));
check (i >= 7 && i < 1017);
#pragma omp teams
f18 <5> (J<L> (&f[121], &f[1010]));
check (i >= 121 && i < 1010);
}
|