Add support for ARMv8-R architecture
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / nested-1.c
blobededf2ba5b78be82b324e9b06c771aa7fd1335d6
1 /* { dg-do run } */
2 /* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
4 #include <openacc.h>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdbool.h>
10 int
11 main (int argc, char **argv)
13 int N = 8;
14 float *a, *b, *c, *d;
15 int i;
17 a = (float *) malloc (N * sizeof (float));
18 b = (float *) malloc (N * sizeof (float));
19 c = (float *) malloc (N * sizeof (float));
21 for (i = 0; i < N; i++)
23 a[i] = 3.0;
24 b[i] = 0.0;
27 #pragma acc data copyin (a[0:N]) copyout (b[0:N])
29 #pragma acc parallel
31 int ii;
33 for (ii = 0; ii < N; ii++)
34 b[ii] = a[ii];
38 for (i = 0; i < N; i++)
40 if (b[i] != 3.0)
41 abort ();
44 if (acc_is_present (&a[0], (N * sizeof (float))))
45 abort ();
47 if (acc_is_present (&b[0], (N * sizeof (float))))
48 abort ();
50 for (i = 0; i < N; i++)
52 a[i] = 5.0;
53 b[i] = 1.0;
56 #pragma acc data copyin (a[0:N]) copyout (b[0:N])
58 #pragma acc parallel
60 int ii;
62 for (ii = 0; ii < N; ii++)
63 b[ii] = a[ii];
67 for (i = 0; i < N; i++)
69 if (b[i] != 5.0)
70 abort ();
73 if (acc_is_present (&a[0], (N * sizeof (float))))
74 abort ();
76 if (acc_is_present (&b[0], (N * sizeof (float))))
77 abort ();
79 for (i = 0; i < N; i++)
81 a[i] = 6.0;
82 b[i] = 0.0;
85 d = (float *) acc_copyin (&a[0], N * sizeof (float));
87 for (i = 0; i < N; i++)
89 a[i] = 9.0;
92 #pragma acc data present_or_copyin (a[0:N]) copyout (b[0:N])
94 #pragma acc parallel
96 int ii;
98 for (ii = 0; ii < N; ii++)
99 b[ii] = a[ii];
103 for (i = 0; i < N; i++)
105 if (b[i] != 6.0)
106 abort ();
109 if (!acc_is_present (&a[0], (N * sizeof (float))))
110 abort ();
112 if (acc_is_present (&b[0], (N * sizeof (float))))
113 abort ();
115 acc_free (d);
117 for (i = 0; i < N; i++)
119 a[i] = 6.0;
120 b[i] = 0.0;
123 #pragma acc data copyin (a[0:N]) present_or_copyout (b[0:N])
125 #pragma acc parallel
127 int ii;
129 for (ii = 0; ii < N; ii++)
130 b[ii] = a[ii];
134 for (i = 0; i < N; i++)
136 if (b[i] != 6.0)
137 abort ();
140 if (acc_is_present (&a[0], (N * sizeof (float))))
141 abort ();
143 if (acc_is_present (&b[0], (N * sizeof (float))))
144 abort ();
146 for (i = 0; i < N; i++)
148 a[i] = 5.0;
149 b[i] = 2.0;
152 d = (float *) acc_copyin (&b[0], N * sizeof (float));
154 #pragma acc data copyin (a[0:N]) present_or_copyout (b[0:N])
156 #pragma acc parallel
158 int ii;
160 for (ii = 0; ii < N; ii++)
161 b[ii] = a[ii];
165 for (i = 0; i < N; i++)
167 if (a[i] != 5.0)
168 abort ();
170 if (b[i] != 2.0)
171 abort ();
174 if (acc_is_present (&a[0], (N * sizeof (float))))
175 abort ();
177 if (!acc_is_present (&b[0], (N * sizeof (float))))
178 abort ();
180 acc_free (d);
182 if (acc_is_present (&b[0], (N * sizeof (float))))
183 abort ();
185 for (i = 0; i < N; i++)
187 a[i] = 3.0;
188 b[i] = 4.0;
191 #pragma acc data copy (a[0:N]) copyout (b[0:N])
193 #pragma acc parallel
195 int ii;
197 for (ii = 0; ii < N; ii++)
199 a[ii] = a[ii] + 1;
200 b[ii] = a[ii] + 2;
205 for (i = 0; i < N; i++)
207 if (a[i] != 4.0)
208 abort ();
210 if (b[i] != 6.0)
211 abort ();
214 if (acc_is_present (&a[0], (N * sizeof (float))))
215 abort ();
217 if (acc_is_present (&b[0], (N * sizeof (float))))
218 abort ();
220 for (i = 0; i < N; i++)
222 a[i] = 4.0;
223 b[i] = 7.0;
226 #pragma acc data present_or_copy (a[0:N]) present_or_copy (b[0:N])
228 #pragma acc parallel
230 int ii;
232 for (ii = 0; ii < N; ii++)
234 a[ii] = a[ii] + 1;
235 b[ii] = b[ii] + 2;
240 for (i = 0; i < N; i++)
242 if (a[i] != 5.0)
243 abort ();
245 if (b[i] != 9.0)
246 abort ();
249 if (acc_is_present (&a[0], (N * sizeof (float))))
250 abort ();
252 if (acc_is_present (&b[0], (N * sizeof (float))))
253 abort ();
255 for (i = 0; i < N; i++)
257 a[i] = 3.0;
258 b[i] = 7.0;
261 d = (float *) acc_copyin (&a[0], N * sizeof (float));
262 d = (float *) acc_copyin (&b[0], N * sizeof (float));
264 #pragma acc data present_or_copy (a[0:N]) present_or_copy (b[0:N])
266 #pragma acc parallel
268 int ii;
270 for (ii = 0; ii < N; ii++)
272 a[ii] = a[ii] + 1;
273 b[ii] = b[ii] + 2;
278 for (i = 0; i < N; i++)
280 if (a[i] != 3.0)
281 abort ();
283 if (b[i] != 7.0)
284 abort ();
287 if (!acc_is_present (&a[0], (N * sizeof (float))))
288 abort ();
290 if (!acc_is_present (&b[0], (N * sizeof (float))))
291 abort ();
293 d = (float *) acc_deviceptr (&a[0]);
294 acc_unmap_data (&a[0]);
295 acc_free (d);
297 d = (float *) acc_deviceptr (&b[0]);
298 acc_unmap_data (&b[0]);
299 acc_free (d);
302 for (i = 0; i < N; i++)
304 a[i] = 3.0;
305 b[i] = 7.0;
308 #pragma acc data copyin (a[0:N]) create (c[0:N]) copyout (b[0:N])
310 #pragma acc parallel
312 int ii;
314 for (ii = 0; ii < N; ii++)
316 c[ii] = a[ii];
317 b[ii] = c[ii];
322 for (i = 0; i < N; i++)
324 if (a[i] != 3.0)
325 abort ();
327 if (b[i] != 3.0)
328 abort ();
331 if (acc_is_present (&a[0], (N * sizeof (float))))
332 abort ();
334 if (acc_is_present (&b[0], (N * sizeof (float))))
335 abort ();
337 if (acc_is_present (&c[0], (N * sizeof (float))))
338 abort ();
340 for (i = 0; i < N; i++)
342 a[i] = 4.0;
343 b[i] = 8.0;
346 #pragma acc data copyin (a[0:N]) present_or_create (c[0:N]) copyout (b[0:N])
348 #pragma acc parallel
350 int ii;
352 for (ii = 0; ii < N; ii++)
354 c[ii] = a[ii];
355 b[ii] = c[ii];
360 for (i = 0; i < N; i++)
362 if (a[i] != 4.0)
363 abort ();
365 if (b[i] != 4.0)
366 abort ();
369 if (acc_is_present (&a[0], (N * sizeof (float))))
370 abort ();
372 if (acc_is_present (&b[0], (N * sizeof (float))))
373 abort ();
375 if (acc_is_present (&c[0], (N * sizeof (float))))
376 abort ();
378 for (i = 0; i < N; i++)
380 a[i] = 2.0;
381 b[i] = 5.0;
384 d = (float *) acc_malloc (N * sizeof (float));
385 acc_map_data (c, d, N * sizeof (float));
387 #pragma acc data copyin (a[0:N]) present_or_create (c[0:N]) copyout (b[0:N])
389 #pragma acc parallel
391 int ii;
393 for (ii = 0; ii < N; ii++)
395 c[ii] = a[ii];
396 b[ii] = c[ii];
401 for (i = 0; i < N; i++)
403 if (a[i] != 2.0)
404 abort ();
406 if (b[i] != 2.0)
407 abort ();
410 if (acc_is_present (a, (N * sizeof (float))))
411 abort ();
413 if (acc_is_present (b, (N * sizeof (float))))
414 abort ();
416 if (!acc_is_present (c, (N * sizeof (float))))
417 abort ();
419 d = (float *) acc_deviceptr (c);
421 acc_unmap_data (c);
423 acc_free (d);
425 for (i = 0; i < N; i++)
427 a[i] = 4.0;
428 b[i] = 8.0;
431 d = (float *) acc_malloc (N * sizeof (float));
432 acc_map_data (c, d, N * sizeof (float));
434 #pragma acc data copyin (a[0:N]) present (c[0:N]) copyout (b[0:N])
436 #pragma acc parallel
438 int ii;
440 for (ii = 0; ii < N; ii++)
442 c[ii] = a[ii];
443 b[ii] = c[ii];
448 for (i = 0; i < N; i++)
450 if (a[i] != 4.0)
451 abort ();
453 if (b[i] != 4.0)
454 abort ();
457 if (acc_is_present (a, (N * sizeof (float))))
458 abort ();
460 if (acc_is_present (b, (N * sizeof (float))))
461 abort ();
463 if (!acc_is_present (c, (N * sizeof (float))))
464 abort ();
466 acc_unmap_data (c);
468 if (acc_is_present (c, (N * sizeof (float))))
469 abort ();
471 acc_free (d);
473 d = (float *) acc_malloc (N * sizeof (float));
474 acc_map_data (c, d, N * sizeof (float));
476 if (!acc_is_present (c, (N * sizeof (float))))
477 abort ();
479 d = (float *) acc_malloc (N * sizeof (float));
480 acc_map_data (b, d, N * sizeof (float));
482 if (!acc_is_present (b, (N * sizeof (float))))
483 abort ();
485 d = (float *) acc_malloc (N * sizeof (float));
486 acc_map_data (a, d, N * sizeof (float));
488 if (!acc_is_present (a, (N * sizeof (float))))
489 abort ();
491 #pragma acc data present (a[0:N]) present (c[0:N]) present (b[0:N])
493 #pragma acc parallel
495 int ii;
497 for (ii = 0; ii < N; ii++)
499 a[ii] = 1.0;
500 c[ii] = 2.0;
501 b[ii] = 4.0;
506 if (!acc_is_present (a, (N * sizeof (float))))
507 abort ();
509 if (!acc_is_present (b, (N * sizeof (float))))
510 abort ();
512 if (!acc_is_present (c, (N * sizeof (float))))
513 abort ();
515 acc_copyout (b, N * sizeof (float));
517 for (i = 0; i < N; i++)
519 if (a[i] != 4.0)
520 abort ();
522 if (b[i] != 4.0)
523 abort ();
526 d = (float *) acc_deviceptr (a);
528 acc_unmap_data (a);
530 acc_free (d);
532 d = (float *) acc_deviceptr (c);
534 acc_unmap_data (c);
536 acc_free (d);
538 for (i = 0; i < N; i++)
540 a[i] = 3.0;
541 b[i] = 6.0;
544 d = (float *) acc_malloc (N * sizeof (float));
546 #pragma acc parallel copyin (a[0:N]) deviceptr (d) copyout (b[0:N])
548 int ii;
550 for (ii = 0; ii < N; ii++)
552 d[ii] = a[ii];
553 b[ii] = d[ii];
557 for (i = 0; i < N; i++)
559 if (a[i] != 3.0)
560 abort ();
562 if (b[i] != 3.0)
563 abort ();
566 if (acc_is_present (a, (N * sizeof (float))))
567 abort ();
569 if (acc_is_present (b, (N * sizeof (float))))
570 abort ();
572 acc_free (d);
574 for (i = 0; i < N; i++)
576 a[i] = 6.0;
577 b[i] = 0.0;
580 d = (float *) acc_copyin (&a[0], N * sizeof (float));
582 for (i = 0; i < N; i++)
584 a[i] = 9.0;
587 #pragma acc data pcopyin (a[0:N]) copyout (b[0:N])
589 #pragma acc parallel
591 int ii;
593 for (ii = 0; ii < N; ii++)
594 b[ii] = a[ii];
598 for (i = 0; i < N; i++)
600 if (b[i] != 6.0)
601 abort ();
604 if (!acc_is_present (&a[0], (N * sizeof (float))))
605 abort ();
607 if (acc_is_present (&b[0], (N * sizeof (float))))
608 abort ();
610 acc_free (d);
612 for (i = 0; i < N; i++)
614 a[i] = 6.0;
615 b[i] = 0.0;
618 #pragma acc data copyin (a[0:N]) pcopyout (b[0:N])
620 #pragma acc parallel
622 int ii;
624 for (ii = 0; ii < N; ii++)
625 b[ii] = a[ii];
629 for (i = 0; i < N; i++)
631 if (b[i] != 6.0)
632 abort ();
635 if (acc_is_present (&a[0], (N * sizeof (float))))
636 abort ();
638 if (acc_is_present (&b[0], (N * sizeof (float))))
639 abort ();
641 for (i = 0; i < N; i++)
643 a[i] = 5.0;
644 b[i] = 7.0;
647 #pragma acc data copyin (a[0:N]) pcreate (c[0:N]) copyout (b[0:N])
649 #pragma acc parallel
651 int ii;
653 for (ii = 0; ii < N; ii++)
655 c[ii] = a[ii];
656 b[ii] = c[ii];
661 for (i = 0; i < N; i++)
663 if (a[i] != 5.0)
664 abort ();
666 if (b[i] != 5.0)
667 abort ();
670 if (acc_is_present (&a[0], (N * sizeof (float))))
671 abort ();
673 if (acc_is_present (&b[0], (N * sizeof (float))))
674 abort ();
676 if (acc_is_present (&c[0], (N * sizeof (float))))
677 abort ();
679 return 0;