1 |
735 |
jeremybenn |
// { dg-do run }
|
2 |
|
|
|
3 |
|
|
#include
|
4 |
|
|
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
5 |
|
|
extern "C" void abort ();
|
6 |
|
|
|
7 |
|
|
template
|
8 |
|
|
class I
|
9 |
|
|
{
|
10 |
|
|
public:
|
11 |
|
|
typedef ptrdiff_t difference_type;
|
12 |
|
|
I ();
|
13 |
|
|
~I ();
|
14 |
|
|
I (T *);
|
15 |
|
|
I (const I &);
|
16 |
|
|
T &operator * ();
|
17 |
|
|
T *operator -> ();
|
18 |
|
|
T &operator [] (const difference_type &) const;
|
19 |
|
|
I &operator = (const I &);
|
20 |
|
|
I &operator ++ ();
|
21 |
|
|
I operator ++ (int);
|
22 |
|
|
I &operator -- ();
|
23 |
|
|
I operator -- (int);
|
24 |
|
|
I &operator += (const difference_type &);
|
25 |
|
|
I &operator -= (const difference_type &);
|
26 |
|
|
I operator + (const difference_type &) const;
|
27 |
|
|
I operator - (const difference_type &) const;
|
28 |
|
|
template friend bool operator == (I &, I &);
|
29 |
|
|
template friend bool operator == (const I &, const I &);
|
30 |
|
|
template friend bool operator < (I &, I &);
|
31 |
|
|
template friend bool operator < (const I &, const I &);
|
32 |
|
|
template friend bool operator <= (I &, I &);
|
33 |
|
|
template friend bool operator <= (const I &, const I &);
|
34 |
|
|
template friend bool operator > (I &, I &);
|
35 |
|
|
template friend bool operator > (const I &, const I &);
|
36 |
|
|
template friend bool operator >= (I &, I &);
|
37 |
|
|
template friend bool operator >= (const I &, const I &);
|
38 |
|
|
template friend typename I::difference_type operator - (I &, I &);
|
39 |
|
|
template friend typename I::difference_type operator - (const I &, const I &);
|
40 |
|
|
template friend I operator + (typename I::difference_type , const I &);
|
41 |
|
|
private:
|
42 |
|
|
T *p;
|
43 |
|
|
};
|
44 |
|
|
template I::I () : p (0) {}
|
45 |
|
|
template I::~I () { p = (T *) 0; }
|
46 |
|
|
template I::I (T *x) : p (x) {}
|
47 |
|
|
template I::I (const I &x) : p (x.p) {}
|
48 |
|
|
template T &I::operator * () { return *p; }
|
49 |
|
|
template T *I::operator -> () { return p; }
|
50 |
|
|
template T &I::operator [] (const difference_type &x) const { return p[x]; }
|
51 |
|
|
template I &I::operator = (const I &x) { p = x.p; return *this; }
|
52 |
|
|
template I &I::operator ++ () { ++p; return *this; }
|
53 |
|
|
template I I::operator ++ (int) { return I (p++); }
|
54 |
|
|
template I &I::operator -- () { --p; return *this; }
|
55 |
|
|
template I I::operator -- (int) { return I (p--); }
|
56 |
|
|
template I &I::operator += (const difference_type &x) { p += x; return *this; }
|
57 |
|
|
template I &I::operator -= (const difference_type &x) { p -= x; return *this; }
|
58 |
|
|
template I I::operator + (const difference_type &x) const { return I (p + x); }
|
59 |
|
|
template I I::operator - (const difference_type &x) const { return I (p - x); }
|
60 |
|
|
template bool operator == (I &x, I &y) { return x.p == y.p; }
|
61 |
|
|
template bool operator == (const I &x, const I &y) { return x.p == y.p; }
|
62 |
|
|
template bool operator != (I &x, I &y) { return !(x == y); }
|
63 |
|
|
template bool operator != (const I &x, const I &y) { return !(x == y); }
|
64 |
|
|
template bool operator < (I &x, I &y) { return x.p < y.p; }
|
65 |
|
|
template bool operator < (const I &x, const I &y) { return x.p < y.p; }
|
66 |
|
|
template bool operator <= (I &x, I &y) { return x.p <= y.p; }
|
67 |
|
|
template bool operator <= (const I &x, const I &y) { return x.p <= y.p; }
|
68 |
|
|
template bool operator > (I &x, I &y) { return x.p > y.p; }
|
69 |
|
|
template bool operator > (const I &x, const I &y) { return x.p > y.p; }
|
70 |
|
|
template bool operator >= (I &x, I &y) { return x.p >= y.p; }
|
71 |
|
|
template bool operator >= (const I &x, const I &y) { return x.p >= y.p; }
|
72 |
|
|
template typename I::difference_type operator - (I &x, I &y) { return x.p - y.p; }
|
73 |
|
|
template typename I::difference_type operator - (const I &x, const I &y) { return x.p - y.p; }
|
74 |
|
|
template I operator + (typename I::difference_type x, const I &y) { return I (x + y.p); }
|
75 |
|
|
|
76 |
|
|
template
|
77 |
|
|
class J
|
78 |
|
|
{
|
79 |
|
|
public:
|
80 |
|
|
J(const I &x, const I &y) : b (x), e (y) {}
|
81 |
|
|
const I &begin ();
|
82 |
|
|
const I &end ();
|
83 |
|
|
private:
|
84 |
|
|
I b, e;
|
85 |
|
|
};
|
86 |
|
|
|
87 |
|
|
template const I &J::begin () { return b; }
|
88 |
|
|
template const I &J::end () { return e; }
|
89 |
|
|
|
90 |
|
|
int results[2000];
|
91 |
|
|
|
92 |
|
|
void
|
93 |
|
|
f1 (J x, J y, J z)
|
94 |
|
|
{
|
95 |
|
|
I i, j, k;
|
96 |
|
|
int l, f = 0, n = 0, m = 0;
|
97 |
|
|
#pragma omp parallel shared (i, j, k, l) firstprivate (f) \
|
98 |
|
|
reduction (+:n, m) num_threads (8)
|
99 |
|
|
{
|
100 |
|
|
#pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
|
101 |
|
|
collapse (4)
|
102 |
|
|
for (i = x.begin (); i < x.end (); ++i)
|
103 |
|
|
for (j = y.begin (); j <= y.end (); j += 1)
|
104 |
|
|
for (l = 0; l < 1; l++)
|
105 |
|
|
for (k = z.begin () + 3; k < z.end () - 3; k++)
|
106 |
|
|
if (omp_get_num_threads () == 8
|
107 |
|
|
&& ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
|
108 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
109 |
|
|
n++;
|
110 |
|
|
else
|
111 |
|
|
m++;
|
112 |
|
|
}
|
113 |
|
|
if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
|
114 |
|
|
|| m != 72 || l != 1)
|
115 |
|
|
abort ();
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
void
|
119 |
|
|
f2 (J x, J y, J z)
|
120 |
|
|
{
|
121 |
|
|
int f = 0, n = 0, m = 0;
|
122 |
|
|
#pragma omp parallel for firstprivate (f) reduction (+:n, m) \
|
123 |
|
|
num_threads (8) schedule (static, 9) \
|
124 |
|
|
collapse (6 - 2)
|
125 |
|
|
for (I i = x.end () - 1; i >= x.begin (); --i)
|
126 |
|
|
for (int l = -131; l >= -131; l--)
|
127 |
|
|
for (I j = y.end (); j > y.begin () - 1; j -= 1)
|
128 |
|
|
{
|
129 |
|
|
for (I k = z.end () - 4; k >= z.begin () + 3; k--)
|
130 |
|
|
if (omp_get_num_threads () == 8
|
131 |
|
|
&& ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
|
132 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
133 |
|
|
n++;
|
134 |
|
|
else
|
135 |
|
|
m++;
|
136 |
|
|
}
|
137 |
|
|
if (n || m != 72)
|
138 |
|
|
abort ();
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
template
|
142 |
|
|
void
|
143 |
|
|
f3 (J x, J y, J z)
|
144 |
|
|
{
|
145 |
|
|
I i, j, k;
|
146 |
|
|
int l, f = 0, n = 0, m = 0;
|
147 |
|
|
#pragma omp parallel shared (i, j, k, l) firstprivate (f) \
|
148 |
|
|
reduction (+:n, m) num_threads (8)
|
149 |
|
|
{
|
150 |
|
|
#pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
|
151 |
|
|
collapse (4)
|
152 |
|
|
for (i = x.begin (); i < x.end (); ++i)
|
153 |
|
|
for (j = y.begin (); j <= y.end (); j += 1)
|
154 |
|
|
for (k = z.begin () + 3; k < z.end () - 3; k++)
|
155 |
|
|
for (l = 7; l <= 7; l++)
|
156 |
|
|
if (omp_get_num_threads () == 8
|
157 |
|
|
&& ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
|
158 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
159 |
|
|
n++;
|
160 |
|
|
else
|
161 |
|
|
m++;
|
162 |
|
|
}
|
163 |
|
|
if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
|
164 |
|
|
|| m != 72 || l != 8)
|
165 |
|
|
abort ();
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
template
|
169 |
|
|
void
|
170 |
|
|
f4 (J x, J y, J z)
|
171 |
|
|
{
|
172 |
|
|
int f = 0, n = 0, m = 0;
|
173 |
|
|
#pragma omp parallel for firstprivate (f) reduction (+:n, m) \
|
174 |
|
|
num_threads (8) schedule (static, 9) \
|
175 |
|
|
collapse (5 - 2)
|
176 |
|
|
for (I i = x.end () - 1; i >= x.begin (); --i)
|
177 |
|
|
{
|
178 |
|
|
for (I j = y.end (); j > y.begin () - 1; j -= 1)
|
179 |
|
|
{
|
180 |
|
|
for (I k = z.end () - 4; k >= z.begin () + 3; k--)
|
181 |
|
|
if (omp_get_num_threads () == 8
|
182 |
|
|
&& ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
|
183 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
184 |
|
|
n++;
|
185 |
|
|
else
|
186 |
|
|
m++;
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
if (n || m != 72)
|
190 |
|
|
abort ();
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
template
|
194 |
|
|
void
|
195 |
|
|
f5 (J x, J y, J z)
|
196 |
|
|
{
|
197 |
|
|
I i, j, k;
|
198 |
|
|
int f = 0, n = 0, m = 0;
|
199 |
|
|
#pragma omp parallel shared (i, j, k) firstprivate (f) \
|
200 |
|
|
reduction (+:n, m) num_threads (8)
|
201 |
|
|
{
|
202 |
|
|
#pragma omp for lastprivate (i, j, k) schedule (static, 9) \
|
203 |
|
|
collapse (3)
|
204 |
|
|
for (i = x.begin (); i < x.end (); ++i)
|
205 |
|
|
for (j = y.begin (); j <= y.end (); j += (T) 1)
|
206 |
|
|
{
|
207 |
|
|
for (k = z.begin () + 3; k < z.end () - 3; k++)
|
208 |
|
|
if (omp_get_num_threads () == 8
|
209 |
|
|
&& ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
|
210 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
211 |
|
|
n++;
|
212 |
|
|
else
|
213 |
|
|
m++;
|
214 |
|
|
}
|
215 |
|
|
}
|
216 |
|
|
if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
|
217 |
|
|
|| m != 72)
|
218 |
|
|
abort ();
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
template
|
222 |
|
|
void
|
223 |
|
|
f6 (J x, J y, J z)
|
224 |
|
|
{
|
225 |
|
|
int f = 0, n = 0, m = 0;
|
226 |
|
|
#pragma omp parallel for firstprivate (f) reduction (+:n, m) \
|
227 |
|
|
num_threads (8) schedule (static, 9) \
|
228 |
|
|
collapse (5 - 2)
|
229 |
|
|
for (I i = x.end () - 1; i >= x.begin (); --i)
|
230 |
|
|
{
|
231 |
|
|
for (I j = y.end (); j > y.begin () - 1; j -= 1)
|
232 |
|
|
{
|
233 |
|
|
for (I k = z.end () - 4; k >= z.begin () + (T) 3; k--)
|
234 |
|
|
if (omp_get_num_threads () == 8
|
235 |
|
|
&& ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
|
236 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
237 |
|
|
n++;
|
238 |
|
|
else
|
239 |
|
|
m++;
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
if (n || m != 72)
|
243 |
|
|
abort ();
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
template
|
247 |
|
|
void
|
248 |
|
|
f7 (J x, J y, J z)
|
249 |
|
|
{
|
250 |
|
|
I i, j, k, o = y.begin ();
|
251 |
|
|
T l, f = 0, n = 0, m = 0;
|
252 |
|
|
#pragma omp parallel shared (i, j, k, l) firstprivate (f) \
|
253 |
|
|
reduction (+:n, m) num_threads (8)
|
254 |
|
|
{
|
255 |
|
|
#pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
|
256 |
|
|
collapse (4)
|
257 |
|
|
for (i = x.begin (); i < x.end (); ++i)
|
258 |
|
|
for (j = y.begin (); j <= y.end (); j += 1)
|
259 |
|
|
for (l = *o; l <= *o; l = 1 + l)
|
260 |
|
|
for (k = z.begin () + 3; k < z.end () - 3; k++)
|
261 |
|
|
if (omp_get_num_threads () == 8
|
262 |
|
|
&& ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
|
263 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
264 |
|
|
n++;
|
265 |
|
|
else
|
266 |
|
|
m++;
|
267 |
|
|
}
|
268 |
|
|
if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
|
269 |
|
|
|| m != 72 || l != *o + 1)
|
270 |
|
|
abort ();
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
template
|
274 |
|
|
void
|
275 |
|
|
f8 (J x, J y, J z)
|
276 |
|
|
{
|
277 |
|
|
T f = 0, n = 0, m = 0;
|
278 |
|
|
#pragma omp parallel for firstprivate (f) reduction (+:n, m) \
|
279 |
|
|
num_threads (8) schedule (static, 9) \
|
280 |
|
|
collapse (6 - 2)
|
281 |
|
|
for (I i = x.end () - 1; i >= x.begin (); --i)
|
282 |
|
|
for (T l = 0; l < 1; l++)
|
283 |
|
|
for (I j = y.end (); j > y.begin () - 1; j -= 1)
|
284 |
|
|
{
|
285 |
|
|
for (I k = z.end () - 4; k >= z.begin () + 3; k--)
|
286 |
|
|
if (omp_get_num_threads () == 8
|
287 |
|
|
&& ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
|
288 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
289 |
|
|
n++;
|
290 |
|
|
else
|
291 |
|
|
m++;
|
292 |
|
|
}
|
293 |
|
|
if (n || m != 72)
|
294 |
|
|
abort ();
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
template
|
298 |
|
|
void
|
299 |
|
|
f9 (J x, J y, J z)
|
300 |
|
|
{
|
301 |
|
|
S i, j, k, o = y.begin ();
|
302 |
|
|
T l, f = 0, n = 0, m = 0;
|
303 |
|
|
#pragma omp parallel shared (i, j, k, l) firstprivate (f) \
|
304 |
|
|
reduction (+:n, m) num_threads (8)
|
305 |
|
|
{
|
306 |
|
|
#pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
|
307 |
|
|
collapse (4)
|
308 |
|
|
for (i = x.begin (); i < x.end (); ++i)
|
309 |
|
|
for (j = y.begin (); j <= y.end (); j += 1)
|
310 |
|
|
for (l = *o; l <= *o; l = 1 + l)
|
311 |
|
|
for (k = z.begin () + 3; k < z.end () - 3; k++)
|
312 |
|
|
if (omp_get_num_threads () == 8
|
313 |
|
|
&& ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
|
314 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
315 |
|
|
n++;
|
316 |
|
|
else
|
317 |
|
|
m++;
|
318 |
|
|
}
|
319 |
|
|
if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
|
320 |
|
|
|| m != 72 || l != *o + 1)
|
321 |
|
|
abort ();
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
template
|
325 |
|
|
void
|
326 |
|
|
f10 (J x, J y, J z)
|
327 |
|
|
{
|
328 |
|
|
T f = 0, n = 0, m = 0;
|
329 |
|
|
#pragma omp parallel for firstprivate (f) reduction (+:n, m) \
|
330 |
|
|
num_threads (8) schedule (static, 9) \
|
331 |
|
|
collapse (6 - 2)
|
332 |
|
|
for (S i = x.end () - 1; i >= x.begin (); --i)
|
333 |
|
|
for (T l = 0; l < 1; l++)
|
334 |
|
|
for (S j = y.end (); j > y.begin () - 1; j -= 1)
|
335 |
|
|
{
|
336 |
|
|
for (S k = z.end () - 4; k >= z.begin () + 3; k--)
|
337 |
|
|
if (omp_get_num_threads () == 8
|
338 |
|
|
&& ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
|
339 |
|
|
!= (omp_get_thread_num () * 9 + f++)))
|
340 |
|
|
n++;
|
341 |
|
|
else
|
342 |
|
|
m++;
|
343 |
|
|
}
|
344 |
|
|
if (n || m != 72)
|
345 |
|
|
abort ();
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
int
|
349 |
|
|
main ()
|
350 |
|
|
{
|
351 |
|
|
int a[2000];
|
352 |
|
|
long b[2000];
|
353 |
|
|
for (int i = 0; i < 2000; i++)
|
354 |
|
|
{
|
355 |
|
|
a[i] = i - 1000;
|
356 |
|
|
b[i] = i - 1000;
|
357 |
|
|
}
|
358 |
|
|
J x (&a[998], &a[1004]);
|
359 |
|
|
J y (&a[995], &a[997]);
|
360 |
|
|
J z (&a[1010], &a[1020]);
|
361 |
|
|
f1 (x, y, z);
|
362 |
|
|
f2 (x, y, z);
|
363 |
|
|
f3 (x, y, z);
|
364 |
|
|
f4 (x, y, z);
|
365 |
|
|
f5 (x, y, z);
|
366 |
|
|
f6 (x, y, z);
|
367 |
|
|
f7 (x, y, z);
|
368 |
|
|
f8 (x, y, z);
|
369 |
|
|
f9 , int> (x, y, z);
|
370 |
|
|
f10 , int> (x, y, z);
|
371 |
|
|
}
|