libgomp testsuite: OpenACC C++ testing.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / if-1.c
blobe289f40a194570e05cb04693152b4fcddeb6cb58
1 /* { dg-do run } */
2 /* { dg-additional-options "-fno-builtin-acc_on_device" } */
4 #include <openacc.h>
5 #include <stdlib.h>
6 #include <stdbool.h>
8 #define N 32
10 int
11 main(int argc, char **argv)
13 float *a, *b, *d_a, *d_b, exp, exp2;
14 int i;
15 const int one = 1;
16 const int zero = 0;
17 int n;
19 a = (float *) malloc (N * sizeof (float));
20 b = (float *) malloc (N * sizeof (float));
21 d_a = (float *) acc_malloc (N * sizeof (float));
22 d_b = (float *) acc_malloc (N * sizeof (float));
24 for (i = 0; i < N; i++)
25 a[i] = 4.0;
27 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(1)
29 int ii;
31 for (ii = 0; ii < N; ii++)
33 if (acc_on_device (acc_device_host))
34 b[ii] = a[ii] + 1;
35 else
36 b[ii] = a[ii];
40 #if ACC_MEM_SHARED
41 exp = 5.0;
42 #else
43 exp = 4.0;
44 #endif
46 for (i = 0; i < N; i++)
48 if (b[i] != exp)
49 abort();
52 for (i = 0; i < N; i++)
53 a[i] = 16.0;
55 #pragma acc parallel if(0)
57 int ii;
59 for (ii = 0; ii < N; ii++)
61 if (acc_on_device (acc_device_host))
62 b[ii] = a[ii] + 1;
63 else
64 b[ii] = a[ii];
68 for (i = 0; i < N; i++)
70 if (b[i] != 17.0)
71 abort();
74 for (i = 0; i < N; i++)
75 a[i] = 8.0;
77 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(one)
79 int ii;
81 for (ii = 0; ii < N; ii++)
83 if (acc_on_device (acc_device_host))
84 b[ii] = a[ii] + 1;
85 else
86 b[ii] = a[ii];
90 #if ACC_MEM_SHARED
91 exp = 9.0;
92 #else
93 exp = 8.0;
94 #endif
96 for (i = 0; i < N; i++)
98 if (b[i] != exp)
99 abort();
102 for (i = 0; i < N; i++)
103 a[i] = 22.0;
105 #pragma acc parallel if(zero)
107 int ii;
109 for (ii = 0; ii < N; ii++)
111 if (acc_on_device (acc_device_host))
112 b[ii] = a[ii] + 1;
113 else
114 b[ii] = a[ii];
118 for (i = 0; i < N; i++)
120 if (b[i] != 23.0)
121 abort();
124 for (i = 0; i < N; i++)
125 a[i] = 16.0;
127 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(true)
129 int ii;
131 for (ii = 0; ii < N; ii++)
133 if (acc_on_device (acc_device_host))
134 b[ii] = a[ii] + 1;
135 else
136 b[ii] = a[ii];
140 #if ACC_MEM_SHARED
141 exp = 17.0;
142 #else
143 exp = 16.0;
144 #endif
146 for (i = 0; i < N; i++)
148 if (b[i] != exp)
149 abort();
152 for (i = 0; i < N; i++)
153 a[i] = 76.0;
155 #pragma acc parallel if(false)
157 int ii;
159 for (ii = 0; ii < N; ii++)
161 if (acc_on_device (acc_device_host))
162 b[ii] = a[ii] + 1;
163 else
164 b[ii] = a[ii];
168 for (i = 0; i < N; i++)
170 if (b[i] != 77.0)
171 abort();
174 for (i = 0; i < N; i++)
175 a[i] = 22.0;
177 n = 1;
179 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(n)
181 int ii;
183 for (ii = 0; ii < N; ii++)
185 if (acc_on_device (acc_device_host))
186 b[ii] = a[ii] + 1;
187 else
188 b[ii] = a[ii];
192 #if ACC_MEM_SHARED
193 exp = 23.0;
194 #else
195 exp = 22.0;
196 #endif
198 for (i = 0; i < N; i++)
200 if (b[i] != exp)
201 abort();
204 for (i = 0; i < N; i++)
205 a[i] = 18.0;
207 n = 0;
209 #pragma acc parallel if(n)
211 int ii;
213 for (ii = 0; ii < N; ii++)
215 if (acc_on_device (acc_device_host))
216 b[ii] = a[ii] + 1;
217 else
218 b[ii] = a[ii];
222 for (i = 0; i < N; i++)
224 if (b[i] != 19.0)
225 abort();
228 for (i = 0; i < N; i++)
229 a[i] = 49.0;
231 n = 1;
233 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(n + n)
235 int ii;
237 for (ii = 0; ii < N; ii++)
239 if (acc_on_device (acc_device_host))
240 b[ii] = a[ii] + 1;
241 else
242 b[ii] = a[ii];
246 #if ACC_MEM_SHARED
247 exp = 50.0;
248 #else
249 exp = 49.0;
250 #endif
252 for (i = 0; i < N; i++)
254 if (b[i] != exp)
255 abort();
258 for (i = 0; i < N; i++)
259 a[i] = 38.0;
261 n = 0;
263 #pragma acc parallel if(n + n)
265 int ii;
267 for (ii = 0; ii < N; ii++)
269 if (acc_on_device (acc_device_host))
270 b[ii] = a[ii] + 1;
271 else
272 b[ii] = a[ii];
276 for (i = 0; i < N; i++)
278 if (b[i] != 39.0)
279 abort();
282 for (i = 0; i < N; i++)
283 a[i] = 91.0;
285 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(-2)
287 int ii;
289 for (ii = 0; ii < N; ii++)
291 if (acc_on_device (acc_device_host))
292 b[ii] = a[ii] + 1;
293 else
294 b[ii] = a[ii];
298 #if ACC_MEM_SHARED
299 exp = 92.0;
300 #else
301 exp = 91.0;
302 #endif
304 for (i = 0; i < N; i++)
306 if (b[i] != exp)
307 abort();
310 for (i = 0; i < N; i++)
311 a[i] = 43.0;
313 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(one == 1)
315 int ii;
317 for (ii = 0; ii < N; ii++)
319 if (acc_on_device (acc_device_host))
320 b[ii] = a[ii] + 1;
321 else
322 b[ii] = a[ii];
326 #if ACC_MEM_SHARED
327 exp = 44.0;
328 #else
329 exp = 43.0;
330 #endif
332 for (i = 0; i < N; i++)
334 if (b[i] != exp)
335 abort();
338 for (i = 0; i < N; i++)
339 a[i] = 87.0;
341 #pragma acc parallel if(one == 0)
343 int ii;
345 for (ii = 0; ii < N; ii++)
347 if (acc_on_device (acc_device_host))
348 b[ii] = a[ii] + 1;
349 else
350 b[ii] = a[ii];
354 for (i = 0; i < N; i++)
356 if (b[i] != 88.0)
357 abort();
360 for (i = 0; i < N; i++)
362 a[i] = 3.0;
363 b[i] = 9.0;
366 #if ACC_MEM_SHARED
367 exp = 0.0;
368 exp2 = 0.0;
369 #else
370 acc_map_data (a, d_a, N * sizeof (float));
371 acc_map_data (b, d_b, N * sizeof (float));
372 exp = 3.0;
373 exp2 = 9.0;
374 #endif
376 #pragma acc update device(a[0:N], b[0:N]) if(1)
378 for (i = 0; i < N; i++)
380 a[i] = 0.0;
381 b[i] = 0.0;
384 #pragma acc update host(a[0:N], b[0:N]) if(1)
386 for (i = 0; i < N; i++)
388 if (a[i] != exp)
389 abort();
391 if (b[i] != exp2)
392 abort();
395 for (i = 0; i < N; i++)
397 a[i] = 6.0;
398 b[i] = 12.0;
401 #pragma acc update device(a[0:N], b[0:N]) if(0)
403 for (i = 0; i < N; i++)
405 a[i] = 0.0;
406 b[i] = 0.0;
409 #pragma acc update host(a[0:N], b[0:N]) if(1)
411 for (i = 0; i < N; i++)
413 if (a[i] != exp)
414 abort();
416 if (b[i] != exp2)
417 abort();
420 for (i = 0; i < N; i++)
422 a[i] = 26.0;
423 b[i] = 21.0;
426 #pragma acc update device(a[0:N], b[0:N]) if(1)
428 for (i = 0; i < N; i++)
430 a[i] = 0.0;
431 b[i] = 0.0;
434 #pragma acc update host(a[0:N], b[0:N]) if(0)
436 for (i = 0; i < N; i++)
438 if (a[i] != 0.0)
439 abort();
441 if (b[i] != 0.0)
442 abort();
445 #if !ACC_MEM_SHARED
446 acc_unmap_data (a);
447 acc_unmap_data (b);
448 #endif
450 acc_free (d_a);
451 acc_free (d_b);
453 for (i = 0; i < N; i++)
455 a[i] = 4.0;
456 b[i] = 0.0;
459 #pragma acc data copyin(a[0:N]) copyout(b[0:N]) if(1)
461 #pragma acc parallel present(a[0:N])
463 int ii;
465 for (ii = 0; ii < N; ii++)
467 b[ii] = a[ii];
472 for (i = 0; i < N; i++)
474 if (b[i] != 4.0)
475 abort();
478 for (i = 0; i < N; i++)
480 a[i] = 8.0;
481 b[i] = 1.0;
484 #pragma acc data copyin(a[0:N]) copyout(b[0:N]) if(0)
486 #if !ACC_MEM_SHARED
487 if (acc_is_present (a, N * sizeof (float)))
488 abort ();
489 #endif
491 #if !ACC_MEM_SHARED
492 if (acc_is_present (b, N * sizeof (float)))
493 abort ();
494 #endif
497 for (i = 0; i < N; i++)
499 a[i] = 18.0;
500 b[i] = 21.0;
503 #pragma acc data copyin(a[0:N]) if(1)
505 #if !ACC_MEM_SHARED
506 if (!acc_is_present (a, N * sizeof (float)))
507 abort ();
508 #endif
510 #pragma acc data copyout(b[0:N]) if(0)
512 #if !ACC_MEM_SHARED
513 if (acc_is_present (b, N * sizeof (float)))
514 abort ();
515 #endif
517 #pragma acc data copyout(b[0:N]) if(1)
519 #pragma acc parallel present(a[0:N]) present(b[0:N])
521 int ii;
523 for (ii = 0; ii < N; ii++)
525 b[ii] = a[ii];
530 #if !ACC_MEM_SHARED
531 if (acc_is_present (b, N * sizeof (float)))
532 abort ();
533 #endif
537 for (i = 0; i < N; i++)
539 if (b[i] != 18.0)
540 abort ();
543 #ifdef XXX_TODO_ENTER_END_DATA
544 #endif
546 return 0;