1! { dg-do run }
2
3program asyncwait
4  real, allocatable :: a(:), b(:), c(:), d(:), e(:)
5  integer i, N
6
7  N = 64
8
9  allocate (a(N))
10  allocate (b(N))
11  allocate (c(N))
12  allocate (d(N))
13  allocate (e(N))
14
15  a(:) = 3.0
16  b(:) = 0.0
17
18  !$acc enter data copyin (a(1:N)) copyin (b(1:N)) copyin (N) async
19
20  !$acc parallel async wait
21  do i = 1, N
22     b(i) = a(i)
23  end do
24  !$acc end parallel
25
26  !$acc wait
27  !$acc exit data copyout (a(1:N)) copyout (b(1:N))
28
29  do i = 1, N
30     if (a(i) .ne. 3.0) STOP 1
31     if (b(i) .ne. 3.0) STOP 2
32  end do
33
34  a(:) = 2.0
35  b(:) = 0.0
36
37  !$acc enter data copyin (a(1:N)) copyin (b(1:N)) async (1)
38
39  !$acc parallel async (1) wait (1)
40  do i = 1, N
41     b(i) = a(i)
42  end do
43  !$acc end parallel
44
45  !$acc wait (1)
46  !$acc exit data copyout (a(1:N)) copyout (b(1:N))
47
48  do i = 1, N
49     if (a(i) .ne. 2.0) STOP 3
50     if (b(i) .ne. 2.0) STOP 4
51  end do
52
53  a(:) = 3.0
54  b(:) = 0.0
55  c(:) = 0.0
56  d(:) = 0.0
57
58  !$acc enter data copyin (a(1:N)) create (b(1:N)) create (c(1:N)) create (d(1:N))
59
60  !$acc parallel async (1)
61  do i = 1, N
62     b(i) = (a(i) * a(i) * a(i)) / a(i)
63  end do
64  !$acc end parallel
65
66  !$acc parallel async (1)
67  do i = 1, N
68     c(i) = (a(i) * 4) / a(i)
69  end do
70  !$acc end parallel
71
72  !$acc parallel async (1)
73  do i = 1, N
74     d(i) = ((a(i) * a(i)  + a(i)) / a(i)) - a(i)
75  end do
76  !$acc end parallel
77
78  !$acc wait (1)
79  !$acc exit data copyout (a(1:N)) copyout (b(1:N)) copyout (c(1:N)) copyout (d(1:N))
80
81  do i = 1, N
82     if (a(i) .ne. 3.0) STOP 5
83     if (b(i) .ne. 9.0) STOP 6
84     if (c(i) .ne. 4.0) STOP 7
85     if (d(i) .ne. 1.0) STOP 8
86  end do
87
88  a(:) = 2.0
89  b(:) = 0.0
90  c(:) = 0.0
91  d(:) = 0.0
92  e(:) = 0.0
93
94  !$acc enter data copyin (a(1:N)) create (b(1:N)) create (c(1:N)) create (d(1:N)) copyin (e(1:N))
95
96  !$acc parallel async (1)
97  do i = 1, N
98     b(i) = (a(i) * a(i) * a(i)) / a(i)
99  end do
100  !$acc end parallel
101
102  !$acc parallel async (1)
103  do i = 1, N
104     c(i) = (a(i) * 4) / a(i)
105  end do
106  !$acc end parallel
107
108  !$acc parallel async (1)
109  do i = 1, N
110     d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
111  end do
112  !$acc end parallel
113
114  !$acc parallel wait (1) async (1)
115  do i = 1, N
116     e(i) = a(i) + b(i) + c(i) + d(i)
117  end do
118  !$acc end parallel
119
120  !$acc wait (1)
121  !$acc exit data copyout (a(1:N)) copyout (b(1:N)) copyout (c(1:N)) copyout (d(1:N)) copyout (e(1:N))
122  !$acc exit data delete (N)
123
124  do i = 1, N
125     if (a(i) .ne. 2.0) STOP 9
126     if (b(i) .ne. 4.0) STOP 10
127     if (c(i) .ne. 4.0) STOP 11
128     if (d(i) .ne. 1.0) STOP 12
129     if (e(i) .ne. 11.0) STOP 13
130  end do
131end program asyncwait
132