C++: simplify output from suggest_alternatives_for
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / clauses-1.c
blob410c46cc651ed9022ffa1afe133356e19eb9f31c
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 parallel copyin (a[0:N]) copyout (b[0:N])
29 int ii;
31 for (ii = 0; ii < N; ii++)
32 b[ii] = a[ii];
35 for (i = 0; i < N; i++)
37 if (b[i] != 3.0)
38 abort ();
41 if (acc_is_present (&a[0], (N * sizeof (float))))
42 abort ();
44 if (acc_is_present (&b[0], (N * sizeof (float))))
45 abort ();
47 for (i = 0; i < N; i++)
49 a[i] = 5.0;
50 b[i] = 1.0;
53 #pragma acc parallel copyin (a[0:N]) copyout (b[0:N])
55 int ii;
57 for (ii = 0; ii < N; ii++)
58 b[ii] = a[ii];
61 for (i = 0; i < N; i++)
63 if (b[i] != 5.0)
64 abort ();
67 if (acc_is_present (&a[0], (N * sizeof (float))))
68 abort ();
70 if (acc_is_present (&b[0], (N * sizeof (float))))
71 abort ();
73 for (i = 0; i < N; i++)
75 a[i] = 6.0;
76 b[i] = 0.0;
79 d = (float *) acc_copyin (&a[0], N * sizeof (float));
81 for (i = 0; i < N; i++)
83 a[i] = 9.0;
86 #pragma acc parallel present_or_copyin (a[0:N]) copyout (b[0:N])
88 int ii;
90 for (ii = 0; ii < N; ii++)
91 b[ii] = a[ii];
94 for (i = 0; i < N; i++)
96 if (b[i] != 6.0)
97 abort ();
100 if (!acc_is_present (&a[0], (N * sizeof (float))))
101 abort ();
103 if (acc_is_present (&b[0], (N * sizeof (float))))
104 abort ();
106 acc_free (d);
108 for (i = 0; i < N; i++)
110 a[i] = 6.0;
111 b[i] = 0.0;
114 #pragma acc parallel copyin (a[0:N]) present_or_copyout (b[0:N])
116 int ii;
118 for (ii = 0; ii < N; ii++)
119 b[ii] = a[ii];
122 for (i = 0; i < N; i++)
124 if (b[i] != 6.0)
125 abort ();
128 if (acc_is_present (&a[0], (N * sizeof (float))))
129 abort ();
131 if (acc_is_present (&b[0], (N * sizeof (float))))
132 abort ();
134 for (i = 0; i < N; i++)
136 a[i] = 5.0;
137 b[i] = 2.0;
140 d = (float *) acc_copyin (&b[0], N * sizeof (float));
142 #pragma acc parallel copyin (a[0:N]) present_or_copyout (b[0:N])
144 int ii;
146 for (ii = 0; ii < N; ii++)
147 b[ii] = a[ii];
150 for (i = 0; i < N; i++)
152 if (a[i] != 5.0)
153 abort ();
155 if (b[i] != 2.0)
156 abort ();
159 if (acc_is_present (&a[0], (N * sizeof (float))))
160 abort ();
162 if (!acc_is_present (&b[0], (N * sizeof (float))))
163 abort ();
165 acc_free (d);
167 if (acc_is_present (&b[0], (N * sizeof (float))))
168 abort ();
170 for (i = 0; i < N; i++)
172 a[i] = 3.0;
173 b[i] = 4.0;
176 #pragma acc parallel copy (a[0:N]) copyout (b[0:N])
178 int ii;
180 for (ii = 0; ii < N; ii++)
182 a[ii] = a[ii] + 1;
183 b[ii] = a[ii] + 2;
187 for (i = 0; i < N; i++)
189 if (a[i] != 4.0)
190 abort ();
192 if (b[i] != 6.0)
193 abort ();
196 if (acc_is_present (&a[0], (N * sizeof (float))))
197 abort ();
199 if (acc_is_present (&b[0], (N * sizeof (float))))
200 abort ();
202 for (i = 0; i < N; i++)
204 a[i] = 4.0;
205 b[i] = 7.0;
208 #pragma acc parallel present_or_copy (a[0:N]) present_or_copy (b[0:N])
210 int ii;
212 for (ii = 0; ii < N; ii++)
214 a[ii] = a[ii] + 1;
215 b[ii] = b[ii] + 2;
219 for (i = 0; i < N; i++)
221 if (a[i] != 5.0)
222 abort ();
224 if (b[i] != 9.0)
225 abort ();
228 if (acc_is_present (&a[0], (N * sizeof (float))))
229 abort ();
231 if (acc_is_present (&b[0], (N * sizeof (float))))
232 abort ();
234 for (i = 0; i < N; i++)
236 a[i] = 3.0;
237 b[i] = 7.0;
240 d = (float *) acc_copyin (&a[0], N * sizeof (float));
241 d = (float *) acc_copyin (&b[0], N * sizeof (float));
243 #pragma acc parallel present_or_copy (a[0:N]) present_or_copy (b[0:N])
245 int ii;
247 for (ii = 0; ii < N; ii++)
249 a[ii] = a[ii] + 1;
250 b[ii] = b[ii] + 2;
254 for (i = 0; i < N; i++)
256 if (a[i] != 3.0)
257 abort ();
259 if (b[i] != 7.0)
260 abort ();
263 if (!acc_is_present (&a[0], (N * sizeof (float))))
264 abort ();
266 if (!acc_is_present (&b[0], (N * sizeof (float))))
267 abort ();
269 d = (float *) acc_deviceptr (&a[0]);
270 acc_unmap_data (&a[0]);
271 acc_free (d);
273 d = (float *) acc_deviceptr (&b[0]);
274 acc_unmap_data (&b[0]);
275 acc_free (d);
277 for (i = 0; i < N; i++)
279 a[i] = 3.0;
280 b[i] = 7.0;
283 #pragma acc parallel copyin (a[0:N]) create (c[0:N]) copyout (b[0:N])
285 int ii;
287 for (ii = 0; ii < N; ii++)
289 c[ii] = a[ii];
290 b[ii] = c[ii];
294 for (i = 0; i < N; i++)
296 if (a[i] != 3.0)
297 abort ();
299 if (b[i] != 3.0)
300 abort ();
303 if (acc_is_present (&a[0], (N * sizeof (float))))
304 abort ();
306 if (acc_is_present (&b[0], (N * sizeof (float))))
307 abort ();
309 if (acc_is_present (&c[0], (N * sizeof (float))))
310 abort ();
312 for (i = 0; i < N; i++)
314 a[i] = 4.0;
315 b[i] = 8.0;
318 #pragma acc parallel copyin (a[0:N]) present_or_create (c[0:N]) copyout (b[0:N])
320 int ii;
322 for (ii = 0; ii < N; ii++)
324 c[ii] = a[ii];
325 b[ii] = c[ii];
329 for (i = 0; i < N; i++)
331 if (a[i] != 4.0)
332 abort ();
334 if (b[i] != 4.0)
335 abort ();
338 if (acc_is_present (&a[0], (N * sizeof (float))))
339 abort ();
341 if (acc_is_present (&b[0], (N * sizeof (float))))
342 abort ();
344 if (acc_is_present (&c[0], (N * sizeof (float))))
345 abort ();
347 for (i = 0; i < N; i++)
349 a[i] = 2.0;
350 b[i] = 5.0;
353 d = (float *) acc_malloc (N * sizeof (float));
354 acc_map_data (c, d, N * sizeof (float));
356 #pragma acc parallel copyin (a[0:N]) present_or_create (c[0:N]) copyout (b[0:N])
358 int ii;
360 for (ii = 0; ii < N; ii++)
362 c[ii] = a[ii];
363 b[ii] = c[ii];
367 for (i = 0; i < N; i++)
369 if (a[i] != 2.0)
370 abort ();
372 if (b[i] != 2.0)
373 abort ();
376 if (acc_is_present (a, (N * sizeof (float))))
377 abort ();
379 if (acc_is_present (b, (N * sizeof (float))))
380 abort ();
382 if (!acc_is_present (c, (N * sizeof (float))))
383 abort ();
385 d = (float *) acc_deviceptr (c);
387 acc_unmap_data (c);
389 acc_free (d);
391 for (i = 0; i < N; i++)
393 a[i] = 4.0;
394 b[i] = 8.0;
397 d = (float *) acc_malloc (N * sizeof (float));
398 acc_map_data (c, d, N * sizeof (float));
400 #pragma acc parallel copyin (a[0:N]) present (c[0:N]) copyout (b[0:N])
402 int ii;
404 for (ii = 0; ii < N; ii++)
406 c[ii] = a[ii];
407 b[ii] = c[ii];
411 for (i = 0; i < N; i++)
413 if (a[i] != 4.0)
414 abort ();
416 if (b[i] != 4.0)
417 abort ();
420 if (acc_is_present (a, (N * sizeof (float))))
421 abort ();
423 if (acc_is_present (b, (N * sizeof (float))))
424 abort ();
426 if (!acc_is_present (c, (N * sizeof (float))))
427 abort ();
429 acc_unmap_data (c);
431 acc_free (d);
433 for (i = 0; i < N; i++)
435 a[i] = 4.0;
436 b[i] = 8.0;
439 acc_copyin (a, N * sizeof (float));
441 d = (float *) acc_malloc (N * sizeof (float));
442 acc_map_data (b, d, N * sizeof (float));
444 d = (float *) acc_malloc (N * sizeof (float));
445 acc_map_data (c, d, N * sizeof (float));
447 #pragma acc parallel present (a[0:N]) present (c[0:N]) present (b[0:N])
449 int ii;
451 for (ii = 0; ii < N; ii++)
453 c[ii] = a[ii];
454 b[ii] = c[ii];
458 if (!acc_is_present (a, (N * sizeof (float))))
459 abort ();
461 if (!acc_is_present (b, (N * sizeof (float))))
462 abort ();
464 if (!acc_is_present (c, (N * sizeof (float))))
465 abort ();
467 acc_copyout (b, N * sizeof (float));
469 for (i = 0; i < N; i++)
471 if (a[i] != 4.0)
472 abort ();
474 if (b[i] != 4.0)
475 abort ();
478 d = (float *) acc_deviceptr (a);
480 acc_unmap_data (a);
482 acc_free (d);
484 d = (float *) acc_deviceptr (c);
486 acc_unmap_data (c);
488 acc_free (d);
490 for (i = 0; i < N; i++)
492 a[i] = 3.0;
493 b[i] = 6.0;
496 d = (float *) acc_malloc (N * sizeof (float));
498 #pragma acc parallel copyin (a[0:N]) deviceptr (d) copyout (b[0:N])
500 int ii;
502 for (ii = 0; ii < N; ii++)
504 d[ii] = a[ii];
505 b[ii] = d[ii];
509 for (i = 0; i < N; i++)
511 if (a[i] != 3.0)
512 abort ();
514 if (b[i] != 3.0)
515 abort ();
518 if (acc_is_present (a, (N * sizeof (float))))
519 abort ();
521 if (acc_is_present (b, (N * sizeof (float))))
522 abort ();
524 acc_free (d);
526 for (i = 0; i < N; i++)
528 a[i] = 6.0;
529 b[i] = 0.0;
532 d = (float *) acc_copyin (&a[0], N * sizeof (float));
534 for (i = 0; i < N; i++)
536 a[i] = 9.0;
539 #pragma acc parallel pcopyin (a[0:N]) copyout (b[0:N])
541 int ii;
543 for (ii = 0; ii < N; ii++)
544 b[ii] = a[ii];
547 for (i = 0; i < N; i++)
549 if (b[i] != 6.0)
550 abort ();
553 if (!acc_is_present (&a[0], (N * sizeof (float))))
554 abort ();
556 if (acc_is_present (&b[0], (N * sizeof (float))))
557 abort ();
559 acc_free (d);
561 for (i = 0; i < N; i++)
563 a[i] = 6.0;
564 b[i] = 0.0;
567 #pragma acc parallel copyin (a[0:N]) pcopyout (b[0:N])
569 int ii;
571 for (ii = 0; ii < N; ii++)
572 b[ii] = a[ii];
575 for (i = 0; i < N; i++)
577 if (b[i] != 6.0)
578 abort ();
581 if (acc_is_present (&a[0], (N * sizeof (float))))
582 abort ();
584 if (acc_is_present (&b[0], (N * sizeof (float))))
585 abort ();
587 for (i = 0; i < N; i++)
589 a[i] = 6.0;
590 b[i] = 0.0;
593 #pragma acc parallel pcopy (a[0:N], b[0:N])
595 int ii;
597 for (ii = 0; ii < N; ii++)
598 b[ii] = a[ii];
601 for (i = 0; i < N; i++)
603 if (b[i] != 6.0)
604 abort ();
607 if (acc_is_present (&a[0], (N * sizeof (float))))
608 abort ();
610 if (acc_is_present (&b[0], (N * sizeof (float))))
611 abort ();
613 for (i = 0; i < N; i++)
615 a[i] = 5.0;
616 b[i] = 7.0;
619 #pragma acc parallel copyin (a[0:N]) pcreate (c[0:N]) copyout (b[0:N])
621 int ii;
623 for (ii = 0; ii < N; ii++)
625 c[ii] = a[ii];
626 b[ii] = c[ii];
630 for (i = 0; i < N; i++)
632 if (a[i] != 5.0)
633 abort ();
635 if (b[i] != 5.0)
636 abort ();
639 if (acc_is_present (&a[0], (N * sizeof (float))))
640 abort ();
642 if (acc_is_present (&b[0], (N * sizeof (float))))
643 abort ();
645 if (acc_is_present (&c[0], (N * sizeof (float))))
646 abort ();
648 return 0;