598 lines · plain
1! REQUIRES: openmp_runtime2 3! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag -fopenmp-version=524use omp_lib5! Check OpenMP clause validity for the following directives:6!7! 2.5 PARALLEL construct8! 2.7.1 Loop construct9! ...10 11 use iso_c_binding12 integer :: b = 12813 integer, allocatable :: allc14 type(C_PTR) :: cpt15 integer :: z, c = 3216 integer, parameter :: num = 1617 real(8) :: arrayA(256), arrayB(512)18 19 integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space20 type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)]21 integer(omp_allocator_handle_kind) :: xy_alloc22 xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits)23 24 arrayA = 1.414d025 arrayB = 3.14d026 N = 102427 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-clause38 39 !$omp parallel40 do i = 1, N41 a = 3.1442 enddo43 !$omp end parallel44 45 !$omp parallel private(b) allocate(b)46 do i = 1, N47 a = 3.1448 enddo49 !$omp end parallel50 51 !$omp parallel private(c, b) allocate(omp_default_mem_space : b, c)52 do i = 1, N53 a = 3.1454 enddo55 !$omp end parallel56 57 !$omp parallel allocate(b) allocate(c) private(b, c)58 do i = 1, N59 a = 3.1460 enddo61 !$omp end parallel62 63 !$omp parallel allocate(xy_alloc :b) private(b)64 do i = 1, N65 a = 3.1466 enddo67 !$omp end parallel68 69 !$omp task private(b) allocate(b)70 do i = 1, N71 z = 272 end do73 !$omp end task74 75 !$omp teams private(b) allocate(b)76 do i = 1, N77 z = 278 end do79 !$omp end teams80 81 !$omp target private(b) allocate(b)82 do i = 1, N83 z = 284 end do85 !$omp end target86 87 !ERROR: ALLOCATE clause is not allowed on the TARGET DATA directive88 !$omp target data map(from: b) allocate(b)89 do i = 1, N90 z = 291 enddo92 !$omp end target data93 94 !ERROR: SCHEDULE clause is not allowed on the PARALLEL directive95 !$omp parallel schedule(static)96 do i = 1, N97 a = 3.1498 enddo99 !$omp end parallel100 101 !ERROR: COLLAPSE clause is not allowed on the PARALLEL directive102 !$omp parallel collapse(2)103 do i = 1, N104 do j = 1, N105 a = 3.14106 enddo107 enddo108 !$omp end parallel109 110 !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression111 !$omp do collapse(-1)112 do i = 1, N113 do j = 1, N114 a = 3.14115 enddo116 enddo117 !$omp end do118 119 a = 1.0120 !$omp parallel firstprivate(a)121 do i = 1, N122 a = 3.14123 enddo124 !ERROR: NUM_THREADS clause is not allowed on the END PARALLEL directive125 !$omp end parallel num_threads(4)126 127 !ERROR: LASTPRIVATE clause is not allowed on the PARALLEL directive128 !ERROR: NUM_TASKS clause is not allowed on the PARALLEL directive129 !ERROR: INBRANCH clause is not allowed on the PARALLEL directive130 !$omp parallel lastprivate(a) NUM_TASKS(4) inbranch131 do i = 1, N132 a = 3.14133 enddo134 !$omp end parallel135 136 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL directive137 !$omp parallel num_threads(2) num_threads(4)138 do i = 1, N139 a = 3.14140 enddo141 !$omp end parallel142 143 !ERROR: The parameter of the NUM_THREADS clause must be a positive integer expression144 !$omp parallel num_threads(1-4)145 do i = 1, N146 a = 3.14147 enddo148 !ERROR: NOWAIT clause is not allowed on the END PARALLEL directive149 !$omp end parallel nowait150 151 !$omp parallel num_threads(num-10)152 do i = 1, N153 a = 3.14154 enddo155 !$omp end parallel156 157 !$omp parallel num_threads(b+1)158 do i = 1, N159 a = 3.14160 enddo161 !$omp end parallel162 163 !$omp parallel164 do i = 1, N165 enddo166 !$omp end parallel167 168 ! OMP 5.0 - 2.6 Restriction point 1169 outofparallel: do k =1, 10170 !$omp parallel171 !$omp do172 outer: do i=0, 10173 inner: do j=1, 10174 exit175 !ERROR: EXIT statement terminates associated loop of an OpenMP DO construct176 exit outer177 !ERROR: EXIT to construct 'outofparallel' outside of PARALLEL construct is not allowed178 !ERROR: EXIT to construct 'outofparallel' outside of DO construct is not allowed179 exit outofparallel180 end do inner181 end do outer182 !$omp end do183 !$omp end parallel184 end do outofparallel185 186! 2.7.1 do-clause -> private-clause |187! firstprivate-clause |188! lastprivate-clause |189! linear-clause |190! reduction-clause |191! schedule-clause |192! collapse-clause |193! ordered-clause194 195 !ERROR: When SCHEDULE clause has AUTO specified, it must not have chunk size specified196 !ERROR: At most one SCHEDULE clause can appear on the DO directive197 !ERROR: When SCHEDULE clause has RUNTIME specified, it must not have chunk size specified198 !$omp do schedule(auto, 2) schedule(runtime, 2)199 do i = 1, N200 a = 3.14201 enddo202 203 !ERROR: A modifier may not be specified in a LINEAR clause on the DO directive204 !$omp do linear(ref(b))205 do i = 1, N206 a = 3.14207 enddo208 209 !ERROR: The NONMONOTONIC modifier can only be specified with SCHEDULE(DYNAMIC) or SCHEDULE(GUIDED)210 !ERROR: The NONMONOTONIC modifier cannot be specified if an ORDERED clause is specified211 !$omp do schedule(NONMONOTONIC:static) ordered212 do i = 1, N213 a = 3.14214 enddo215 216 !$omp do schedule(simd, monotonic:dynamic)217 do i = 1, N218 a = 3.14219 enddo220 221 !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive222 !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression223 !ERROR: 'b' appears in more than one data-sharing clause on the same OpenMP directive224 !$omp do ordered(1-1) private(b) linear(b) linear(a)225 do i = 1, N226 a = 3.14227 enddo228 229 !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive230 !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression231 !$omp do ordered(1-1) linear(a)232 do i = 1, N233 a = 3.14234 enddo235 236 !ERROR: The parameter of the ORDERED clause must be greater than or equal to the parameter of the COLLAPSE clause237 !$omp do collapse(num-14) ordered(1)238 do i = 1, N239 do j = 1, N240 do k = 1, N241 a = 3.14242 enddo243 enddo244 enddo245 246 !$omp parallel do simd if(parallel:a>1.)247 do i = 1, N248 enddo249 !$omp end parallel do simd250 251 !ERROR: TARGET is not a constituent of the PARALLEL DO directive252 !$omp parallel do if(target:a>1.)253 do i = 1, N254 enddo255 !ERROR: Misplaced OpenMP end-directive256 !$omp end simd257 258! 2.7.2 sections-clause -> private-clause |259! firstprivate-clause |260! lastprivate-clause |261! reduction-clause262 263 !$omp parallel264 !$omp sections265 !$omp section266 a = 0.0267 !$omp section268 b = 1269 !$omp end sections nowait270 !$omp end parallel271 272 !$omp parallel273 !$omp sections274 !$omp section275 a = 0.0276 !ERROR: Unmatched END PARALLEL SECTIONS directive277 !$omp end parallel sections278 !$omp end parallel279 280 !$omp parallel281 !$omp sections282 a = 0.0283 b = 1284 !$omp section285 c = 1286 d = 2287 !ERROR: NUM_THREADS clause is not allowed on the END SECTIONS directive288 !$omp end sections num_threads(4)289 290 !$omp parallel291 !$omp sections292 b = 1293 !$omp section294 c = 1295 d = 2296 !ERROR: At most one NOWAIT clause can appear on the END SECTIONS directive297 !$omp end sections nowait nowait298 !$omp end parallel299 300 !$omp end parallel301 302! 2.11.2 parallel-sections-clause -> parallel-clause |303! sections-clause304 305 !$omp parallel sections num_threads(4) private(b) lastprivate(d)306 a = 0.0307 !$omp section308 b = 1309 c = 2310 !$omp section311 d = 3312 !$omp end parallel sections313 314 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL SECTIONS directive315 !$omp parallel sections num_threads(1) num_threads(4)316 a = 0.0317 !ERROR: Unmatched END SECTIONS directive318 !$omp end sections319 320 !$omp parallel sections321 !ERROR: NOWAIT clause is not allowed on the END PARALLEL SECTIONS directive322 !$omp end parallel sections nowait323 324! 2.7.3 single-clause -> private-clause |325! firstprivate-clause326! end-single-clause -> copyprivate-clause |327! nowait-clause328 329 !$omp parallel330 b = 1331 !ERROR: LASTPRIVATE clause is not allowed on the SINGLE directive332 !ERROR: NOWAIT clause must not be used with COPYPRIVATE clause on the SINGLE directive333 !$omp single private(a) lastprivate(c) nowait334 a = 3.14335 !ERROR: COPYPRIVATE variable 'a' may not appear on a PRIVATE or FIRSTPRIVATE clause on a SINGLE construct336 !ERROR: At most one NOWAIT clause can appear on the SINGLE directive337 !ERROR: At most one NOWAIT clause can appear on the SINGLE directive338 !ERROR: At most one NOWAIT clause can appear on the END SINGLE directive339 !$omp end single copyprivate(a) nowait nowait340 c = 2341 !$omp end parallel342 343! 2.7.4 workshare344 345 !$omp parallel346 !$omp workshare347 a = 1.0348 !$omp end workshare nowait349 !ERROR: NUM_THREADS clause is not allowed on the WORKSHARE directive350 !$omp workshare num_threads(4)351 a = 1.0352 !ERROR: COPYPRIVATE clause is not allowed on the END WORKSHARE directive353 !$omp end workshare nowait copyprivate(a)354 !$omp workshare nowait355 !$omp end workshare356 !$omp end parallel357 358! 2.8.1 simd-clause -> safelen-clause |359! simdlen-clause |360! linear-clause |361! aligned-clause |362! private-clause |363! lastprivate-clause |364! reduction-clause |365! collapse-clause366 367 a = 0.0368 !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive369 !$omp simd private(b) reduction(+:a) task_reduction(+:a)370 do i = 1, N371 a = a + b + 3.14372 enddo373 374 !ERROR: At most one SAFELEN clause can appear on the SIMD directive375 !$omp simd safelen(1) safelen(2)376 do i = 1, N377 a = 3.14378 enddo379 380 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression381 !$omp simd simdlen(-1)382 do i = 1, N383 a = 3.14384 enddo385 386 !ERROR: The alignment value should be a constant positive integer387 !$omp simd aligned(cpt:-2)388 do i = 1, N389 a = 3.14390 enddo391 392 !$omp parallel393 !ERROR: The parameter of the SIMDLEN clause must be less than or equal to the parameter of the SAFELEN clause394 !$omp simd safelen(1+1) simdlen(1+2)395 do i = 1, N396 a = 3.14397 enddo398 !$omp end parallel399 400 !ERROR: The `SAFELEN` clause cannot appear in the `SIMD` directive with `ORDER(CONCURRENT)` clause401 !$omp simd order(concurrent) safelen(1+2)402 do i = 1, N403 a = 3.14404 enddo405 406! 2.11.1 parallel-do-clause -> parallel-clause |407! do-clause408 409 !ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive410 !ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive411 !$omp parallel do proc_bind(master) proc_bind(close) linear(val(b))412 do i = 1, N413 a = 3.14414 enddo415 416! 2.8.3 do-simd-clause -> do-clause |417! simd-clause418 419 !$omp parallel420 !ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive421 !ERROR: NOGROUP clause is not allowed on the DO SIMD directive422 !$omp do simd ordered(2) NOGROUP nowait423 do i = 1, N424 do j = 1, N425 a = 3.14426 enddo427 enddo428 !omp end do nowait429 !$omp end parallel 430 431! 2.11.4 parallel-do-simd-clause -> parallel-clause |432! do-simd-clause433 434 !$omp parallel do simd collapse(2) safelen(2) &435 !$omp & simdlen(1) private(c) firstprivate(a) proc_bind(spread)436 do i = 1, N437 do j = 1, N438 a = 3.14439 enddo440 enddo441 442! 2.9.2 taskloop -> TASKLOOP [taskloop-clause[ [,] taskloop-clause]...]443! taskloop-clause -> if-clause |444! shared-clause |445! private-clause |446! firstprivate-clause |447! lastprivate-clause |448! default-clause |449! grainsize-clause |450! num-tasks-clause |451! collapse-clause |452! final-clause |453! priority-clause |454! untied-clause |455! mergeable-clause |456! nogroup-clause457 458 !$omp taskloop459 do i = 1, N460 a = 3.14461 enddo462 463 !ERROR: SCHEDULE clause is not allowed on the TASKLOOP directive464 !$omp taskloop schedule(static)465 do i = 1, N466 a = 3.14467 enddo468 469 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP directive470 !$omp taskloop num_tasks(3) grainsize(2)471 do i = 1,N472 a = 3.14473 enddo474 475 !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive476 !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive477 !$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*:a)478 do i = 1,N479 a = 3.14480 enddo481 482! 2.13.1 master483 484 !$omp parallel485 !WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead. [-Wopen-mp-usage]486 !$omp master487 a=3.14488 !$omp end master489 !$omp end parallel490 491 !$omp parallel492 !WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead. [-Wopen-mp-usage]493 !ERROR: NUM_THREADS clause is not allowed on the MASTER directive494 !$omp master num_threads(4)495 a=3.14496 !$omp end master497 !$omp end parallel498 499! Standalone Directives (basic)500 501 !$omp taskyield502 !$omp barrier503 !$omp taskwait504 !WARNING: SOURCE dependence type is deprecated in OpenMP v5.2505 !ERROR: The SINK and SOURCE dependence types can only be used with the ORDERED directive, used here in the TASKWAIT construct506 !$omp taskwait depend(source)507 ! !$omp taskwait depend(sink:i-1)508 ! !$omp target enter data map(to:arrayA) map(alloc:arrayB)509 ! !$omp target update from(arrayA) to(arrayB)510 ! !$omp target exit data map(from:arrayA) map(delete:arrayB)511 !$omp flush (c)512 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead513 !$omp flush acq_rel514 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead515 !$omp flush release516 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead517 !$omp flush acquire518 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead519 !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive520 !$omp flush release (c)521 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead522 !$omp flush seq_cst523 !WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead524 !ERROR: RELAXED clause is not allowed on the FLUSH directive525 !$omp flush relaxed526 527! 2.13.2 critical Construct528 529 ! !$omp critical (first)530 a = 3.14531 ! !$omp end critical (first)532 533! 2.9.1 task-clause -> if-clause |534! final-clause |535! untied-clause |536! default-clause |537! mergeable-clause |538! private-clause |539! firstprivate-clause |540! shared-clause |541! depend-clause |542! priority-clause543 544 !$omp task shared(a) default(none) if(task:a > 1.)545 a = 1.546 !$omp end task547 548 !ERROR: TASKLOOP is not a constituent of the TASK directive549 !$omp task private(a) if(taskloop:a.eq.1)550 a = 1.551 !$omp end task552 553 !ERROR: LASTPRIVATE clause is not allowed on the TASK directive554 !ERROR: At most one FINAL clause can appear on the TASK directive555 !$omp task lastprivate(b) final(a.GE.1) final(.false.)556 b = 1557 !$omp end task558 559 !ERROR: The parameter of the PRIORITY clause must be a positive integer expression560 !$omp task priority(-1) firstprivate(a) mergeable561 a = 3.14562 !$omp end task563 564! 2.9.3 taskloop-simd-clause -> taskloop-clause |565! simd-clause566 567 !$omp taskloop simd568 do i = 1, N569 a = 3.14570 enddo571 !$omp end taskloop simd572 573 !$omp taskloop simd reduction(+:a)574 do i = 1, N575 a = a + 3.14576 enddo577 !ERROR: Misplaced OpenMP end-directive578 !$omp end taskloop579 580 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP SIMD directive581 !$omp taskloop simd num_tasks(3) grainsize(2)582 do i = 1,N583 a = 3.14584 enddo585 586 allocate(allc)587 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression588 !ERROR: The alignment value should be a constant positive integer589 !$omp taskloop simd simdlen(-1) aligned(allc:-2)590 do i = 1, N591 allc = 3.14592 enddo593 594 !$omp target enter data map(alloc:A) device(0) 595 !$omp target exit data map(delete:A) device(0) 596 597end program598