Improve atomic store implementation on hppa-linux.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / f-asyncwait-1.c
blobcf851707dc7c98dd255b9c85bfd1ed0176644ce2
1 /* { dg-do run } */
3 /* Based on asyncwait-1.f90. */
5 #include <stdlib.h>
7 #define N 64
9 int
10 main (void)
12 int *a, *b, *c, *d, *e;
14 a = (int*)malloc (N * sizeof (*a));
15 b = (int*)malloc (N * sizeof (*b));
16 c = (int*)malloc (N * sizeof (*c));
17 d = (int*)malloc (N * sizeof (*d));
18 e = (int*)malloc (N * sizeof (*e));
20 for (int i = 0; i < N; ++i)
22 a[i] = 3;
23 b[i] = 0;
26 #pragma acc data copy (a[0:N]) copy (b[0:N])
29 #pragma acc parallel async
30 #pragma acc loop
31 for (int i = 0; i < N; ++i)
32 b[i] = a[i];
34 #pragma acc wait
37 for (int i = 0; i < N; ++i)
39 if (a[i] != 3)
40 abort ();
41 if (b[i] != 3)
42 abort ();
45 for (int i = 0; i < N; ++i)
47 a[i] = 2;
48 b[i] = 0;
51 #pragma acc data copy (a[0:N]) copy (b[0:N])
53 #pragma acc parallel async (1)
54 #pragma acc loop
55 for (int i = 0; i < N; ++i)
56 b[i] = a[i];
58 #pragma acc wait (1)
61 for (int i = 0; i < N; ++i)
63 if (a[i] != 2) abort ();
64 if (b[i] != 2) abort ();
67 for (int i = 0; i < N; ++i)
69 a[i] = 3;
70 b[i] = 0;
71 c[i] = 0;
72 d[i] = 0;
75 #pragma acc data copy (a[0:N]) copy (b[0:N]) copy (c[0:N]) copy (d[0:N])
78 #pragma acc parallel async (1)
79 for (int i = 0; i < N; ++i)
80 b[i] = (a[i] * a[i] * a[i]) / a[i];
82 #pragma acc parallel async (1)
83 for (int i = 0; i < N; ++i)
84 c[i] = (a[i] * 4) / a[i];
87 #pragma acc parallel async (1)
88 #pragma acc loop
89 for (int i = 0; i < N; ++i)
90 d[i] = ((a[i] * a[i] + a[i]) / a[i]) - a[i];
92 #pragma acc wait (1)
95 for (int i = 0; i < N; ++i)
97 if (a[i] != 3)
98 abort ();
99 if (b[i] != 9)
100 abort ();
101 if (c[i] != 4)
102 abort ();
103 if (d[i] != 1)
104 abort ();
107 for (int i = 0; i < N; ++i)
109 a[i] = 2;
110 b[i] = 0;
111 c[i] = 0;
112 d[i] = 0;
113 e[i] = 0;
116 #pragma acc data copy (a[0:N], b[0:N], c[0:N], d[0:N], e[0:N])
119 #pragma acc parallel async (1)
120 for (int i = 0; i < N; ++i)
121 b[i] = (a[i] * a[i] * a[i]) / a[i];
123 #pragma acc parallel async (1)
124 #pragma acc loop
125 for (int i = 0; i < N; ++i)
126 c[i] = (a[i] * 4) / a[i];
128 #pragma acc parallel async (1)
129 #pragma acc loop
130 for (int i = 0; i < N; ++i)
131 d[i] = ((a[i] * a[i] + a[i]) / a[i]) - a[i];
134 #pragma acc parallel wait (1) async (1)
135 #pragma acc loop
136 for (int i = 0; i < N; ++i)
137 e[i] = a[i] + b[i] + c[i] + d[i];
139 #pragma acc wait (1)
142 for (int i = 0; i < N; ++i)
144 if (a[i] != 2)
145 abort ();
146 if (b[i] != 4)
147 abort ();
148 if (c[i] != 4)
149 abort ();
150 if (d[i] != 1)
151 abort ();
152 if (e[i] != 11)
153 abort ();
156 for (int i = 0; i < N; ++i)
158 a[i] = 3;
159 b[i] = 0;
162 #pragma acc data copy (a[0:N]) copy (b[0:N])
165 #pragma acc kernels async
166 #pragma acc loop
167 for (int i = 0; i < N; ++i)
168 b[i] = a[i];
170 #pragma acc wait
173 for (int i = 0; i < N; ++i)
175 if (a[i] != 3)
176 abort ();
177 if (b[i] != 3)
178 abort ();
181 for (int i = 0; i < N; ++i)
183 a[i] = 2;
184 b[i] = 0;
187 #pragma acc data copy (a[0:N]) copy (b[0:N])
189 #pragma acc kernels async (1)
190 #pragma acc loop
191 for (int i = 0; i < N; ++i)
192 b[i] = a[i];
194 #pragma acc wait (1)
197 for (int i = 0; i < N; ++i)
199 if (a[i] != 2)
200 abort ();
201 if (b[i] != 2)
202 abort ();
205 for (int i = 0; i < N; ++i)
207 a[i] = 3;
208 b[i] = 0;
209 c[i] = 0;
210 d[i] = 0;
213 #pragma acc data copy (a[0:N]) copy (b[0:N]) copy (c[0:N]) copy (d[0:N])
215 #pragma acc kernels async (1)
216 for (int i = 0; i < N; ++i)
217 b[i] = (a[i] * a[i] * a[i]) / a[i];
219 #pragma acc kernels async (1)
220 for (int i = 0; i < N; ++i)
221 c[i] = (a[i] * 4) / a[i];
223 #pragma acc kernels async (1)
224 #pragma acc loop
225 for (int i = 0; i < N; ++i)
226 d[i] = ((a[i] * a[i] + a[i]) / a[i]) - a[i];
228 #pragma acc wait (1)
231 for (int i = 0; i < N; ++i)
233 if (a[i] != 3)
234 abort ();
235 if (b[i] != 9)
236 abort ();
237 if (c[i] != 4)
238 abort ();
239 if (d[i] != 1)
240 abort ();
243 for (int i = 0; i < N; ++i)
245 a[i] = 2;
246 b[i] = 0;
247 c[i] = 0;
248 d[i] = 0;
249 e[i] = 0;
252 #pragma acc data copy (a[0:N], b[0:N], c[0:N], d[0:N], e[0:N])
254 #pragma acc kernels async (1)
255 for (int i = 0; i < N; ++i)
256 b[i] = (a[i] * a[i] * a[i]) / a[i];
258 #pragma acc kernels async (1)
259 #pragma acc loop
260 for (int i = 0; i < N; ++i)
261 c[i] = (a[i] * 4) / a[i];
263 #pragma acc kernels async (1)
264 #pragma acc loop
265 for (int i = 0; i < N; ++i)
266 d[i] = ((a[i] * a[i] + a[i]) / a[i]) - a[i];
268 #pragma acc kernels wait (1) async (1)
269 #pragma acc loop
270 for (int i = 0; i < N; ++i)
271 e[i] = a[i] + b[i] + c[i] + d[i];
273 #pragma acc wait (1)
276 for (int i = 0; i < N; ++i)
278 if (a[i] != 2)
279 abort ();
280 if (b[i] != 4)
281 abort ();
282 if (c[i] != 4)
283 abort ();
284 if (d[i] != 1)
285 abort ();
286 if (e[i] != 11)
287 abort ();
290 free (a);
291 free (b);
292 free (c);
293 free (d);
294 free (e);
296 return 0;