* builtins.def (BUILT_IN_SETJMP): Declare as library builtin instead
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-fortran / if-1.f90
blob44055e177f8ed1e17c0fa1a72fb7ffe739901b73
1 ! { dg-do run }
2 ! { dg-additional-options "-cpp" }
4 program main
5 use openacc
6 implicit none
8 integer, parameter :: N = 8
9 integer, parameter :: one = 1
10 integer, parameter :: zero = 0
11 integer i, nn
12 real, allocatable :: a(:), b(:)
13 real exp, exp2
15 i = 0
17 allocate (a(N))
18 allocate (b(N))
20 a(:) = 4.0
22 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
23 do i = 1, N
24 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
25 b(i) = a(i) + 1
26 else
27 b(i) = a(i)
28 end if
29 end do
30 !$acc end parallel
32 #if ACC_MEM_SHARED
33 exp = 5.0
34 #else
35 exp = 4.0
36 #endif
38 do i = 1, N
39 if (b(i) .ne. exp) call abort
40 end do
42 a(:) = 16.0
44 !$acc parallel if (0 == 1)
45 do i = 1, N
46 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
47 b(i) = a(i) + 1
48 else
49 b(i) = a(i)
50 end if
51 end do
52 !$acc end parallel
54 do i = 1, N
55 if (b(i) .ne. 17.0) call abort
56 end do
58 a(:) = 8.0
60 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (one == 1)
61 do i = 1, N
62 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
63 b(i) = a(i) + 1
64 else
65 b(i) = a(i)
66 end if
67 end do
68 !$acc end parallel
70 #if ACC_MEM_SHARED
71 exp = 9.0
72 #else
73 exp = 8.0
74 #endif
76 do i = 1, N
77 if (b(i) .ne. exp) call abort
78 end do
80 a(:) = 22.0
82 !$acc parallel if (zero == 1)
83 do i = 1, N
84 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
85 b(i) = a(i) + 1
86 else
87 b(i) = a(i)
88 end if
89 end do
90 !$acc end parallel
92 do i = 1, N
93 if (b(i) .ne. 23.0) call abort
94 end do
96 a(:) = 16.0
98 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (.TRUE.)
99 do i = 1, N
100 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
101 b(i) = a(i) + 1
102 else
103 b(i) = a(i)
104 end if
105 end do
106 !$acc end parallel
108 #if ACC_MEM_SHARED
109 exp = 17.0;
110 #else
111 exp = 16.0;
112 #endif
114 do i = 1, N
115 if (b(i) .ne. exp) call abort
116 end do
118 a(:) = 76.0
120 !$acc parallel if (.FALSE.)
121 do i = 1, N
122 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
123 b(i) = a(i) + 1
124 else
125 b(i) = a(i)
126 end if
127 end do
128 !$acc end parallel
130 do i = 1, N
131 if (b(i) .ne. 77.0) call abort
132 end do
134 a(:) = 22.0
136 nn = 1
138 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (nn == 1)
139 do i = 1, N
140 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
141 b(i) = a(i) + 1
142 else
143 b(i) = a(i)
144 end if
145 end do
146 !$acc end parallel
148 #if ACC_MEM_SHARED
149 exp = 23.0;
150 #else
151 exp = 22.0;
152 #endif
154 do i = 1, N
155 if (b(i) .ne. exp) call abort
156 end do
158 a(:) = 18.0
160 nn = 0
162 !$acc parallel if (nn == 1)
163 do i = 1, N
164 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
165 b(i) = a(i) + 1
166 else
167 b(i) = a(i)
168 end if
169 end do
170 !$acc end parallel
172 do i = 1, N
173 if (b(i) .ne. 19.0) call abort
174 end do
176 a(:) = 49.0
178 nn = 1
180 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if ((nn + nn) > 0)
181 do i = 1, N
182 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
183 b(i) = a(i) + 1
184 else
185 b(i) = a(i)
186 end if
187 end do
188 !$acc end parallel
190 #if ACC_MEM_SHARED
191 exp = 50.0
192 #else
193 exp = 49.0
194 #endif
196 do i = 1, N
197 if (b(i) .ne. exp) call abort
198 end do
200 a(:) = 38.0
202 nn = 0;
204 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if ((nn + nn) > 0)
205 do i = 1, N
206 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
207 b(i) = a(i) + 1
208 else
209 b(i) = a(i)
210 end if
211 end do
212 !$acc end parallel
214 do i = 1, N
215 if (b(i) .ne. 39.0) call abort
216 end do
218 a(:) = 91.0
220 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (-2 > 0)
221 do i = 1, N
222 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
223 b(i) = a(i) + 1
224 else
225 b(i) = a(i)
226 end if
227 end do
228 !$acc end parallel
230 do i = 1, N
231 if (b(i) .ne. 92.0) call abort
232 end do
234 a(:) = 43.0
236 !$acc parallel copyin (a(1:N)) copyout (b(1:N)) if (one == 1)
237 do i = 1, N
238 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
239 b(i) = a(i) + 1
240 else
241 b(i) = a(i)
242 end if
243 end do
244 !$acc end parallel
246 #if ACC_MEM_SHARED
247 exp = 44.0
248 #else
249 exp = 43.0
250 #endif
252 do i = 1, N
253 if (b(i) .ne. exp) call abort
254 end do
256 a(:) = 87.0
258 !$acc parallel if (one == 0)
259 do i = 1, N
260 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
261 b(i) = a(i) + 1
262 else
263 b(i) = a(i)
264 end if
265 end do
266 !$acc end parallel
268 do i = 1, N
269 if (b(i) .ne. 88.0) call abort
270 end do
272 a(:) = 3.0
273 b(:) = 9.0
275 #if ACC_MEM_SHARED
276 exp = 0.0
277 exp2 = 0.0
278 #else
279 call acc_copyin (a, sizeof (a))
280 call acc_copyin (b, sizeof (b))
281 exp = 3.0;
282 exp2 = 9.0;
283 #endif
285 !$acc update device (a(1:N), b(1:N)) if (1 == 1)
287 a(:) = 0.0
288 b(:) = 0.0
290 !$acc update host (a(1:N), b(1:N)) if (1 == 1)
292 do i = 1, N
293 if (a(i) .ne. exp) call abort
294 if (b(i) .ne. exp2) call abort
295 end do
297 a(:) = 6.0
298 b(:) = 12.0
300 !$acc update device (a(1:N), b(1:N)) if (0 == 1)
302 a(:) = 0.0
303 b(:) = 0.0
305 !$acc update host (a(1:N), b(1:N)) if (1 == 1)
307 do i = 1, N
308 if (a(i) .ne. exp) call abort
309 if (b(i) .ne. exp2) call abort
310 end do
312 a(:) = 26.0
313 b(:) = 21.0
315 !$acc update device (a(1:N), b(1:N)) if (1 == 1)
317 a(:) = 0.0
318 b(:) = 0.0
320 !$acc update host (a(1:N), b(1:N)) if (0 == 1)
322 do i = 1, N
323 if (a(i) .ne. 0.0) call abort
324 if (b(i) .ne. 0.0) call abort
325 end do
327 #if !ACC_MEM_SHARED
328 call acc_copyout (a, sizeof (a))
329 call acc_copyout (b, sizeof (b))
330 #endif
332 a(:) = 4.0
333 b(:) = 0.0
335 !$acc data copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
337 !$acc parallel present (a(1:N))
338 do i = 1, N
339 b(i) = a(i)
340 end do
341 !$acc end parallel
342 !$acc end data
344 do i = 1, N
345 if (b(i) .ne. 4.0) call abort
346 end do
348 a(:) = 8.0
349 b(:) = 1.0
351 !$acc data copyin (a(1:N)) copyout (b(1:N)) if (0 == 1)
353 #if !ACC_MEM_SHARED
354 if (acc_is_present (a) .eqv. .TRUE.) call abort
355 if (acc_is_present (b) .eqv. .TRUE.) call abort
356 #endif
358 !$acc end data
360 a(:) = 18.0
361 b(:) = 21.0
363 !$acc data copyin (a(1:N)) if (1 == 1)
365 #if !ACC_MEM_SHARED
366 if (acc_is_present (a) .eqv. .FALSE.) call abort
367 #endif
369 !$acc data copyout (b(1:N)) if (0 == 1)
370 #if !ACC_MEM_SHARED
371 if (acc_is_present (b) .eqv. .TRUE.) call abort
372 #endif
373 !$acc data copyout (b(1:N)) if (1 == 1)
375 !$acc parallel present (a(1:N)) present (b(1:N))
376 do i = 1, N
377 b(i) = a(i)
378 end do
379 !$acc end parallel
381 !$acc end data
383 #if !ACC_MEM_SHARED
384 if (acc_is_present (b) .eqv. .TRUE.) call abort
385 #endif
386 !$acc end data
387 !$acc end data
389 do i = 1, N
390 if (b(1) .ne. 18.0) call abort
391 end do
393 !$acc enter data copyin (b(1:N)) if (0 == 1)
395 #if !ACC_MEM_SHARED
396 if (acc_is_present (b) .eqv. .TRUE.) call abort
397 #endif
399 !$acc exit data delete (b(1:N)) if (0 == 1)
401 !$acc enter data copyin (b(1:N)) if (1 == 1)
403 #if !ACC_MEM_SHARED
404 if (acc_is_present (b) .eqv. .FALSE.) call abort
405 #endif
407 !$acc exit data delete (b(1:N)) if (1 == 1)
409 #if !ACC_MEM_SHARED
410 if (acc_is_present (b) .eqv. .TRUE.) call abort
411 #endif
413 !$acc enter data copyin (b(1:N)) if (zero == 1)
415 #if !ACC_MEM_SHARED
416 if (acc_is_present (b) .eqv. .TRUE.) call abort
417 #endif
419 !$acc exit data delete (b(1:N)) if (zero == 1)
421 !$acc enter data copyin (b(1:N)) if (one == 1)
423 #if !ACC_MEM_SHARED
424 if (acc_is_present (b) .eqv. .FALSE.) call abort
425 #endif
427 !$acc exit data delete (b(1:N)) if (one == 1)
429 #if !ACC_MEM_SHARED
430 if (acc_is_present (b) .eqv. .TRUE.) call abort
431 #endif
433 !$acc enter data copyin (b(1:N)) if (one == 0)
435 #if !ACC_MEM_SHARED
436 if (acc_is_present (b) .eqv. .TRUE.) call abort
437 #endif
439 !$acc exit data delete (b(1:N)) if (one == 0)
441 !$acc enter data copyin (b(1:N)) if (one == 1)
443 #if !ACC_MEM_SHARED
444 if (acc_is_present (b) .eqv. .FALSE.) call abort
445 #endif
447 !$acc exit data delete (b(1:N)) if (one == 1)
449 #if !ACC_MEM_SHARED
450 if (acc_is_present (b) .eqv. .TRUE.) call abort
451 #endif
453 a(:) = 4.0
455 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
456 do i = 1, N
457 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
458 b(i) = a(i) + 1
459 else
460 b(i) = a(i)
461 end if
462 end do
463 !$acc end kernels
465 #if ACC_MEM_SHARED
466 exp = 5.0
467 #else
468 exp = 4.0
469 #endif
471 do i = 1, N
472 if (b(i) .ne. exp) call abort
473 end do
475 a(:) = 16.0
477 !$acc kernels if (0 == 1)
478 do i = 1, N
479 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
480 b(i) = a(i) + 1
481 else
482 b(i) = a(i)
483 end if
484 end do
485 !$acc end kernels
487 do i = 1, N
488 if (b(i) .ne. 17.0) call abort
489 end do
491 a(:) = 8.0
493 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (one == 1)
494 do i = 1, N
495 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
496 b(i) = a(i) + 1
497 else
498 b(i) = a(i)
499 end if
500 end do
501 !$acc end kernels
503 #if ACC_MEM_SHARED
504 exp = 9.0
505 #else
506 exp = 8.0
507 #endif
509 do i = 1, N
510 if (b(i) .ne. exp) call abort
511 end do
513 a(:) = 22.0
515 !$acc kernels if (zero == 1)
516 do i = 1, N
517 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
518 b(i) = a(i) + 1
519 else
520 b(i) = a(i)
521 end if
522 end do
523 !$acc end kernels
525 do i = 1, N
526 if (b(i) .ne. 23.0) call abort
527 end do
529 a(:) = 16.0
531 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (.TRUE.)
532 do i = 1, N
533 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
534 b(i) = a(i) + 1
535 else
536 b(i) = a(i)
537 end if
538 end do
539 !$acc end kernels
541 #if ACC_MEM_SHARED
542 exp = 17.0;
543 #else
544 exp = 16.0;
545 #endif
547 do i = 1, N
548 if (b(i) .ne. exp) call abort
549 end do
551 a(:) = 76.0
553 !$acc kernels if (.FALSE.)
554 do i = 1, N
555 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
556 b(i) = a(i) + 1
557 else
558 b(i) = a(i)
559 end if
560 end do
561 !$acc end kernels
563 do i = 1, N
564 if (b(i) .ne. 77.0) call abort
565 end do
567 a(:) = 22.0
569 nn = 1
571 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (nn == 1)
572 do i = 1, N
573 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
574 b(i) = a(i) + 1
575 else
576 b(i) = a(i)
577 end if
578 end do
579 !$acc end kernels
581 #if ACC_MEM_SHARED
582 exp = 23.0;
583 #else
584 exp = 22.0;
585 #endif
587 do i = 1, N
588 if (b(i) .ne. exp) call abort
589 end do
591 a(:) = 18.0
593 nn = 0
595 !$acc kernels if (nn == 1)
596 do i = 1, N
597 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
598 b(i) = a(i) + 1
599 else
600 b(i) = a(i)
601 end if
602 end do
603 !$acc end kernels
605 do i = 1, N
606 if (b(i) .ne. 19.0) call abort
607 end do
609 a(:) = 49.0
611 nn = 1
613 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if ((nn + nn) > 0)
614 do i = 1, N
615 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
616 b(i) = a(i) + 1
617 else
618 b(i) = a(i)
619 end if
620 end do
621 !$acc end kernels
623 #if ACC_MEM_SHARED
624 exp = 50.0
625 #else
626 exp = 49.0
627 #endif
629 do i = 1, N
630 if (b(i) .ne. exp) call abort
631 end do
633 a(:) = 38.0
635 nn = 0;
637 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if ((nn + nn) > 0)
638 do i = 1, N
639 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
640 b(i) = a(i) + 1
641 else
642 b(i) = a(i)
643 end if
644 end do
645 !$acc end kernels
647 do i = 1, N
648 if (b(i) .ne. 39.0) call abort
649 end do
651 a(:) = 91.0
653 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (-2 > 0)
654 do i = 1, N
655 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
656 b(i) = a(i) + 1
657 else
658 b(i) = a(i)
659 end if
660 end do
661 !$acc end kernels
663 do i = 1, N
664 if (b(i) .ne. 92.0) call abort
665 end do
667 a(:) = 43.0
669 !$acc kernels copyin (a(1:N)) copyout (b(1:N)) if (one == 1)
670 do i = 1, N
671 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
672 b(i) = a(i) + 1
673 else
674 b(i) = a(i)
675 end if
676 end do
677 !$acc end kernels
679 #if ACC_MEM_SHARED
680 exp = 44.0
681 #else
682 exp = 43.0
683 #endif
685 do i = 1, N
686 if (b(i) .ne. exp) call abort
687 end do
689 a(:) = 87.0
691 !$acc kernels if (one == 0)
692 do i = 1, N
693 if (acc_on_device (acc_device_host) .eqv. .TRUE.) then
694 b(i) = a(i) + 1
695 else
696 b(i) = a(i)
697 end if
698 end do
699 !$acc end kernels
701 do i = 1, N
702 if (b(i) .ne. 88.0) call abort
703 end do
705 a(:) = 3.0
706 b(:) = 9.0
708 #if ACC_MEM_SHARED
709 exp = 0.0
710 exp2 = 0.0
711 #else
712 call acc_copyin (a, sizeof (a))
713 call acc_copyin (b, sizeof (b))
714 exp = 3.0;
715 exp2 = 9.0;
716 #endif
718 !$acc update device (a(1:N), b(1:N)) if (1 == 1)
720 a(:) = 0.0
721 b(:) = 0.0
723 !$acc update host (a(1:N), b(1:N)) if (1 == 1)
725 do i = 1, N
726 if (a(i) .ne. exp) call abort
727 if (b(i) .ne. exp2) call abort
728 end do
730 a(:) = 6.0
731 b(:) = 12.0
733 !$acc update device (a(1:N), b(1:N)) if (0 == 1)
735 a(:) = 0.0
736 b(:) = 0.0
738 !$acc update host (a(1:N), b(1:N)) if (1 == 1)
740 do i = 1, N
741 if (a(i) .ne. exp) call abort
742 if (b(i) .ne. exp2) call abort
743 end do
745 a(:) = 26.0
746 b(:) = 21.0
748 !$acc update device (a(1:N), b(1:N)) if (1 == 1)
750 a(:) = 0.0
751 b(:) = 0.0
753 !$acc update host (a(1:N), b(1:N)) if (0 == 1)
755 do i = 1, N
756 if (a(i) .ne. 0.0) call abort
757 if (b(i) .ne. 0.0) call abort
758 end do
760 #if !ACC_MEM_SHARED
761 call acc_copyout (a, sizeof (a))
762 call acc_copyout (b, sizeof (b))
763 #endif
765 a(:) = 4.0
766 b(:) = 0.0
768 !$acc data copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
770 !$acc kernels present (a(1:N))
771 do i = 1, N
772 b(i) = a(i)
773 end do
774 !$acc end kernels
775 !$acc end data
777 do i = 1, N
778 if (b(i) .ne. 4.0) call abort
779 end do
781 a(:) = 8.0
782 b(:) = 1.0
784 !$acc data copyin (a(1:N)) copyout (b(1:N)) if (0 == 1)
786 #if !ACC_MEM_SHARED
787 if (acc_is_present (a) .eqv. .TRUE.) call abort
788 if (acc_is_present (b) .eqv. .TRUE.) call abort
789 #endif
791 !$acc end data
793 a(:) = 18.0
794 b(:) = 21.0
796 !$acc data copyin (a(1:N)) if (1 == 1)
798 #if !ACC_MEM_SHARED
799 if (acc_is_present (a) .eqv. .FALSE.) call abort
800 #endif
802 !$acc data copyout (b(1:N)) if (0 == 1)
803 #if !ACC_MEM_SHARED
804 if (acc_is_present (b) .eqv. .TRUE.) call abort
805 #endif
806 !$acc data copyout (b(1:N)) if (1 == 1)
808 !$acc kernels present (a(1:N)) present (b(1:N))
809 do i = 1, N
810 b(i) = a(i)
811 end do
812 !$acc end kernels
814 !$acc end data
816 #if !ACC_MEM_SHARED
817 if (acc_is_present (b) .eqv. .TRUE.) call abort
818 #endif
819 !$acc end data
820 !$acc end data
822 do i = 1, N
823 if (b(1) .ne. 18.0) call abort
824 end do
826 !$acc enter data copyin (b(1:N)) if (0 == 1)
828 #if !ACC_MEM_SHARED
829 if (acc_is_present (b) .eqv. .TRUE.) call abort
830 #endif
832 !$acc exit data delete (b(1:N)) if (0 == 1)
834 !$acc enter data copyin (b(1:N)) if (1 == 1)
836 #if !ACC_MEM_SHARED
837 if (acc_is_present (b) .eqv. .FALSE.) call abort
838 #endif
840 !$acc exit data delete (b(1:N)) if (1 == 1)
842 #if !ACC_MEM_SHARED
843 if (acc_is_present (b) .eqv. .TRUE.) call abort
844 #endif
846 !$acc enter data copyin (b(1:N)) if (zero == 1)
848 #if !ACC_MEM_SHARED
849 if (acc_is_present (b) .eqv. .TRUE.) call abort
850 #endif
852 !$acc exit data delete (b(1:N)) if (zero == 1)
854 !$acc enter data copyin (b(1:N)) if (one == 1)
856 #if !ACC_MEM_SHARED
857 if (acc_is_present (b) .eqv. .FALSE.) call abort
858 #endif
860 !$acc exit data delete (b(1:N)) if (one == 1)
862 #if !ACC_MEM_SHARED
863 if (acc_is_present (b) .eqv. .TRUE.) call abort
864 #endif
866 !$acc enter data copyin (b(1:N)) if (one == 0)
868 #if !ACC_MEM_SHARED
869 if (acc_is_present (b) .eqv. .TRUE.) call abort
870 #endif
872 !$acc exit data delete (b(1:N)) if (one == 0)
874 !$acc enter data copyin (b(1:N)) if (one == 1)
876 #if !ACC_MEM_SHARED
877 if (acc_is_present (b) .eqv. .FALSE.) call abort
878 #endif
880 !$acc exit data delete (b(1:N)) if (one == 1)
882 #if !ACC_MEM_SHARED
883 if (acc_is_present (b) .eqv. .TRUE.) call abort
884 #endif
886 end program main