[clang-format][NFC] Add a TypeScript test case
[llvm-project.git] / flang / test / Semantics / OpenACC / acc-loop.f90
blob859cf3feec0d6700fb2ede161f6f7ba4a6af2857
1 ! RUN: %python %S/../test_errors.py %s %flang -fopenacc
3 ! Check OpenACC clause validity for the following construct and directive:
4 ! 2.9 Loop
6 program openacc_loop_validity
8 implicit none
10 type atype
11 real(8), dimension(10) :: arr
12 real(8) :: s
13 integer :: n
14 end type atype
16 integer :: i, j, k, b, gang_size, vector_size, worker_size
17 integer, parameter :: N = 256
18 integer, dimension(N) :: c
19 logical, dimension(N) :: d, e
20 integer :: async1
21 integer :: wait1, wait2
22 real :: reduction_r
23 logical :: reduction_l
24 real(8), dimension(N, N) :: aa, bb, cc
25 logical :: ifCondition = .TRUE.
26 type(atype) :: t
27 type(atype), dimension(10) :: ta
29 real(8), dimension(N) :: a, f, g, h
31 !$acc parallel
32 !$acc loop tile(2)
33 do i = 1, N
34 a(i) = 3.14
35 end do
36 !$acc end parallel
38 !$acc parallel device_type(*) num_gangs(2)
39 !$acc loop
40 do i = 1, N
41 a(i) = 3.14
42 end do
43 !$acc end parallel
45 !$acc parallel
46 !$acc loop seq
47 do i = 1, N
48 a(i) = 3.14
49 end do
50 !$acc end parallel
52 !$acc parallel
53 !$acc loop independent
54 do i = 1, N
55 a(i) = 3.14
56 end do
57 !$acc end parallel
59 !$acc parallel
60 !$acc loop auto
61 do i = 1, N
62 a(i) = 3.14
63 end do
64 !$acc end parallel
66 !$acc parallel
67 !ERROR: At most one VECTOR clause can appear on the LOOP directive or in group separated by the DEVICE_TYPE clause
68 !$acc loop vector vector(128)
69 do i = 1, N
70 a(i) = 3.14
71 end do
72 !$acc end parallel
74 !$acc parallel
75 !$acc loop vector
76 do i = 1, N
77 a(i) = 3.14
78 end do
79 !$acc end parallel
81 !$acc parallel
82 !$acc loop vector(10)
83 do i = 1, N
84 a(i) = 3.14
85 end do
86 !$acc end parallel
88 !$acc parallel
89 !$acc loop vector(vector_size)
90 do i = 1, N
91 a(i) = 3.14
92 end do
93 !$acc end parallel
95 !$acc parallel
96 !$acc loop vector(length: vector_size)
97 do i = 1, N
98 a(i) = 3.14
99 end do
100 !$acc end parallel
102 !$acc parallel
103 !ERROR: At most one WORKER clause can appear on the LOOP directive or in group separated by the DEVICE_TYPE clause
104 !$acc loop worker worker(10)
105 do i = 1, N
106 a(i) = 3.14
107 end do
108 !$acc end parallel
110 !$acc parallel
111 !$acc loop worker
112 do i = 1, N
113 a(i) = 3.14
114 end do
115 !$acc end parallel
117 !$acc parallel
118 !$acc loop worker(10)
119 do i = 1, N
120 a(i) = 3.14
121 end do
122 !$acc end parallel
124 !$acc parallel
125 !$acc loop worker(worker_size)
126 do i = 1, N
127 a(i) = 3.14
128 end do
129 !$acc end parallel
131 !$acc parallel
132 !$acc loop worker(num: worker_size)
133 do i = 1, N
134 a(i) = 3.14
135 end do
136 !$acc end parallel
138 !$acc parallel
139 !ERROR: At most one GANG clause can appear on the LOOP directive or in group separated by the DEVICE_TYPE clause
140 !$acc loop gang gang(gang_size)
141 do i = 1, N
142 a(i) = 3.14
143 end do
144 !$acc end parallel
146 !$acc loop gang device_type(default) gang(gang_size)
147 do i = 1, N
148 a(i) = 3.14
149 end do
151 !ERROR: At most one GANG clause can appear on the PARALLEL LOOP directive or in group separated by the DEVICE_TYPE clause
152 !$acc parallel loop gang gang(gang_size)
153 do i = 1, N
154 a(i) = 3.14
155 end do
157 !$acc parallel loop gang device_type(default) gang(gang_size)
158 do i = 1, N
159 a(i) = 3.14
160 end do
162 !$acc parallel
163 !$acc loop gang(gang_size)
164 do i = 1, N
165 a(i) = 3.14
166 end do
167 !$acc end parallel
169 !$acc parallel
170 !$acc loop gang(num: gang_size)
171 do i = 1, N
172 a(i) = 3.14
173 end do
174 !$acc end parallel
176 !$acc parallel
177 !$acc loop gang(gang_size, static:*)
178 do i = 1, N
179 a(i) = 3.14
180 end do
181 !$acc end parallel
183 !$acc parallel
184 !$acc loop gang(num: gang_size, static:*)
185 do i = 1, N
186 a(i) = 3.14
187 end do
188 !$acc end parallel
190 !$acc parallel
191 !$acc loop gang(num: gang_size, static: gang_size)
192 do i = 1, N
193 a(i) = 3.14
194 end do
195 !$acc end parallel
197 !$acc parallel
198 !$acc loop private(b, a(:))
199 do i = 1, N
200 a(i) = b
201 end do
202 !$acc end parallel
204 !$acc parallel
205 !$acc loop tile(*)
206 do i = 1, N
207 a(i) = b
208 end do
209 !$acc end parallel
211 !$acc parallel
212 !$acc loop tile(2, 2)
213 do i = 1, N
214 do j = 1, N
215 a(i) = b
216 end do
217 end do
218 !$acc end parallel
220 !$acc parallel
221 !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression
222 !$acc loop collapse(-1)
223 do i = 1, N
224 do j = 1, N
225 a(i) = 3.14 + j
226 end do
227 end do
228 !$acc end parallel
230 !$acc parallel
231 !ERROR: Clause PRIVATE is not allowed after clause DEVICE_TYPE on the LOOP directive
232 !$acc loop device_type(*) private(i)
233 do i = 1, N
234 a(i) = 3.14
235 end do
236 !$acc end parallel
238 !$acc parallel
239 !ERROR: Clause GANG is not allowed if clause SEQ appears on the LOOP directive
240 !$acc loop gang seq
241 do i = 1, N
242 a(i) = 3.14
243 end do
244 !$acc end parallel
246 !$acc parallel
247 !ERROR: Clause WORKER is not allowed if clause SEQ appears on the LOOP directive
248 !$acc loop worker seq
249 do i = 1, N
250 a(i) = 3.14
251 end do
252 !$acc end parallel
254 !$acc parallel
255 !ERROR: Clause VECTOR is not allowed if clause SEQ appears on the LOOP directive
256 !$acc loop vector seq
257 do i = 1, N
258 a(i) = 3.14
259 end do
260 !$acc end parallel
262 !ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the PARALLEL directive
263 !$acc parallel device_type(*) if(.TRUE.)
264 !$acc loop
265 do i = 1, N
266 a(i) = 3.14
267 end do
268 !$acc end parallel
270 !$acc loop collapse(2)
271 do i = 1, N
272 !ERROR: Loop control is not present in the DO LOOP
274 a(i) = 3.14
275 end do
276 end do
278 !ERROR: The num argument is not allowed when dim is specified
279 !$acc loop gang(1, dim: 2)
280 do i = 1, N
281 end do
283 !$acc loop
284 do i = 1, N
285 end do
286 !$acc end loop
288 !$acc loop collapse(2)
289 do i = 1, 10
290 !ERROR: LOOP directive not expected in COLLAPSE loop nest
291 !$acc loop
292 do j = 1, 10
293 end do
294 end do
296 !$acc parallel
297 !$acc loop
298 do i = 1, n
299 if(i == 10) cycle
300 end do
301 !$acc end parallel
303 !$acc loop gang device_type(nvidia) gang(num: 8)
304 DO i = 1, n
305 END DO
307 !$acc loop vector device_type(default) vector(16)
308 DO i = 1, n
309 END DO
311 !$acc loop worker device_type(*) worker(8)
312 DO i = 1, n
313 END DO
315 !$acc loop device_type(multicore) collapse(2)
316 DO i = 1, n
317 DO j = 1, n
318 END DO
319 END DO
321 !ERROR: Trip count must be computable and invariant
322 !$acc loop collapse(2)
323 DO i = 1, n
324 DO j = 1, c(i)
325 END DO
326 END DO
328 !ERROR: Trip count must be computable and invariant
329 !$acc loop collapse(2)
330 DO i = 1, n
331 DO j = 1, i
332 END DO
333 END DO
335 !ERROR: Trip count must be computable and invariant
336 !$acc loop collapse(2)
337 DO i = 1, n
338 DO j = 1, ta(i)%n
339 END DO
340 END DO
342 !ERROR: Trip count must be computable and invariant
343 !$acc parallel loop collapse(2)
344 DO i = 1, n
345 DO j = 1, ta(i)%n
346 END DO
347 END DO
349 !ERROR: Trip count must be computable and invariant
350 !$acc loop collapse(3)
351 DO i = 1, n
352 DO j = 1, n
353 DO k = 1, i
354 END DO
355 END DO
356 END DO
358 end program openacc_loop_validity