1! { dg-do run }
2! { dg-additional-options "-cpp" }
3
4program main
5  use openacc
6  implicit none
7
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
14
15  i = 0
16
17  allocate (a(N))
18  allocate (b(N))
19
20  a(:) = 4.0
21
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
31
32#if ACC_MEM_SHARED
33  exp = 5.0
34#else
35  exp = 4.0
36#endif
37
38  do i = 1, N
39    if (b(i) .ne. exp) STOP 1
40  end do
41
42  a(:) = 16.0
43
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
53
54  do i = 1, N
55    if (b(i) .ne. 17.0) STOP 2
56  end do
57
58  a(:) = 8.0
59
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
69
70#if ACC_MEM_SHARED
71  exp = 9.0
72#else
73  exp = 8.0
74#endif
75
76  do i = 1, N
77    if (b(i) .ne. exp) STOP 3
78  end do
79
80  a(:) = 22.0
81
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
91
92  do i = 1, N
93    if (b(i) .ne. 23.0) STOP 4
94  end do
95
96  a(:) = 16.0
97
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
107
108#if ACC_MEM_SHARED
109  exp = 17.0;
110#else
111  exp = 16.0;
112#endif
113
114  do i = 1, N
115    if (b(i) .ne. exp) STOP 5
116  end do
117
118  a(:) = 76.0
119
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
129
130  do i = 1, N
131    if (b(i) .ne. 77.0) STOP 6
132  end do
133
134  a(:) = 22.0
135
136  nn = 1
137
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
147
148#if ACC_MEM_SHARED
149  exp = 23.0;
150#else
151  exp = 22.0;
152#endif
153
154  do i = 1, N
155    if (b(i) .ne. exp) STOP 7
156  end do
157
158  a(:) = 18.0
159
160  nn = 0
161
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
171
172  do i = 1, N
173    if (b(i) .ne. 19.0) STOP 8
174  end do
175
176  a(:) = 49.0
177
178  nn = 1
179
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
189
190#if ACC_MEM_SHARED
191  exp = 50.0
192#else
193  exp = 49.0
194#endif
195
196  do i = 1, N
197    if (b(i) .ne. exp) STOP 9
198  end do
199
200  a(:) = 38.0
201
202  nn = 0;
203
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
213
214  do i = 1, N
215    if (b(i) .ne. 39.0) STOP 10
216  end do
217
218  a(:) = 91.0
219
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
229
230  do i = 1, N
231    if (b(i) .ne. 92.0) STOP 11
232  end do
233
234  a(:) = 43.0
235
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
245
246#if ACC_MEM_SHARED
247  exp = 44.0
248#else
249  exp = 43.0
250#endif
251
252  do i = 1, N
253    if (b(i) .ne. exp) STOP 12
254  end do
255
256  a(:) = 87.0
257
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
267
268  do i = 1, N
269    if (b(i) .ne. 88.0) STOP 13
270  end do
271
272  a(:) = 3.0
273  b(:) = 9.0
274
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
284
285  !$acc update device (a(1:N), b(1:N)) if (1 == 1)
286
287  a(:) = 0.0
288  b(:) = 0.0
289
290  !$acc update host (a(1:N), b(1:N)) if (1 == 1)
291
292  do i = 1, N
293    if (a(i) .ne. exp) STOP 14
294    if (b(i) .ne. exp2) STOP 15
295  end do
296
297  a(:) = 6.0
298  b(:) = 12.0
299
300  !$acc update device (a(1:N), b(1:N)) if (0 == 1)
301
302  a(:) = 0.0
303  b(:) = 0.0
304
305  !$acc update host (a(1:N), b(1:N)) if (1 == 1)
306
307  do i = 1, N
308    if (a(i) .ne. exp) STOP 16
309    if (b(i) .ne. exp2) STOP 17
310  end do
311
312  a(:) = 26.0
313  b(:) = 21.0
314
315  !$acc update device (a(1:N), b(1:N)) if (1 == 1)
316
317  a(:) = 0.0
318  b(:) = 0.0
319
320  !$acc update host (a(1:N), b(1:N)) if (0 == 1)
321
322  do i = 1, N
323    if (a(i) .ne. 0.0) STOP 18
324    if (b(i) .ne. 0.0) STOP 19
325  end do
326
327#if !ACC_MEM_SHARED
328  call acc_copyout (a, sizeof (a))
329  call acc_copyout (b, sizeof (b))
330#endif
331
332  a(:) = 4.0
333  b(:) = 0.0
334
335  !$acc data copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
336
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
343
344  do i = 1, N
345    if (b(i) .ne. 4.0) STOP 20
346  end do
347
348  a(:) = 8.0
349  b(:) = 1.0
350
351  !$acc data copyin (a(1:N)) copyout (b(1:N)) if (0 == 1)
352
353#if !ACC_MEM_SHARED
354  if (acc_is_present (a) .eqv. .TRUE.) STOP 21
355  if (acc_is_present (b) .eqv. .TRUE.) STOP 22
356#endif
357
358  !$acc end data
359
360  a(:) = 18.0
361  b(:) = 21.0
362
363  !$acc data copyin (a(1:N)) if (1 == 1)
364
365#if !ACC_MEM_SHARED
366    if (acc_is_present (a) .eqv. .FALSE.) STOP 23
367#endif
368
369    !$acc data copyout (b(1:N)) if (0 == 1)
370#if !ACC_MEM_SHARED
371      if (acc_is_present (b) .eqv. .TRUE.) STOP 24
372#endif
373        !$acc data copyout (b(1:N)) if (1 == 1)
374
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
380
381    !$acc end data
382
383#if !ACC_MEM_SHARED
384    if (acc_is_present (b) .eqv. .TRUE.) STOP 25
385#endif
386    !$acc end data
387  !$acc end data
388
389  do i = 1, N
390   if (b(1) .ne. 18.0) STOP 26
391  end do
392
393  !$acc enter data copyin (b(1:N)) if (0 == 1)
394
395#if !ACC_MEM_SHARED
396  if (acc_is_present (b) .eqv. .TRUE.) STOP 27
397#endif
398
399  !$acc exit data delete (b(1:N)) if (0 == 1)
400
401  !$acc enter data copyin (b(1:N)) if (1 == 1)
402
403#if !ACC_MEM_SHARED
404    if (acc_is_present (b) .eqv. .FALSE.) STOP 28
405#endif
406
407  !$acc exit data delete (b(1:N)) if (1 == 1)
408
409#if !ACC_MEM_SHARED
410  if (acc_is_present (b) .eqv. .TRUE.) STOP 29
411#endif
412
413  !$acc enter data copyin (b(1:N)) if (zero == 1)
414
415#if !ACC_MEM_SHARED
416    if (acc_is_present (b) .eqv. .TRUE.) STOP 30
417#endif
418
419  !$acc exit data delete (b(1:N)) if (zero == 1)
420
421  !$acc enter data copyin (b(1:N)) if (one == 1)
422
423#if !ACC_MEM_SHARED
424    if (acc_is_present (b) .eqv. .FALSE.) STOP 31
425#endif
426
427  !$acc exit data delete (b(1:N)) if (one == 1)
428
429#if !ACC_MEM_SHARED
430  if (acc_is_present (b) .eqv. .TRUE.) STOP 32
431#endif
432
433  !$acc enter data copyin (b(1:N)) if (one == 0)
434
435#if !ACC_MEM_SHARED
436    if (acc_is_present (b) .eqv. .TRUE.) STOP 33
437#endif
438
439  !$acc exit data delete (b(1:N)) if (one == 0)
440
441  !$acc enter data copyin (b(1:N)) if (one == 1)
442
443#if !ACC_MEM_SHARED
444    if (acc_is_present (b) .eqv. .FALSE.) STOP 34
445#endif
446
447  !$acc exit data delete (b(1:N)) if (one == 1)
448
449#if !ACC_MEM_SHARED
450  if (acc_is_present (b) .eqv. .TRUE.) STOP 35
451#endif
452
453  a(:) = 4.0
454
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
464
465#if ACC_MEM_SHARED
466  exp = 5.0
467#else
468  exp = 4.0
469#endif
470
471  do i = 1, N
472    if (b(i) .ne. exp) STOP 36
473  end do
474
475  a(:) = 16.0
476
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
486
487  do i = 1, N
488    if (b(i) .ne. 17.0) STOP 37
489  end do
490
491  a(:) = 8.0
492
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
502
503#if ACC_MEM_SHARED
504  exp = 9.0
505#else
506  exp = 8.0
507#endif
508
509  do i = 1, N
510    if (b(i) .ne. exp) STOP 38
511  end do
512
513  a(:) = 22.0
514
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
524
525  do i = 1, N
526    if (b(i) .ne. 23.0) STOP 39
527  end do
528
529  a(:) = 16.0
530
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
540
541#if ACC_MEM_SHARED
542  exp = 17.0;
543#else
544  exp = 16.0;
545#endif
546
547  do i = 1, N
548    if (b(i) .ne. exp) STOP 40
549  end do
550
551  a(:) = 76.0
552
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
562
563  do i = 1, N
564    if (b(i) .ne. 77.0) STOP 41
565  end do
566
567  a(:) = 22.0
568
569  nn = 1
570
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
580
581#if ACC_MEM_SHARED
582  exp = 23.0;
583#else
584  exp = 22.0;
585#endif
586
587  do i = 1, N
588    if (b(i) .ne. exp) STOP 42
589  end do
590
591  a(:) = 18.0
592
593  nn = 0
594
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
604
605  do i = 1, N
606    if (b(i) .ne. 19.0) STOP 43
607  end do
608
609  a(:) = 49.0
610
611  nn = 1
612
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
622
623#if ACC_MEM_SHARED
624  exp = 50.0
625#else
626  exp = 49.0
627#endif
628
629  do i = 1, N
630    if (b(i) .ne. exp) STOP 44
631  end do
632
633  a(:) = 38.0
634
635  nn = 0;
636
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
646
647  do i = 1, N
648    if (b(i) .ne. 39.0) STOP 45
649  end do
650
651  a(:) = 91.0
652
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
662
663  do i = 1, N
664    if (b(i) .ne. 92.0) STOP 46
665  end do
666
667  a(:) = 43.0
668
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
678
679#if ACC_MEM_SHARED
680  exp = 44.0
681#else
682  exp = 43.0
683#endif
684
685  do i = 1, N
686    if (b(i) .ne. exp) STOP 47
687  end do
688
689  a(:) = 87.0
690
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
700
701  do i = 1, N
702    if (b(i) .ne. 88.0) STOP 48
703  end do
704
705  a(:) = 3.0
706  b(:) = 9.0
707
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
717
718  !$acc update device (a(1:N), b(1:N)) if (1 == 1)
719
720  a(:) = 0.0
721  b(:) = 0.0
722
723  !$acc update host (a(1:N), b(1:N)) if (1 == 1)
724
725  do i = 1, N
726    if (a(i) .ne. exp) STOP 49
727    if (b(i) .ne. exp2) STOP 50
728  end do
729
730  a(:) = 6.0
731  b(:) = 12.0
732
733  !$acc update device (a(1:N), b(1:N)) if (0 == 1)
734
735  a(:) = 0.0
736  b(:) = 0.0
737
738  !$acc update host (a(1:N), b(1:N)) if (1 == 1)
739
740  do i = 1, N
741    if (a(i) .ne. exp) STOP 51
742    if (b(i) .ne. exp2) STOP 52
743  end do
744
745  a(:) = 26.0
746  b(:) = 21.0
747
748  !$acc update device (a(1:N), b(1:N)) if (1 == 1)
749
750  a(:) = 0.0
751  b(:) = 0.0
752
753  !$acc update host (a(1:N), b(1:N)) if (0 == 1)
754
755  do i = 1, N
756    if (a(i) .ne. 0.0) STOP 53
757    if (b(i) .ne. 0.0) STOP 54
758  end do
759
760#if !ACC_MEM_SHARED
761  call acc_copyout (a, sizeof (a))
762  call acc_copyout (b, sizeof (b))
763#endif
764
765  a(:) = 4.0
766  b(:) = 0.0
767
768  !$acc data copyin (a(1:N)) copyout (b(1:N)) if (1 == 1)
769
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
776
777  do i = 1, N
778    if (b(i) .ne. 4.0) STOP 55
779  end do
780
781  a(:) = 8.0
782  b(:) = 1.0
783
784  !$acc data copyin (a(1:N)) copyout (b(1:N)) if (0 == 1)
785
786#if !ACC_MEM_SHARED
787  if (acc_is_present (a) .eqv. .TRUE.) STOP 56
788  if (acc_is_present (b) .eqv. .TRUE.) STOP 57
789#endif
790
791  !$acc end data
792
793  a(:) = 18.0
794  b(:) = 21.0
795
796  !$acc data copyin (a(1:N)) if (1 == 1)
797
798#if !ACC_MEM_SHARED
799    if (acc_is_present (a) .eqv. .FALSE.) STOP 58
800#endif
801
802    !$acc data copyout (b(1:N)) if (0 == 1)
803#if !ACC_MEM_SHARED
804      if (acc_is_present (b) .eqv. .TRUE.) STOP 59
805#endif
806        !$acc data copyout (b(1:N)) if (1 == 1)
807
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
813
814    !$acc end data
815
816#if !ACC_MEM_SHARED
817    if (acc_is_present (b) .eqv. .TRUE.) STOP 60
818#endif
819    !$acc end data
820  !$acc end data
821
822  do i = 1, N
823   if (b(1) .ne. 18.0) STOP 61
824  end do
825
826  !$acc enter data copyin (b(1:N)) if (0 == 1)
827
828#if !ACC_MEM_SHARED
829  if (acc_is_present (b) .eqv. .TRUE.) STOP 62
830#endif
831
832  !$acc exit data delete (b(1:N)) if (0 == 1)
833
834  !$acc enter data copyin (b(1:N)) if (1 == 1)
835
836#if !ACC_MEM_SHARED
837    if (acc_is_present (b) .eqv. .FALSE.) STOP 63
838#endif
839
840  !$acc exit data delete (b(1:N)) if (1 == 1)
841
842#if !ACC_MEM_SHARED
843  if (acc_is_present (b) .eqv. .TRUE.) STOP 64
844#endif
845
846  !$acc enter data copyin (b(1:N)) if (zero == 1)
847
848#if !ACC_MEM_SHARED
849    if (acc_is_present (b) .eqv. .TRUE.) STOP 65
850#endif
851
852  !$acc exit data delete (b(1:N)) if (zero == 1)
853
854  !$acc enter data copyin (b(1:N)) if (one == 1)
855
856#if !ACC_MEM_SHARED
857    if (acc_is_present (b) .eqv. .FALSE.) STOP 66
858#endif
859
860  !$acc exit data delete (b(1:N)) if (one == 1)
861
862#if !ACC_MEM_SHARED
863  if (acc_is_present (b) .eqv. .TRUE.) STOP 67
864#endif
865
866  !$acc enter data copyin (b(1:N)) if (one == 0)
867
868#if !ACC_MEM_SHARED
869    if (acc_is_present (b) .eqv. .TRUE.) STOP 68
870#endif
871
872  !$acc exit data delete (b(1:N)) if (one == 0)
873
874  !$acc enter data copyin (b(1:N)) if (one == 1)
875
876#if !ACC_MEM_SHARED
877    if (acc_is_present (b) .eqv. .FALSE.) STOP 69
878#endif
879
880  !$acc exit data delete (b(1:N)) if (one == 1)
881
882#if !ACC_MEM_SHARED
883  if (acc_is_present (b) .eqv. .TRUE.) STOP 70
884#endif
885
886end program main
887