1 extern "C" void abort ();
2 
3 struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
4 
5 int S::cnt1;
6 int S::cnt2;
7 int S::cnt3;
8 
S()9 S::S ()
10 {
11   #pragma omp atomic
12   cnt1++;
13 }
14 
S(long int x,long int y)15 S::S (long int x, long int y) : s (x), t (y)
16 {
17   #pragma omp atomic update
18   ++cnt2;
19 }
20 
~S()21 S::~S ()
22 {
23   #pragma omp atomic
24   cnt3 = cnt3 + 1;
25   if (t < 3 || t > 9 || (t & 1) == 0)
26     abort ();
27 }
28 
29 void
bar(S * p,S * o)30 bar (S *p, S *o)
31 {
32   p->s = 1;
33   if (o->t != 5)
34     abort ();
35   p->t = 9;
36 }
37 
38 static inline void
baz(S * o,S * i)39 baz (S *o, S *i)
40 {
41   if (o->t != 5 || i->t != 9)
42     abort ();
43   o->s *= i->s;
44 }
45 
46 #pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
47 #pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
48 
49 S a[2] = { { 0, 7 }, { 0, 7 } };
50 S b[7] = { { 9, 5 }, { 11, 5 }, { 1, 5 }, { 1, 5 }, { 1, 5 }, { 13, 5 }, { 15, 5 } };
51 S e[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
52 S f[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
53 S g[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
54 S h[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
55 S k[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
56 S *s;
57 S (*t)[2];
58 
59 void
foo(int n,S * c,S * d,S m[3],S * r,S o[4],S * p,S q[4][2])60 foo (int n, S *c, S *d, S m[3], S *r, S o[4], S *p, S q[4][2])
61 {
62   int i;
63   #pragma omp taskloop in_reduction (+: a, c[:2]) in_reduction (*: b[2 * n:3 * n], d[0:2]) \
64 		       in_reduction (+: o[n:n*2], m[1], k[1:2][:], p[0], f[2:2]) \
65 		       in_reduction (+: q[1:2][:], g[n:n*2], e[1], h[0], r[2:2]) \
66 		       in_reduction (*: s[1:2], t[2:2][:]) nogroup
67   for (i = 0; i < 2; i++)
68     {
69       a[0].s += 7;
70       a[1].s += 17;
71       b[2].s *= 2;
72       b[4].s *= 2;
73       c[0].s += 6;
74       d[1].s *= 2;
75       e[1].s += 19;
76       f[2].s += 21;
77       f[3].s += 23;
78       g[1].s += 25;
79       g[2].s += 27;
80       h[0].s += 29;
81       k[1][0].s += 31;
82       k[2][1].s += 33;
83       m[1].s += 19;
84       r[2].s += 21;
85       r[3].s += 23;
86       o[1].s += 25;
87       o[2].s += 27;
88       p[0].s += 29;
89       q[1][0].s += 31;
90       q[2][1].s += 33;
91       s[1].s *= 2;
92       t[2][0].s *= 2;
93       t[3][1].s *= 2;
94       if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
95 	  || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
96 	abort ();
97       for (int z = 0; z < 2; z++)
98 	if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
99 	    || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
100 	    || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
101 	    || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
102 	    || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
103 	    || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
104 	    || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
105 	  abort ();
106       for (int z = 0; z < 3; z++)
107 	if (b[z + 2].t != 5 && b[z + 2].t != 9)
108 	  abort ();
109     }
110 }
111 
112 void
test(int n)113 test (int n)
114 {
115   S c[2] = { { 0, 7 }, { 0, 7 } };
116   S p[3] = { { 0, 7 }, { 1, 7 }, { 4, 7 } };
117   S q[4][2] = { { { 5, 7 }, { 6, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 0, 7 }, { 0, 7 } }, { { 7, 7 }, { 8, 7 } } };
118   S ss[4] = { { 5, 5 }, { 1, 5 }, { 1, 5 }, { 6, 5 } };
119   S tt[5][2] = { { { 9, 5 }, { 10, 5 } }, { { 11, 5 }, { 12, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 1, 5 }, { 1, 5 } }, { { 13, 5 }, { 14, 5 } } };
120   s = ss;
121   t = tt;
122   #pragma omp parallel
123   #pragma omp single
124   {
125     S d[] = { { 1, 5 }, { 1, 5 } };
126     S m[3] = { { 5, 7 }, { 0, 7 }, { 5, 7 } };
127     S r[5] = { { 6, 7 }, { 7, 7 }, { 0, 7 }, { 0, 7 }, { 9, 7 } };
128     S o[4] = { { 1, 7 }, { 0, 7 }, { 0, 7 }, { 2, 7 } };
129     int i;
130     #pragma omp taskloop reduction (+: a, c) reduction (*: b[2 * n:3 * n], d) \
131 			 reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][0:2]) \
132 			 reduction (+: o[n:n*2], m[1], q[1:2][:], p[0], r[2:2]) \
133 			 reduction (*: t[2:2][:], s[1:n + 1])
134     for (i = 0; i < 4; i++)
135       {
136 	int j;
137 	a[0].s += 2;
138 	a[1].s += 3;
139 	b[2].s *= 2;
140 	f[3].s += 8;
141 	g[1].s += 9;
142 	g[2].s += 10;
143 	h[0].s += 11;
144 	k[1][1].s += 13;
145 	k[2][1].s += 15;
146 	m[1].s += 16;
147 	r[2].s += 8;
148 	s[1].s *= 2;
149 	t[2][1].s *= 2;
150 	t[3][1].s *= 2;
151 	if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
152 	     || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
153 	  abort ();
154 	for (int z = 0; z < 2; z++)
155 	  if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
156 	       || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
157 	       || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
158 	       || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
159 	       || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
160 	       || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
161 	       || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
162 	    abort ();
163 	for (int z = 0; z < 3; z++)
164 	  if (b[z + 2].t != 5 && b[z + 2].t != 9)
165 	    abort ();
166 	#pragma omp taskloop in_reduction (+: a, c[:2]) \
167 			     in_reduction (*: b[2 * n:3 * n], d[n - 1:n + 1]) \
168 			     in_reduction (+: e[1], f[2:2], g[n:n*2], h[0], k[1:2][:2]) \
169 			     in_reduction (+: m[1], r[2:2], o[n:n*2], p[0], q[1:2][:2]) \
170 			     in_reduction (*: s[n:2], t[2:2][:]) nogroup
171 	for (j = 0; j < 2; j++)
172 	  {
173 	    m[1].s += 6;
174 	    r[2].s += 7;
175 	    q[1][0].s += 17;
176 	    q[2][0].s += 19;
177 	    a[0].s += 4;
178 	    a[1].s += 5;
179 	    b[3].s *= 2;
180 	    b[4].s *= 2;
181 	    f[3].s += 18;
182 	    g[1].s += 29;
183 	    g[2].s += 18;
184 	    h[0].s += 19;
185 	    s[2].s *= 2;
186 	    t[2][0].s *= 2;
187 	    t[3][0].s *= 2;
188 	    foo (n, c, d, m, r, o, p, q);
189 	    if ((e[1].t != 7 && e[1].t != 3) || (h[0].t != 7 && h[0].t != 3)
190 		 || (m[1].t != 7 && m[1].t != 3) || (p[0].t != 7 && p[0].t != 3))
191 	      abort ();
192 	    for (int z = 0; z < 2; z++)
193 	      if ((a[z].t != 7 && a[z].t != 3) || (c[z].t != 7 && c[z].t != 3)
194 		   || (d[z].t != 5 && d[z].t != 9) || (f[z + 2].t != 7 && f[z + 2].t != 3)
195 		   || (g[z + 1].t != 7 && g[z + 1].t != 3) || (r[z + 2].t != 7 && r[z + 2].t != 3)
196 		   || (s[z + 1].t != 5 && s[z + 1].t != 9) || (o[z + 1].t != 7 && o[z + 1].t != 3)
197 		   || (k[z + 1][0].t != 7 && k[z + 1][0].t != 3) || (k[z + 1][1].t != 7 && k[z + 1][1].t != 3)
198 		   || (q[z + 1][0].t != 7 && q[z + 1][0].t != 3) || (q[z + 1][1].t != 7 && q[z + 1][1].t != 3)
199 		   || (t[z + 2][0].t != 5 && t[z + 2][0].t != 9) || (t[z + 2][1].t != 5 && t[z + 2][1].t != 9))
200 		abort ();
201 	    for (int z = 0; z < 3; z++)
202 	      if (b[z + 2].t != 5 && b[z + 2].t != 9)
203 		abort ();
204 	    r[3].s += 18;
205 	    o[1].s += 29;
206 	    o[2].s += 18;
207 	    p[0].s += 19;
208 	    c[0].s += 4;
209 	    c[1].s += 5;
210 	    d[0].s *= 2;
211 	    e[1].s += 6;
212 	    f[2].s += 7;
213 	    k[1][0].s += 17;
214 	    k[2][0].s += 19;
215 	  }
216 	r[3].s += 8;
217 	o[1].s += 9;
218 	o[2].s += 10;
219 	p[0].s += 11;
220 	q[1][1].s += 13;
221 	q[2][1].s += 15;
222 	b[3].s *= 2;
223 	c[0].s += 4;
224 	c[1].s += 9;
225 	d[0].s *= 2;
226 	e[1].s += 16;
227 	f[2].s += 8;
228       }
229     if (d[0].s != 1LL << (8 + 4)
230 	|| d[1].s != 1LL << 16
231 	|| m[0].s != 5
232 	|| m[1].s != 19 * 16 + 6 * 8 + 16 * 4
233 	|| m[2].s != 5
234 	|| r[0].s != 6
235 	|| r[1].s != 7
236 	|| r[2].s != 21 * 16 + 7 * 8 + 8 * 4
237 	|| r[3].s != 23 * 16 + 18 * 8 + 8 * 4
238 	|| r[4].s != 9
239 	|| o[0].s != 1
240 	|| o[1].s != 25 * 16 + 29 * 8 + 9 * 4
241 	|| o[2].s != 27 * 16 + 18 * 8 + 10 * 4
242 	|| o[3].s != 2)
243       abort ();
244     if (e[1].t != 7 || h[0].t != 7 || m[1].t != 7 || p[0].t != 7)
245       abort ();
246     for (int z = 0; z < 2; z++)
247       if (a[z].t != 7 || c[z].t != 7 || d[z].t != 5 || f[z + 2].t != 7
248 	  || g[z + 1].t != 7 || r[z + 2].t != 7 || s[z + 1].t != 5 || o[z + 1].t != 7
249 	  || k[z + 1][0].t != 7 || k[z + 1][1].t != 7 || q[z + 1][0].t != 7 || q[z + 1][1].t != 7
250 	  || t[z + 2][0].t != 5 || t[z + 2][1].t != 5)
251 	abort ();
252     for (int z = 0; z < 3; z++)
253       if (b[z + 2].t != 5)
254 	abort ();
255   }
256   if (a[0].s != 7 * 16 + 4 * 8 + 2 * 4
257       || a[1].s != 17 * 16 + 5 * 8 + 3 * 4
258       || b[0].s != 9 || b[1].s != 11
259       || b[2].s != 1LL << (16 + 4)
260       || b[3].s != 1LL << (8 + 4)
261       || b[4].s != 1LL << (16 + 8)
262       || b[5].s != 13 || b[6].s != 15
263       || c[0].s != 6 * 16 + 4 * 8 + 4 * 4
264       || c[1].s != 5 * 8 + 9 * 4
265       || e[0].s != 5
266       || e[1].s != 19 * 16 + 6 * 8 + 16 * 4
267       || e[2].s != 5
268       || f[0].s != 6
269       || f[1].s != 7
270       || f[2].s != 21 * 16 + 7 * 8 + 8 * 4
271       || f[3].s != 23 * 16 + 18 * 8 + 8 * 4
272       || f[4].s != 9
273       || g[0].s != 1
274       || g[1].s != 25 * 16 + 29 * 8 + 9 * 4
275       || g[2].s != 27 * 16 + 18 * 8 + 10 * 4
276       || g[3].s != 2
277       || h[0].s != 29 * 16 + 19 * 8 + 11 * 4
278       || h[1].s != 1 || h[2].s != 4
279       || k[0][0].s != 5 || k[0][1].s != 6
280       || k[1][0].s != 31 * 16 + 17 * 8
281       || k[1][1].s != 13 * 4
282       || k[2][0].s != 19 * 8
283       || k[2][1].s != 33 * 16 + 15 * 4
284       || k[3][0].s != 7 || k[3][1].s != 8
285       || p[0].s != 29 * 16 + 19 * 8 + 11 * 4
286       || p[1].s != 1 || p[2].s != 4
287       || q[0][0].s != 5 || q[0][1].s != 6
288       || q[1][0].s != 31 * 16 + 17 * 8
289       || q[1][1].s != 13 * 4
290       || q[2][0].s != 19 * 8
291       || q[2][1].s != 33 * 16 + 15 * 4
292       || q[3][0].s != 7 || q[3][1].s != 8
293       || ss[0].s != 5
294       || ss[1].s != 1LL << (16 + 4)
295       || ss[2].s != 1LL << 8
296       || ss[3].s != 6
297       || tt[0][0].s != 9 || tt[0][1].s != 10 || tt[1][0].s != 11 || tt[1][1].s != 12
298       || tt[2][0].s != 1LL << (16 + 8)
299       || tt[2][1].s != 1LL << 4
300       || tt[3][0].s != 1LL << 8
301       || tt[3][1].s != 1LL << (16 + 4)
302       || tt[4][0].s != 13 || tt[4][1].s != 14)
303     abort ();
304 }
305 
306 int
main()307 main ()
308 {
309   int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
310   test (1);
311   if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
312     abort ();
313   return 0;
314 }
315