Debian Codegraph @

flang/test/Semantics/OpenMP/clause-validity01.f90

raw
1 ! REQUIRES: openmp_runtime
2
3 ! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag
4 use omp_lib
5 ! Check OpenMP clause validity for the following directives:
6 !
7 ! 2.5 PARALLEL construct
8 ! 2.7.1 Loop construct
9 ! ...
10
11 use iso_c_binding
12 integer :: b = 128
13 integer, allocatable :: allc
14 type(C_PTR) :: cpt
15 integer :: z, c = 32
16 integer, parameter :: num = 16
17 real(8) :: arrayA(256), arrayB(512)
18
19 integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space
20 type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)]
21 integer(omp_allocator_handle_kind) :: xy_alloc
22 xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits)
23
24 arrayA = 1.414
25 arrayB = 3.14
26 N = 1024
27
28 ! 2.5 parallel-clause -> if-clause |
29 ! num-threads-clause |
30 ! default-clause |
31 ! private-clause |
32 ! firstprivate-clause |
33 ! shared-clause |
34 ! copyin-clause |
35 ! reduction-clause |
36 ! proc-bind-clause |
37 ! allocate-clause
38
39 !$omp parallel
40 do i = 1, N
41 a = 3.14
42 enddo
43 !$omp end parallel
44
45 !$omp parallel private(b) allocate(b)
46 do i = 1, N
47 a = 3.14
48 enddo
49 !$omp end parallel
50
51 !$omp parallel private(c, b) allocate(omp_default_mem_space : b, c)
52 do i = 1, N
53 a = 3.14
54 enddo
55 !$omp end parallel
56
57 !$omp parallel allocate(b) allocate(c) private(b, c)
58 do i = 1, N
59 a = 3.14
60 enddo
61 !$omp end parallel
62
63 !$omp parallel allocate(xy_alloc :b) private(b)
64 do i = 1, N
65 a = 3.14
66 enddo
67 !$omp end parallel
68
69 !$omp task private(b) allocate(b)
70 do i = 1, N
71 z = 2
72 end do
73 !$omp end task
74
75 !$omp teams private(b) allocate(b)
76 do i = 1, N
77 z = 2
78 end do
79 !$omp end teams
80
81 !$omp target private(b) allocate(b)
82 do i = 1, N
83 z = 2
84 end do
85 !$omp end target
86
87 !ERROR: ALLOCATE clause is not allowed on the TARGET DATA directive
88 !$omp target data map(from: b) allocate(b)
89 do i = 1, N
90 z = 2
91 enddo
92 !$omp end target data
93
94 !ERROR: SCHEDULE clause is not allowed on the PARALLEL directive
95 !$omp parallel schedule(static)
96 do i = 1, N
97 a = 3.14
98 enddo
99 !$omp end parallel
100
101 !ERROR: COLLAPSE clause is not allowed on the PARALLEL directive
102 !$omp parallel collapse(2)
103 do i = 1, N
104 do j = 1, N
105 a = 3.14
106 enddo
107 enddo
108 !$omp end parallel
109
110 !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression
111 !$omp do collapse(-1)
112 do i = 1, N
113 do j = 1, N
114 a = 3.14
115 enddo
116 enddo
117 !$omp end do
118
119 a = 1.0
120 !$omp parallel firstprivate(a)
121 do i = 1, N
122 a = 3.14
123 enddo
124 !ERROR: NUM_THREADS clause is not allowed on the END PARALLEL directive
125 !$omp end parallel num_threads(4)
126
127 !ERROR: LASTPRIVATE clause is not allowed on the PARALLEL directive
128 !ERROR: NUM_TASKS clause is not allowed on the PARALLEL directive
129 !ERROR: INBRANCH clause is not allowed on the PARALLEL directive
130 !$omp parallel lastprivate(a) NUM_TASKS(4) inbranch
131 do i = 1, N
132 a = 3.14
133 enddo
134 !$omp end parallel
135
136 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL directive
137 !$omp parallel num_threads(2) num_threads(4)
138 do i = 1, N
139 a = 3.14
140 enddo
141 !$omp end parallel
142
143 !ERROR: The parameter of the NUM_THREADS clause must be a positive integer expression
144 !$omp parallel num_threads(1-4)
145 do i = 1, N
146 a = 3.14
147 enddo
148 !ERROR: NOWAIT clause is not allowed on the END PARALLEL directive
149 !$omp end parallel nowait
150
151 !$omp parallel num_threads(num-10)
152 do i = 1, N
153 a = 3.14
154 enddo
155 !$omp end parallel
156
157 !$omp parallel num_threads(b+1)
158 do i = 1, N
159 a = 3.14
160 enddo
161 !$omp end parallel
162
163 !$omp parallel
164 do i = 1, N
165 enddo
166 !ERROR: Unmatched END TARGET directive
167 !$omp end target
168
169 ! OMP 5.0 - 2.6 Restriction point 1
170 outofparallel: do k =1, 10
171 !$omp parallel
172 !$omp do
173 outer: do i=0, 10
174 inner: do j=1, 10
175 exit
176 !ERROR: EXIT statement terminates associated loop of an OpenMP DO construct
177 exit outer
178 !ERROR: EXIT to construct 'outofparallel' outside of PARALLEL construct is not allowed
179 !ERROR: EXIT to construct 'outofparallel' outside of DO construct is not allowed
180 exit outofparallel
181 end do inner
182 end do outer
183 !$omp end do
184 !$omp end parallel
185 end do outofparallel
186
187 ! 2.7.1 do-clause -> private-clause |
188 ! firstprivate-clause |
189 ! lastprivate-clause |
190 ! linear-clause |
191 ! reduction-clause |
192 ! schedule-clause |
193 ! collapse-clause |
194 ! ordered-clause
195
196 !ERROR: When SCHEDULE clause has AUTO specified, it must not have chunk size specified
197 !ERROR: At most one SCHEDULE clause can appear on the DO directive
198 !ERROR: When SCHEDULE clause has RUNTIME specified, it must not have chunk size specified
199 !$omp do schedule(auto, 2) schedule(runtime, 2)
200 do i = 1, N
201 a = 3.14
202 enddo
203
204 !ERROR: A modifier may not be specified in a LINEAR clause on the DO directive
205 !$omp do linear(ref(b))
206 do i = 1, N
207 a = 3.14
208 enddo
209
210 !ERROR: The NONMONOTONIC modifier can only be specified with SCHEDULE(DYNAMIC) or SCHEDULE(GUIDED)
211 !ERROR: The NONMONOTONIC modifier cannot be specified if an ORDERED clause is specified
212 !$omp do schedule(NONMONOTONIC:static) ordered
213 do i = 1, N
214 a = 3.14
215 enddo
216
217 !$omp do schedule(simd, monotonic:dynamic)
218 do i = 1, N
219 a = 3.14
220 enddo
221
222 !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
223 !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
224 !$omp do ordered(1-1) private(b) linear(b) linear(a)
225 do i = 1, N
226 a = 3.14
227 enddo
228
229 !ERROR: The parameter of the ORDERED clause must be greater than or equal to the parameter of the COLLAPSE clause
230 !$omp do collapse(num-14) ordered(1)
231 do i = 1, N
232 do j = 1, N
233 do k = 1, N
234 a = 3.14
235 enddo
236 enddo
237 enddo
238
239 !$omp parallel do simd if(parallel:a>1.)
240 do i = 1, N
241 enddo
242 !$omp end parallel do simd
243
244 !ERROR: Unmatched directive name modifier TARGET on the IF clause
245 !$omp parallel do if(target:a>1.)
246 do i = 1, N
247 enddo
248 !ERROR: Unmatched END SIMD directive
249 !$omp end simd
250
251 ! 2.7.2 sections-clause -> private-clause |
252 ! firstprivate-clause |
253 ! lastprivate-clause |
254 ! reduction-clause
255
256 !$omp parallel
257 !$omp sections
258 !$omp section
259 a = 0.0
260 !$omp section
261 b = 1
262 !$omp end sections nowait
263 !$omp end parallel
264
265 !$omp parallel
266 !$omp sections
267 !$omp section
268 a = 0.0
269 !ERROR: Unmatched END PARALLEL SECTIONS directive
270 !$omp end parallel sections
271 !$omp end parallel
272
273 !$omp parallel
274 !$omp sections
275 a = 0.0
276 b = 1
277 !$omp section
278 c = 1
279 d = 2
280 !ERROR: NUM_THREADS clause is not allowed on the END SECTIONS directive
281 !$omp end sections num_threads(4)
282
283 !$omp parallel
284 !$omp sections
285 b = 1
286 !$omp section
287 c = 1
288 d = 2
289 !ERROR: At most one NOWAIT clause can appear on the END SECTIONS directive
290 !$omp end sections nowait nowait
291 !$omp end parallel
292
293 !$omp end parallel
294
295 ! 2.11.2 parallel-sections-clause -> parallel-clause |
296 ! sections-clause
297
298 !$omp parallel sections num_threads(4) private(b) lastprivate(d)
299 a = 0.0
300 !$omp section
301 b = 1
302 c = 2
303 !$omp section
304 d = 3
305 !$omp end parallel sections
306
307 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL SECTIONS directive
308 !$omp parallel sections num_threads(1) num_threads(4)
309 a = 0.0
310 !ERROR: Unmatched END SECTIONS directive
311 !$omp end sections
312
313 !$omp parallel sections
314 !ERROR: NOWAIT clause is not allowed on the END PARALLEL SECTIONS directive
315 !$omp end parallel sections nowait
316
317 ! 2.7.3 single-clause -> private-clause |
318 ! firstprivate-clause
319 ! end-single-clause -> copyprivate-clause |
320 ! nowait-clause
321
322 !$omp parallel
323 b = 1
324 !ERROR: LASTPRIVATE clause is not allowed on the SINGLE directive
325 !ERROR: NOWAIT clause is not allowed on the OMP SINGLE directive, use it on OMP END SINGLE directive
326 !$omp single private(a) lastprivate(c) nowait
327 a = 3.14
328 !ERROR: Clause NOWAIT is not allowed if clause COPYPRIVATE appears on the END SINGLE directive
329 !ERROR: COPYPRIVATE variable 'a' may not appear on a PRIVATE or FIRSTPRIVATE clause on a SINGLE construct
330 !ERROR: At most one NOWAIT clause can appear on the END SINGLE directive
331 !$omp end single copyprivate(a) nowait nowait
332 c = 2
333 !$omp end parallel
334
335 ! 2.7.4 workshare
336
337 !$omp parallel
338 !$omp workshare
339 a = 1.0
340 !$omp end workshare nowait
341 !ERROR: NUM_THREADS clause is not allowed on the WORKSHARE directive
342 !$omp workshare num_threads(4)
343 a = 1.0
344 !ERROR: COPYPRIVATE clause is not allowed on the END WORKSHARE directive
345 !$omp end workshare nowait copyprivate(a)
346 !ERROR: NOWAIT clause is not allowed on the OMP WORKSHARE directive, use it on OMP END WORKSHARE directive
347 !$omp workshare nowait
348 !$omp end workshare
349 !$omp end parallel
350
351 ! 2.8.1 simd-clause -> safelen-clause |
352 ! simdlen-clause |
353 ! linear-clause |
354 ! aligned-clause |
355 ! private-clause |
356 ! lastprivate-clause |
357 ! reduction-clause |
358 ! collapse-clause
359
360 a = 0.0
361 !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
362 !$omp simd private(b) reduction(+:a) task_reduction(+:a)
363 do i = 1, N
364 a = a + b + 3.14
365 enddo
366
367 !ERROR: At most one SAFELEN clause can appear on the SIMD directive
368 !$omp simd safelen(1) safelen(2)
369 do i = 1, N
370 a = 3.14
371 enddo
372
373 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
374 !$omp simd simdlen(-1)
375 do i = 1, N
376 a = 3.14
377 enddo
378
379 !ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
380 !$omp simd aligned(cpt:-2)
381 do i = 1, N
382 a = 3.14
383 enddo
384
385 !$omp parallel
386 !ERROR: The parameter of the SIMDLEN clause must be less than or equal to the parameter of the SAFELEN clause
387 !$omp simd safelen(1+1) simdlen(1+2)
388 do i = 1, N
389 a = 3.14
390 enddo
391 !$omp end parallel
392
393 ! 2.11.1 parallel-do-clause -> parallel-clause |
394 ! do-clause
395
396 !ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive
397 !ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive
398 !$omp parallel do proc_bind(master) proc_bind(close) linear(val(b))
399 do i = 1, N
400 a = 3.14
401 enddo
402
403 ! 2.8.3 do-simd-clause -> do-clause |
404 ! simd-clause
405
406 !$omp parallel
407 !ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive
408 !ERROR: NOGROUP clause is not allowed on the DO SIMD directive
409 !ERROR: NOWAIT clause is not allowed on the OMP DO SIMD directive, use it on OMP END DO SIMD directive
410 !$omp do simd ordered(2) NOGROUP nowait
411 do i = 1, N
412 do j = 1, N
413 a = 3.14
414 enddo
415 enddo
416 !omp end do nowait
417 !$omp end parallel
418
419 ! 2.11.4 parallel-do-simd-clause -> parallel-clause |
420 ! do-simd-clause
421
422 !$omp parallel do simd collapse(2) safelen(2) &
423 !$omp & simdlen(1) private(c) firstprivate(a) proc_bind(spread)
424 do i = 1, N
425 do j = 1, N
426 a = 3.14
427 enddo
428 enddo
429
430 ! 2.9.2 taskloop -> TASKLOOP [taskloop-clause[ [,] taskloop-clause]...]
431 ! taskloop-clause -> if-clause |
432 ! shared-clause |
433 ! private-clause |
434 ! firstprivate-clause |
435 ! lastprivate-clause |
436 ! default-clause |
437 ! grainsize-clause |
438 ! num-tasks-clause |
439 ! collapse-clause |
440 ! final-clause |
441 ! priority-clause |
442 ! untied-clause |
443 ! mergeable-clause |
444 ! nogroup-clause
445
446 !$omp taskloop
447 do i = 1, N
448 a = 3.14
449 enddo
450
451 !ERROR: SCHEDULE clause is not allowed on the TASKLOOP directive
452 !$omp taskloop schedule(static)
453 do i = 1, N
454 a = 3.14
455 enddo
456
457 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP directive
458 !$omp taskloop num_tasks(3) grainsize(2)
459 do i = 1,N
460 a = 3.14
461 enddo
462
463 !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
464 !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
465 !$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*:a)
466 do i = 1,N
467 a = 3.14
468 enddo
469
470 ! 2.13.1 master
471
472 !$omp parallel
473 !$omp master
474 a=3.14
475 !$omp end master
476 !$omp end parallel
477
478 !$omp parallel
479 !ERROR: NUM_THREADS clause is not allowed on the MASTER directive
480 !$omp master num_threads(4)
481 a=3.14
482 !$omp end master
483 !$omp end parallel
484
485 ! Standalone Directives (basic)
486
487 !$omp taskyield
488 !$omp barrier
489 !$omp taskwait
490 !ERROR: DEPEND(SOURCE) or DEPEND(SINK : vec) can be used only with the ordered directive. Used here in the TASKWAIT construct.
491 !$omp taskwait depend(source)
492 ! !$omp taskwait depend(sink:i-1)
493 ! !$omp target enter data map(to:arrayA) map(alloc:arrayB)
494 ! !$omp target update from(arrayA) to(arrayB)
495 ! !$omp target exit data map(from:arrayA) map(delete:arrayB)
496 !$omp flush (c)
497 !$omp flush acq_rel
498 !$omp flush release
499 !$omp flush acquire
500 !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
501 !$omp flush release (c)
502 !ERROR: SEQ_CST clause is not allowed on the FLUSH directive
503 !$omp flush seq_cst
504 !ERROR: RELAXED clause is not allowed on the FLUSH directive
505 !$omp flush relaxed
506
507 ! 2.13.2 critical Construct
508
509 ! !$omp critical (first)
510 a = 3.14
511 ! !$omp end critical (first)
512
513 ! 2.9.1 task-clause -> if-clause |
514 ! final-clause |
515 ! untied-clause |
516 ! default-clause |
517 ! mergeable-clause |
518 ! private-clause |
519 ! firstprivate-clause |
520 ! shared-clause |
521 ! depend-clause |
522 ! priority-clause
523
524 !$omp task shared(a) default(none) if(task:a > 1.)
525 a = 1.
526 !$omp end task
527
528 !ERROR: Unmatched directive name modifier TASKLOOP on the IF clause
529 !$omp task private(a) if(taskloop:a.eq.1)
530 a = 1.
531 !$omp end task
532
533 !ERROR: LASTPRIVATE clause is not allowed on the TASK directive
534 !ERROR: At most one FINAL clause can appear on the TASK directive
535 !$omp task lastprivate(b) final(a.GE.1) final(.false.)
536 b = 1
537 !$omp end task
538
539 !ERROR: The parameter of the PRIORITY clause must be a positive integer expression
540 !$omp task priority(-1) firstprivate(a) mergeable
541 a = 3.14
542 !$omp end task
543
544 ! 2.9.3 taskloop-simd-clause -> taskloop-clause |
545 ! simd-clause
546
547 !$omp taskloop simd
548 do i = 1, N
549 a = 3.14
550 enddo
551 !$omp end taskloop simd
552
553 !$omp taskloop simd reduction(+:a)
554 do i = 1, N
555 a = a + 3.14
556 enddo
557 !ERROR: Unmatched END TASKLOOP directive
558 !$omp end taskloop
559
560 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP SIMD directive
561 !$omp taskloop simd num_tasks(3) grainsize(2)
562 do i = 1,N
563 a = 3.14
564 enddo
565
566 allocate(allc)
567 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
568 !ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
569 !$omp taskloop simd simdlen(-1) aligned(allc:-2)
570 do i = 1, N
571 allc = 3.14
572 enddo
573
574 !$omp target enter data map(alloc:A) device(0)
575 !$omp target exit data map(delete:A) device(0)
576
577 end program