1! { dg-do run }
2! { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } }
3
4program main
5  use openacc
6  implicit none
7
8  integer, parameter :: N = 32
9  real, allocatable :: a(:), b(:), c(:)
10  integer i
11
12  i = 0
13
14  allocate (a(N))
15  allocate (b(N))
16  allocate (c(N))
17
18  a(:) = 3.0
19  b(:) = 0.0
20
21  !$acc parallel copyin (a(1:N)) copyout (b(1:N))
22    do i = 1, N
23      b(i) = a(i)
24    end do
25  !$acc end parallel
26
27  do i = 1, N
28    if (b(i) .ne. 3.0) STOP 1
29  end do
30
31  if (acc_is_present (a) .eqv. .TRUE.) STOP 2
32  if (acc_is_present (b) .eqv. .TRUE.) STOP 3
33
34  a(:) = 5.0
35  b(:) = 1.0
36
37  !$acc parallel copyin (a(1:N)) copyout (b(1:N))
38    do i = 1, N
39      b(i) = a(i)
40    end do
41  !$acc end parallel
42
43  do i = 1, N
44    if (b(i) .ne. 5.0) STOP 4
45  end do
46
47  if (acc_is_present (a) .eqv. .TRUE.) STOP 5
48  if (acc_is_present (b) .eqv. .TRUE.) STOP 6
49
50  a(:) = 6.0
51  b(:) = 0.0
52
53  call acc_copyin (a, sizeof (a))
54
55  a(:) = 9.0
56
57  !$acc parallel present_or_copyin (a(1:N)) copyout (b(1:N))
58    do i = 1, N
59      b(i) = a(i)
60    end do
61  !$acc end parallel
62
63  do i = 1, N
64    if (b(i) .ne. 6.0) STOP 7
65  end do
66
67  call acc_copyout (a, sizeof (a))
68
69  if (acc_is_present (a) .eqv. .TRUE.) STOP 8
70  if (acc_is_present (b) .eqv. .TRUE.) STOP 9
71
72  a(:) = 6.0
73  b(:) = 0.0
74
75  !$acc parallel copyin (a(1:N)) present_or_copyout (b(1:N))
76     do i = 1, N
77       b(i) = a(i)
78     end do
79  !$acc end parallel
80
81  do i = 1, N
82     if (b(i) .ne. 6.0) STOP 10
83  end do
84
85  if (acc_is_present (a) .eqv. .TRUE.) STOP 11
86  if (acc_is_present (b) .eqv. .TRUE.) STOP 12
87
88  a(:) = 5.0
89  b(:) = 2.0
90
91  call acc_copyin (b, sizeof (b))
92
93  !$acc parallel copyin (a(1:N)) present_or_copyout (b(1:N))
94     do i = 1, N
95       b(i) = a(i)
96     end do
97  !$acc end parallel
98
99  do i = 1, N
100    if (a(i) .ne. 5.0) STOP 13
101    if (b(i) .ne. 2.0) STOP 14
102  end do
103
104  call acc_copyout (b, sizeof (b))
105
106  if (acc_is_present (a) .eqv. .TRUE.) STOP 15
107  if (acc_is_present (b) .eqv. .TRUE.) STOP 16
108
109  a(:) = 3.0;
110  b(:) = 4.0;
111
112  !$acc parallel copy (a(1:N)) copyout (b(1:N))
113    do i = 1, N
114      a(i) = a(i) + 1
115      b(i) = a(i) + 2
116    end do
117  !$acc end parallel
118
119  do i = 1, N
120    if (a(i) .ne. 4.0) STOP 17
121    if (b(i) .ne. 6.0) STOP 18
122  end do
123
124  if (acc_is_present (a) .eqv. .TRUE.) STOP 19
125  if (acc_is_present (b) .eqv. .TRUE.) STOP 20
126
127  a(:) = 4.0
128  b(:) = 7.0
129
130  !$acc parallel present_or_copy (a(1:N)) present_or_copy (b(1:N))
131    do i = 1, N
132      a(i) = a(i) + 1
133      b(i) = b(i) + 2
134    end do
135  !$acc end parallel
136
137  do i = 1, N
138    if (a(i) .ne. 5.0) STOP 21
139    if (b(i) .ne. 9.0) STOP 22
140  end do
141
142  if (acc_is_present (a) .eqv. .TRUE.) STOP 23
143  if (acc_is_present (b) .eqv. .TRUE.) STOP 24
144
145  a(:) = 3.0
146  b(:) = 7.0
147
148  call acc_copyin (a, sizeof (a))
149  call acc_copyin (b, sizeof (b))
150
151  !$acc parallel present_or_copy (a(1:N)) present_or_copy (b(1:N))
152    do i = 1, N
153      a(i) = a(i) + 1
154      b(i) = b(i) + 2
155    end do
156  !$acc end parallel
157
158  do i = 1, N
159    if (a(i) .ne. 3.0) STOP 25
160    if (b(i) .ne. 7.0) STOP 26
161  end do
162
163  call acc_copyout (a, sizeof (a))
164  call acc_copyout (b, sizeof (b))
165
166  if (acc_is_present (a) .eqv. .TRUE.) STOP 27
167  if (acc_is_present (b) .eqv. .TRUE.) STOP 28
168
169  a(:) = 3.0
170  b(:) = 7.0
171
172  !$acc parallel copyin (a(1:N)) create (c(1:N)) copyout (b(1:N))
173    do i = 1, N
174      c(i) = a(i)
175      b(i) = c(i)
176    end do
177  !$acc end parallel
178
179  do i = 1, N
180    if (a(i) .ne. 3.0) STOP 29
181    if (b(i) .ne. 3.0) STOP 30
182  end do
183
184  if (acc_is_present (a) .eqv. .TRUE.) STOP 31
185  if (acc_is_present (b) .eqv. .TRUE.) STOP 32
186  if (acc_is_present (c) .eqv. .TRUE.) STOP 33
187
188  a(:) = 4.0
189  b(:) = 8.0
190
191  !$acc parallel copyin (a(1:N)) present_or_create (c(1:N)) copyout (b(1:N))
192    do i = 1, N
193      c(i) = a(i)
194      b(i) = c(i)
195    end do
196  !$acc end parallel
197
198  do i = 1, N
199    if (a(i) .ne. 4.0) STOP 34
200    if (b(i) .ne. 4.0) STOP 35
201  end do
202
203  if (acc_is_present (a) .eqv. .TRUE.) STOP 36
204  if (acc_is_present (b) .eqv. .TRUE.) STOP 37
205  if (acc_is_present (c) .eqv. .TRUE.) STOP 38
206
207  a(:) = 4.0
208
209  call acc_copyin (a, sizeof (a))
210  call acc_copyin (b, sizeof (b))
211  call acc_copyin (c, sizeof (c))
212
213  !$acc parallel present (a(1:N)) present (c(1:N)) present (b(1:N))
214    do i = 1, N
215      c(i) = a(i)
216      b(i) = c(i)
217    end do
218  !$acc end parallel
219
220  call acc_copyout (a, sizeof (a))
221  call acc_copyout (b, sizeof (b))
222  call acc_copyout (c, sizeof (c))
223
224  do i = 1, N
225    if (a(i) .ne. 4.0) STOP 39
226    if (b(i) .ne. 4.0) STOP 40
227  end do
228
229  if (acc_is_present (a) .eqv. .TRUE.) STOP 41
230  if (acc_is_present (b) .eqv. .TRUE.) STOP 42
231  if (acc_is_present (c) .eqv. .TRUE.) STOP 43
232
233  a(:) = 6.0
234  b(:) = 0.0
235
236  call acc_copyin (a, sizeof (a))
237
238  a(:) = 9.0
239
240  !$acc parallel pcopyin (a(1:N)) copyout (b(1:N))
241    do i = 1, N
242      b(i) = a(i)
243    end do
244  !$acc end parallel
245
246  do i = 1, N
247    if (b(i) .ne. 6.0) STOP 44
248  end do
249
250  call acc_copyout (a, sizeof (a))
251
252  if (acc_is_present (a) .eqv. .TRUE.) STOP 45
253  if (acc_is_present (b) .eqv. .TRUE.) STOP 46
254
255  a(:) = 6.0
256  b(:) = 0.0
257
258  !$acc parallel copyin (a(1:N)) pcopyout (b(1:N))
259   do i = 1, N
260     b(i) = a(i)
261   end do
262  !$acc end parallel
263
264  do i = 1, N
265    if (b(i) .ne. 6.0) STOP 47
266  end do
267
268  if (acc_is_present (a) .eqv. .TRUE.) STOP 48
269  if (acc_is_present (b) .eqv. .TRUE.) STOP 49
270
271  a(:) = 5.0
272  b(:) = 7.0
273
274  !$acc parallel copyin (a(1:N)) pcreate (c(1:N)) copyout (b(1:N))
275    do i = 1, N
276      c(i) = a(i)
277      b(i) = c(i)
278    end do
279  !$acc end parallel
280
281  do i = 1, N
282    if (a(i) .ne. 5.0) STOP 50
283    if (b(i) .ne. 5.0) STOP 51
284  end do
285
286  if (acc_is_present (a) .eqv. .TRUE.) STOP 52
287  if (acc_is_present (b) .eqv. .TRUE.) STOP 53
288  if (acc_is_present (c) .eqv. .TRUE.) STOP 54
289
290end program main
291