2021-09-06 16:19:20 +08:00
|
|
|
! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenmp
|
2020-08-05 22:58:13 +08:00
|
|
|
use omp_lib
|
2019-06-26 07:18:51 +08:00
|
|
|
! Check OpenMP clause validity for the following directives:
|
|
|
|
!
|
|
|
|
! 2.5 PARALLEL construct
|
2019-07-02 04:55:06 +08:00
|
|
|
! 2.7.1 Loop construct
|
2019-06-26 07:18:51 +08:00
|
|
|
! ...
|
|
|
|
|
2019-07-02 04:55:06 +08:00
|
|
|
integer :: b = 128
|
2020-09-09 18:50:13 +08:00
|
|
|
integer :: z, c = 32
|
2019-07-04 05:24:37 +08:00
|
|
|
integer, parameter :: num = 16
|
2019-08-07 02:59:40 +08:00
|
|
|
real(8) :: arrayA(256), arrayB(512)
|
|
|
|
|
2020-08-05 22:58:13 +08:00
|
|
|
integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space
|
|
|
|
type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)]
|
|
|
|
integer(omp_allocator_handle_kind) :: xy_alloc
|
|
|
|
xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits)
|
|
|
|
|
2019-08-07 02:59:40 +08:00
|
|
|
arrayA = 1.414
|
|
|
|
arrayB = 3.14
|
2019-07-02 04:55:06 +08:00
|
|
|
N = 1024
|
|
|
|
|
|
|
|
! 2.5 parallel-clause -> if-clause |
|
2019-06-26 07:18:51 +08:00
|
|
|
! num-threads-clause |
|
|
|
|
! default-clause |
|
|
|
|
! private-clause |
|
|
|
|
! firstprivate-clause |
|
|
|
|
! shared-clause |
|
|
|
|
! copyin-clause |
|
|
|
|
! reduction-clause |
|
2020-08-05 22:58:13 +08:00
|
|
|
! proc-bind-clause |
|
|
|
|
! allocate-clause
|
2019-06-26 07:18:51 +08:00
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!$omp parallel private(b) allocate(b)
|
2020-08-05 22:58:13 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!$omp parallel private(c, b) allocate(omp_default_mem_space : b, c)
|
2020-08-05 22:58:13 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!$omp parallel allocate(b) allocate(c) private(b, c)
|
2020-08-05 22:58:13 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!$omp parallel allocate(xy_alloc :b) private(b)
|
2020-08-05 22:58:13 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
2020-11-22 03:31:17 +08:00
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!$omp task private(b) allocate(b)
|
|
|
|
do i = 1, N
|
|
|
|
z = 2
|
|
|
|
end do
|
|
|
|
!$omp end task
|
|
|
|
|
|
|
|
!$omp teams private(b) allocate(b)
|
|
|
|
do i = 1, N
|
|
|
|
z = 2
|
|
|
|
end do
|
|
|
|
!$omp end teams
|
|
|
|
|
|
|
|
!$omp target private(b) allocate(b)
|
|
|
|
do i = 1, N
|
|
|
|
z = 2
|
|
|
|
end do
|
|
|
|
!$omp end target
|
2020-11-22 03:31:17 +08:00
|
|
|
|
2020-09-09 18:50:13 +08:00
|
|
|
!ERROR: ALLOCATE clause is not allowed on the TARGET DATA directive
|
|
|
|
!$omp target data map(from: b) allocate(b)
|
|
|
|
do i = 1, N
|
|
|
|
z = 2
|
|
|
|
enddo
|
2021-07-14 21:42:26 +08:00
|
|
|
!$omp end target data
|
2020-08-05 22:58:13 +08:00
|
|
|
|
2019-06-26 07:18:51 +08:00
|
|
|
!ERROR: SCHEDULE clause is not allowed on the PARALLEL directive
|
|
|
|
!$omp parallel schedule(static)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
!ERROR: COLLAPSE clause is not allowed on the PARALLEL directive
|
|
|
|
!$omp parallel collapse(2)
|
|
|
|
do i = 1, N
|
[flang] [OpenMP] Predetermined rules for loop index variables (flang-compiler/f18#962)
This refers to three rules in OpenMP 4.5 Spec 2.15.1.1:
* The loop iteration variable(s) in the associated do-loop(s) of a do,
parallel do, taskloop, or distribute construct is (are) private.
* The loop iteration variable in the associated do-loop of a simd
construct with just one associated do-loop is linear with a linear-step
that is the increment of the associated do-loop.
* The loop iteration variables in the associated do-loops of a simd
construct with multiple associated do-loops are lastprivate.
A simple example:
```
implicit none
integer :: N = 1024
integer i, j, k
!$omp parallel do collapse(3)
do i=1, N <- i is private
do j=1, N <- j is private
do k=1, N <- k is private
enddo
enddo
enddo
end
```
If `collapse` clause is not present, the associated do-loop for construct
`parallel do` is only `i` loop. With `collapse(n)`, `i`, `j`, and `k` are
all associated do-loops and the loop index variables are private to the
OpenMP construct:
```
implicit none
!DEF: /MainProgram1/n ObjectEntity INTEGER(4)
integer :: n = 1024
!DEF: /MainProgram1/i ObjectEntity INTEGER(4)
!DEF: /MainProgram1/j ObjectEntity INTEGER(4)
!DEF: /MainProgram1/k ObjectEntity INTEGER(4)
integer i, j, k
!$omp parallel do collapse(3)
!DEF: /MainProgram1/Block1/i (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do i=1,n
!DEF: /MainProgram1/Block1/j (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do j=1,n
!DEF: /MainProgram1/Block1/k (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do k=1,n
end do
end do
end do
end program
```
This implementation assumes that the structural checks for do-loops
are done at this point, for example the `n` in `collapse(n)` should
be no more than the number of actual perfectly nested do-loops, etc..
Original-commit: flang-compiler/f18@572a57d3d0d785bb3f2aad9e890ef498c1214309
Reviewed-on: https://github.com/flang-compiler/f18/pull/962
2020-02-06 02:13:43 +08:00
|
|
|
do j = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-06-26 07:18:51 +08:00
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
[Flang][OpenMP] Avoid abort when collapse clause value is negative
Summary:
If the value in the collapse close is negative f18 abort without the correct error message. This PR change the size_t in name resolution to a int64_t and check appropriately for negative or zero before the privatization of induction variable.
The correct error is then catch by the OpenMP structure check.
This diff is migrated from the GitHub pull request https://github.com/flang-compiler/f18/pull/1098
Reviewers: ichoyjx, jdoerfert, sscalpone, DavidTruby
Reviewed By: ichoyjx, sscalpone, DavidTruby
Subscribers: sscalpone, klausler, yaxunl, guansong, llvm-commits
Tags: #llvm, #flang
Differential Revision: https://reviews.llvm.org/D77821
2020-05-15 09:34:33 +08:00
|
|
|
!ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression
|
|
|
|
!$omp do collapse(-1)
|
|
|
|
do i = 1, N
|
|
|
|
do j = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
!$omp end do
|
|
|
|
|
2019-06-26 07:18:51 +08:00
|
|
|
a = 1.0
|
|
|
|
!$omp parallel firstprivate(a)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
[flang] [OpenMP] parse tree changes for `OpenMPBlockConstruct` (flang-compiler/f18#632)
* [OpenMP] parse tree changes for `OpenMPBlockConstruct`
1. merge `Workshare` and `Single` into `OpenMPBlockConstruct` because
they both accept structured-block and syntax is similar to other block
directives.
2. `OpenMPBlockConstruct` changes to structure like `{Begin, Block, End}`,
where `Begin` and `End` are tuple of `{Directive, ClauseList}`.
3. Updated the check-omp-structure.* for necessary parts. Added all the END
directive enumeration types that may have clauses.
More tests will be added during Semantics.
* [OpenMP] Update on Tim's suggestion
1. Fix unspecified enumeration for `OmpDirective` in the `OmpContext`.
This is through getting rid of `PushContext(source)` function to
make sure whenever it is about to push a NEW context, directive
source location and enumeration are available. To do that, I moved
around all the switches for directive into high level `Construct`'s
`Enter` node. Besides fixing the issue, the side benefit is that
whenever we call `GetContext().directive`, we are sure that the
`directive` here was set already.
2. When `Enter` the `OmpEndBlockDirective` node, partial context
information, such as directive source location or legal clause lists,
needs to be reset. The new directive source location should be
`OmpEndBlockDirective`'s `source`. The enumeration `directive`
should not be reset for the END directives that do not accept
clauses because nothing needs to be checked (for example any clause
that is on `END PARALLEL` is illegal).
Original-commit: flang-compiler/f18@e5bd6b7ba0fbe9006f3e431260428b194f2d2616
Reviewed-on: https://github.com/flang-compiler/f18/pull/632
2019-08-10 06:11:20 +08:00
|
|
|
!ERROR: NUM_THREADS clause is not allowed on the END PARALLEL directive
|
|
|
|
!$omp end parallel num_threads(4)
|
2019-06-26 07:18:51 +08:00
|
|
|
|
|
|
|
!ERROR: LASTPRIVATE clause is not allowed on the PARALLEL directive
|
|
|
|
!ERROR: NUM_TASKS clause is not allowed on the PARALLEL directive
|
|
|
|
!ERROR: INBRANCH clause is not allowed on the PARALLEL directive
|
|
|
|
!$omp parallel lastprivate(a) NUM_TASKS(4) inbranch
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
!ERROR: At most one NUM_THREADS clause can appear on the PARALLEL directive
|
|
|
|
!$omp parallel num_threads(2) num_threads(4)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
2019-07-02 04:55:06 +08:00
|
|
|
|
2019-07-04 05:24:37 +08:00
|
|
|
!ERROR: The parameter of the NUM_THREADS clause must be a positive integer expression
|
|
|
|
!$omp parallel num_threads(1-4)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-08-24 08:37:57 +08:00
|
|
|
!ERROR: NOWAIT clause is not allowed on the END PARALLEL directive
|
|
|
|
!$omp end parallel nowait
|
2019-07-04 05:24:37 +08:00
|
|
|
|
|
|
|
!$omp parallel num_threads(num-10)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
!$omp parallel num_threads(b+1)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-28 04:30:38 +08:00
|
|
|
!$omp parallel
|
|
|
|
do i = 1, N
|
|
|
|
enddo
|
|
|
|
!ERROR: Unmatched END TARGET directive
|
|
|
|
!$omp end target
|
|
|
|
|
2020-10-30 12:50:05 +08:00
|
|
|
! OMP 5.0 - 2.6 Restriction point 1
|
|
|
|
outofparallel: do k =1, 10
|
|
|
|
!$omp parallel
|
|
|
|
!$omp do
|
|
|
|
outer: do i=0, 10
|
|
|
|
inner: do j=1, 10
|
|
|
|
exit
|
|
|
|
exit outer
|
|
|
|
!ERROR: EXIT to construct 'outofparallel' outside of PARALLEL construct is not allowed
|
2021-02-03 18:18:30 +08:00
|
|
|
!ERROR: EXIT to construct 'outofparallel' outside of DO construct is not allowed
|
2020-10-30 12:50:05 +08:00
|
|
|
exit outofparallel
|
|
|
|
end do inner
|
|
|
|
end do outer
|
2021-07-14 21:42:26 +08:00
|
|
|
!$omp end do
|
2020-10-30 12:50:05 +08:00
|
|
|
!$omp end parallel
|
|
|
|
end do outofparallel
|
|
|
|
|
2019-07-02 04:55:06 +08:00
|
|
|
! 2.7.1 do-clause -> private-clause |
|
|
|
|
! firstprivate-clause |
|
|
|
|
! lastprivate-clause |
|
|
|
|
! linear-clause |
|
|
|
|
! reduction-clause |
|
|
|
|
! schedule-clause |
|
|
|
|
! collapse-clause |
|
|
|
|
! ordered-clause
|
|
|
|
|
|
|
|
!ERROR: When SCHEDULE clause has AUTO specified, it must not have chunk size specified
|
|
|
|
!ERROR: At most one SCHEDULE clause can appear on the DO directive
|
|
|
|
!ERROR: When SCHEDULE clause has RUNTIME specified, it must not have chunk size specified
|
|
|
|
!$omp do schedule(auto, 2) schedule(runtime, 2)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2019-07-12 06:18:09 +08:00
|
|
|
!ERROR: A modifier may not be specified in a LINEAR clause on the DO directive
|
2019-07-02 04:55:06 +08:00
|
|
|
!$omp do linear(ref(b))
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: The NONMONOTONIC modifier can only be specified with SCHEDULE(DYNAMIC) or SCHEDULE(GUIDED)
|
|
|
|
!ERROR: The NONMONOTONIC modifier cannot be specified if an ORDERED clause is specified
|
|
|
|
!$omp do schedule(NONMONOTONIC:static) ordered
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!$omp do schedule(simd, monotonic:dynamic)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2020-11-05 16:55:06 +08:00
|
|
|
!ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
|
2019-07-04 05:24:37 +08:00
|
|
|
!ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
|
|
|
|
!$omp do ordered(1-1) private(b) linear(b) linear(a)
|
2019-07-02 04:55:06 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-07-04 05:24:37 +08:00
|
|
|
|
|
|
|
!ERROR: The parameter of the ORDERED clause must be greater than or equal to the parameter of the COLLAPSE clause
|
[flang] [OpenMP] Predetermined rules for loop index variables (flang-compiler/f18#962)
This refers to three rules in OpenMP 4.5 Spec 2.15.1.1:
* The loop iteration variable(s) in the associated do-loop(s) of a do,
parallel do, taskloop, or distribute construct is (are) private.
* The loop iteration variable in the associated do-loop of a simd
construct with just one associated do-loop is linear with a linear-step
that is the increment of the associated do-loop.
* The loop iteration variables in the associated do-loops of a simd
construct with multiple associated do-loops are lastprivate.
A simple example:
```
implicit none
integer :: N = 1024
integer i, j, k
!$omp parallel do collapse(3)
do i=1, N <- i is private
do j=1, N <- j is private
do k=1, N <- k is private
enddo
enddo
enddo
end
```
If `collapse` clause is not present, the associated do-loop for construct
`parallel do` is only `i` loop. With `collapse(n)`, `i`, `j`, and `k` are
all associated do-loops and the loop index variables are private to the
OpenMP construct:
```
implicit none
!DEF: /MainProgram1/n ObjectEntity INTEGER(4)
integer :: n = 1024
!DEF: /MainProgram1/i ObjectEntity INTEGER(4)
!DEF: /MainProgram1/j ObjectEntity INTEGER(4)
!DEF: /MainProgram1/k ObjectEntity INTEGER(4)
integer i, j, k
!$omp parallel do collapse(3)
!DEF: /MainProgram1/Block1/i (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do i=1,n
!DEF: /MainProgram1/Block1/j (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do j=1,n
!DEF: /MainProgram1/Block1/k (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do k=1,n
end do
end do
end do
end program
```
This implementation assumes that the structural checks for do-loops
are done at this point, for example the `n` in `collapse(n)` should
be no more than the number of actual perfectly nested do-loops, etc..
Original-commit: flang-compiler/f18@572a57d3d0d785bb3f2aad9e890ef498c1214309
Reviewed-on: https://github.com/flang-compiler/f18/pull/962
2020-02-06 02:13:43 +08:00
|
|
|
!$omp do collapse(num-14) ordered(1)
|
2019-07-04 05:24:37 +08:00
|
|
|
do i = 1, N
|
|
|
|
do j = 1, N
|
|
|
|
do k = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
2019-07-10 05:08:50 +08:00
|
|
|
|
2019-09-06 01:31:34 +08:00
|
|
|
!$omp parallel do simd if(parallel:a>1.)
|
2019-08-28 04:30:38 +08:00
|
|
|
do i = 1, N
|
|
|
|
enddo
|
|
|
|
!$omp end parallel do simd
|
|
|
|
|
2019-09-06 01:31:34 +08:00
|
|
|
!ERROR: Unmatched directive name modifier TARGET on the IF clause
|
|
|
|
!$omp parallel do if(target:a>1.)
|
2019-08-28 04:30:38 +08:00
|
|
|
do i = 1, N
|
|
|
|
enddo
|
|
|
|
!ERROR: Unmatched END SIMD directive
|
|
|
|
!$omp end simd
|
|
|
|
|
2019-08-02 05:32:33 +08:00
|
|
|
! 2.7.2 sections-clause -> private-clause |
|
|
|
|
! firstprivate-clause |
|
|
|
|
! lastprivate-clause |
|
|
|
|
! reduction-clause
|
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
!$omp sections
|
|
|
|
!$omp section
|
|
|
|
a = 0.0
|
|
|
|
!$omp section
|
|
|
|
b = 1
|
|
|
|
!$omp end sections nowait
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-28 04:30:38 +08:00
|
|
|
!$omp parallel
|
|
|
|
!$omp sections
|
|
|
|
!$omp section
|
|
|
|
a = 0.0
|
|
|
|
!ERROR: Unmatched END PARALLEL SECTIONS directive
|
|
|
|
!$omp end parallel sections
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-02 05:32:33 +08:00
|
|
|
!$omp parallel
|
2019-08-14 23:42:28 +08:00
|
|
|
!$omp sections
|
|
|
|
a = 0.0
|
|
|
|
b = 1
|
2019-08-02 05:32:33 +08:00
|
|
|
!$omp section
|
2019-08-14 23:42:28 +08:00
|
|
|
c = 1
|
|
|
|
d = 2
|
|
|
|
!ERROR: NUM_THREADS clause is not allowed on the END SECTIONS directive
|
|
|
|
!$omp end sections num_threads(4)
|
2020-10-14 17:52:28 +08:00
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
!$omp sections
|
|
|
|
b = 1
|
|
|
|
!$omp section
|
|
|
|
c = 1
|
|
|
|
d = 2
|
|
|
|
!ERROR: At most one NOWAIT clause can appear on the END SECTIONS directive
|
|
|
|
!$omp end sections nowait nowait
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-02 05:32:33 +08:00
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-28 04:55:18 +08:00
|
|
|
! 2.11.2 parallel-sections-clause -> parallel-clause |
|
|
|
|
! sections-clause
|
|
|
|
|
|
|
|
!$omp parallel sections num_threads(4) private(b) lastprivate(d)
|
|
|
|
a = 0.0
|
|
|
|
!$omp section
|
|
|
|
b = 1
|
|
|
|
c = 2
|
|
|
|
!$omp section
|
|
|
|
d = 3
|
|
|
|
!$omp end parallel sections
|
|
|
|
|
|
|
|
!ERROR: At most one NUM_THREADS clause can appear on the PARALLEL SECTIONS directive
|
|
|
|
!$omp parallel sections num_threads(1) num_threads(4)
|
|
|
|
a = 0.0
|
|
|
|
!ERROR: Unmatched END SECTIONS directive
|
|
|
|
!$omp end sections
|
|
|
|
|
|
|
|
!$omp parallel sections
|
|
|
|
!ERROR: NOWAIT clause is not allowed on the END PARALLEL SECTIONS directive
|
|
|
|
!$omp end parallel sections nowait
|
|
|
|
|
2019-08-02 05:32:33 +08:00
|
|
|
! 2.7.3 single-clause -> private-clause |
|
|
|
|
! firstprivate-clause
|
|
|
|
! end-single-clause -> copyprivate-clause |
|
|
|
|
! nowait-clause
|
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
b = 1
|
|
|
|
!ERROR: LASTPRIVATE clause is not allowed on the SINGLE directive
|
2019-09-18 08:52:46 +08:00
|
|
|
!$omp single private(a) lastprivate(c)
|
2019-08-02 05:32:33 +08:00
|
|
|
a = 3.14
|
2020-11-05 16:55:06 +08:00
|
|
|
!ERROR: Clause NOWAIT is not allowed if clause COPYPRIVATE appears on the END SINGLE directive
|
2021-01-31 00:45:09 +08:00
|
|
|
!ERROR: COPYPRIVATE variable 'a' may not appear on a PRIVATE or FIRSTPRIVATE clause on a SINGLE construct
|
2019-08-02 05:32:33 +08:00
|
|
|
!ERROR: At most one NOWAIT clause can appear on the END SINGLE directive
|
|
|
|
!$omp end single copyprivate(a) nowait nowait
|
|
|
|
c = 2
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
! 2.7.4 workshare
|
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
!$omp workshare
|
|
|
|
a = 1.0
|
|
|
|
!$omp end workshare nowait
|
[flang] [OpenMP] parse tree changes for `OpenMPBlockConstruct` (flang-compiler/f18#632)
* [OpenMP] parse tree changes for `OpenMPBlockConstruct`
1. merge `Workshare` and `Single` into `OpenMPBlockConstruct` because
they both accept structured-block and syntax is similar to other block
directives.
2. `OpenMPBlockConstruct` changes to structure like `{Begin, Block, End}`,
where `Begin` and `End` are tuple of `{Directive, ClauseList}`.
3. Updated the check-omp-structure.* for necessary parts. Added all the END
directive enumeration types that may have clauses.
More tests will be added during Semantics.
* [OpenMP] Update on Tim's suggestion
1. Fix unspecified enumeration for `OmpDirective` in the `OmpContext`.
This is through getting rid of `PushContext(source)` function to
make sure whenever it is about to push a NEW context, directive
source location and enumeration are available. To do that, I moved
around all the switches for directive into high level `Construct`'s
`Enter` node. Besides fixing the issue, the side benefit is that
whenever we call `GetContext().directive`, we are sure that the
`directive` here was set already.
2. When `Enter` the `OmpEndBlockDirective` node, partial context
information, such as directive source location or legal clause lists,
needs to be reset. The new directive source location should be
`OmpEndBlockDirective`'s `source`. The enumeration `directive`
should not be reset for the END directives that do not accept
clauses because nothing needs to be checked (for example any clause
that is on `END PARALLEL` is illegal).
Original-commit: flang-compiler/f18@e5bd6b7ba0fbe9006f3e431260428b194f2d2616
Reviewed-on: https://github.com/flang-compiler/f18/pull/632
2019-08-10 06:11:20 +08:00
|
|
|
!ERROR: NUM_THREADS clause is not allowed on the WORKSHARE directive
|
|
|
|
!$omp workshare num_threads(4)
|
|
|
|
a = 1.0
|
|
|
|
!ERROR: COPYPRIVATE clause is not allowed on the END WORKSHARE directive
|
|
|
|
!$omp end workshare nowait copyprivate(a)
|
2019-08-02 05:32:33 +08:00
|
|
|
!$omp end parallel
|
|
|
|
|
2019-07-10 05:08:50 +08:00
|
|
|
! 2.8.1 simd-clause -> safelen-clause |
|
|
|
|
! simdlen-clause |
|
|
|
|
! linear-clause |
|
|
|
|
! aligned-clause |
|
|
|
|
! private-clause |
|
|
|
|
! lastprivate-clause |
|
|
|
|
! reduction-clause |
|
|
|
|
! collapse-clause
|
|
|
|
|
|
|
|
a = 0.0
|
2021-01-04 11:17:02 +08:00
|
|
|
!ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
|
|
|
|
!$omp simd private(b) reduction(+:a) task_reduction(+:a)
|
2019-07-10 05:08:50 +08:00
|
|
|
do i = 1, N
|
|
|
|
a = a + b + 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: At most one SAFELEN clause can appear on the SIMD directive
|
|
|
|
!$omp simd safelen(1) safelen(2)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
|
|
|
|
!$omp simd simdlen(-1)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2020-11-05 16:55:06 +08:00
|
|
|
!ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
|
2019-07-10 05:08:50 +08:00
|
|
|
!$omp simd aligned(b:-2)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2019-07-12 06:18:09 +08:00
|
|
|
!$omp parallel
|
2019-07-10 05:08:50 +08:00
|
|
|
!ERROR: The parameter of the SIMDLEN clause must be less than or equal to the parameter of the SAFELEN clause
|
|
|
|
!$omp simd safelen(1+1) simdlen(1+2)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-07-12 06:18:09 +08:00
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
! 2.11.1 parallel-do-clause -> parallel-clause |
|
|
|
|
! do-clause
|
|
|
|
|
|
|
|
!ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive
|
|
|
|
!ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive
|
|
|
|
!$omp parallel do proc_bind(master) proc_bind(close) linear(val(b))
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
! 2.8.3 do-simd-clause -> do-clause |
|
|
|
|
! simd-clause
|
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
!ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive
|
|
|
|
!ERROR: NOGROUP clause is not allowed on the DO SIMD directive
|
|
|
|
!$omp do simd ordered(2) NOGROUP
|
|
|
|
do i = 1, N
|
[flang] [OpenMP] Predetermined rules for loop index variables (flang-compiler/f18#962)
This refers to three rules in OpenMP 4.5 Spec 2.15.1.1:
* The loop iteration variable(s) in the associated do-loop(s) of a do,
parallel do, taskloop, or distribute construct is (are) private.
* The loop iteration variable in the associated do-loop of a simd
construct with just one associated do-loop is linear with a linear-step
that is the increment of the associated do-loop.
* The loop iteration variables in the associated do-loops of a simd
construct with multiple associated do-loops are lastprivate.
A simple example:
```
implicit none
integer :: N = 1024
integer i, j, k
!$omp parallel do collapse(3)
do i=1, N <- i is private
do j=1, N <- j is private
do k=1, N <- k is private
enddo
enddo
enddo
end
```
If `collapse` clause is not present, the associated do-loop for construct
`parallel do` is only `i` loop. With `collapse(n)`, `i`, `j`, and `k` are
all associated do-loops and the loop index variables are private to the
OpenMP construct:
```
implicit none
!DEF: /MainProgram1/n ObjectEntity INTEGER(4)
integer :: n = 1024
!DEF: /MainProgram1/i ObjectEntity INTEGER(4)
!DEF: /MainProgram1/j ObjectEntity INTEGER(4)
!DEF: /MainProgram1/k ObjectEntity INTEGER(4)
integer i, j, k
!$omp parallel do collapse(3)
!DEF: /MainProgram1/Block1/i (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do i=1,n
!DEF: /MainProgram1/Block1/j (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do j=1,n
!DEF: /MainProgram1/Block1/k (OmpPrivate) HostAssoc INTEGER(4)
!REF: /MainProgram1/n
do k=1,n
end do
end do
end do
end program
```
This implementation assumes that the structural checks for do-loops
are done at this point, for example the `n` in `collapse(n)` should
be no more than the number of actual perfectly nested do-loops, etc..
Original-commit: flang-compiler/f18@572a57d3d0d785bb3f2aad9e890ef498c1214309
Reviewed-on: https://github.com/flang-compiler/f18/pull/962
2020-02-06 02:13:43 +08:00
|
|
|
do j = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-07-12 06:18:09 +08:00
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
! 2.11.4 parallel-do-simd-clause -> parallel-clause |
|
|
|
|
! do-simd-clause
|
|
|
|
|
|
|
|
!$omp parallel do simd collapse(2) safelen(2) &
|
|
|
|
!$omp & simdlen(1) private(c) firstprivate(a) proc_bind(spread)
|
|
|
|
do i = 1, N
|
|
|
|
do j = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
enddo
|
2019-08-07 02:59:40 +08:00
|
|
|
|
2019-08-27 16:34:29 +08:00
|
|
|
! 2.9.2 taskloop -> TASKLOOP [taskloop-clause[ [,] taskloop-clause]...]
|
|
|
|
! taskloop-clause -> if-clause |
|
|
|
|
! shared-clause |
|
|
|
|
! private-clause |
|
|
|
|
! firstprivate-clause |
|
|
|
|
! lastprivate-clause |
|
|
|
|
! default-clause |
|
|
|
|
! grainsize-clause |
|
|
|
|
! num-tasks-clause |
|
|
|
|
! collapse-clause |
|
|
|
|
! final-clause |
|
|
|
|
! priority-clause |
|
|
|
|
! untied-clause |
|
|
|
|
! mergeable-clause |
|
|
|
|
! nogroup-clause
|
|
|
|
|
|
|
|
!$omp taskloop
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: SCHEDULE clause is not allowed on the TASKLOOP directive
|
|
|
|
!$omp taskloop schedule(static)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2020-08-06 02:20:26 +08:00
|
|
|
!ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP directive
|
2019-08-27 16:34:29 +08:00
|
|
|
!$omp taskloop num_tasks(3) grainsize(2)
|
|
|
|
do i = 1,N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
|
2021-01-04 11:17:02 +08:00
|
|
|
!ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
|
|
|
|
!$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*:a)
|
2019-08-27 16:34:29 +08:00
|
|
|
do i = 1,N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
2019-11-06 16:48:12 +08:00
|
|
|
! 2.13.1 master
|
|
|
|
|
2019-11-06 19:43:22 +08:00
|
|
|
!$omp parallel
|
|
|
|
!$omp master
|
|
|
|
a=3.14
|
|
|
|
!$omp end master
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-11-06 16:48:12 +08:00
|
|
|
!$omp parallel
|
|
|
|
!ERROR: NUM_THREADS clause is not allowed on the MASTER directive
|
|
|
|
!$omp master num_threads(4)
|
|
|
|
a=3.14
|
|
|
|
!$omp end master
|
|
|
|
!$omp end parallel
|
|
|
|
|
2019-08-07 02:59:40 +08:00
|
|
|
! Standalone Directives (basic)
|
|
|
|
|
|
|
|
!$omp taskyield
|
|
|
|
!$omp barrier
|
|
|
|
!$omp taskwait
|
2020-07-16 12:40:59 +08:00
|
|
|
!$omp taskwait depend(source)
|
2021-01-31 00:45:09 +08:00
|
|
|
! !$omp taskwait depend(sink:i-1)
|
2019-08-07 02:59:40 +08:00
|
|
|
! !$omp target enter data map(to:arrayA) map(alloc:arrayB)
|
|
|
|
! !$omp target update from(arrayA) to(arrayB)
|
|
|
|
! !$omp target exit data map(from:arrayA) map(delete:arrayB)
|
|
|
|
!$omp flush (c)
|
2020-07-07 16:56:22 +08:00
|
|
|
!$omp flush acq_rel
|
|
|
|
!$omp flush release
|
|
|
|
!$omp flush acquire
|
2020-12-14 16:00:26 +08:00
|
|
|
!ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
|
2020-07-07 16:56:22 +08:00
|
|
|
!$omp flush release (c)
|
2020-11-22 03:31:17 +08:00
|
|
|
!ERROR: SEQ_CST clause is not allowed on the FLUSH directive
|
|
|
|
!$omp flush seq_cst
|
|
|
|
!ERROR: RELAXED clause is not allowed on the FLUSH directive
|
|
|
|
!$omp flush relaxed
|
|
|
|
|
2019-08-13 07:08:10 +08:00
|
|
|
! 2.13.2 critical Construct
|
|
|
|
|
2021-01-31 00:45:09 +08:00
|
|
|
! !$omp critical (first)
|
2019-08-13 07:08:10 +08:00
|
|
|
a = 3.14
|
2021-01-31 00:45:09 +08:00
|
|
|
! !$omp end critical (first)
|
2019-09-05 14:35:44 +08:00
|
|
|
|
|
|
|
! 2.9.1 task-clause -> if-clause |
|
|
|
|
! final-clause |
|
|
|
|
! untied-clause |
|
|
|
|
! default-clause |
|
|
|
|
! mergeable-clause |
|
|
|
|
! private-clause |
|
|
|
|
! firstprivate-clause |
|
|
|
|
! shared-clause |
|
|
|
|
! depend-clause |
|
|
|
|
! priority-clause
|
|
|
|
|
|
|
|
!$omp task shared(a) default(none) if(task:a > 1.)
|
|
|
|
a = 1.
|
|
|
|
!$omp end task
|
|
|
|
|
2019-09-05 18:15:23 +08:00
|
|
|
!ERROR: Unmatched directive name modifier TASKLOOP on the IF clause
|
|
|
|
!$omp task private(a) if(taskloop:a.eq.1)
|
|
|
|
a = 1.
|
|
|
|
!$omp end task
|
|
|
|
|
2019-09-05 14:35:44 +08:00
|
|
|
!ERROR: LASTPRIVATE clause is not allowed on the TASK directive
|
|
|
|
!ERROR: At most one FINAL clause can appear on the TASK directive
|
|
|
|
!$omp task lastprivate(b) final(a.GE.1) final(.false.)
|
|
|
|
b = 1
|
|
|
|
!$omp end task
|
|
|
|
|
|
|
|
!ERROR: The parameter of the PRIORITY clause must be a positive integer expression
|
|
|
|
!$omp task priority(-1) firstprivate(a) mergeable
|
|
|
|
a = 3.14
|
|
|
|
!$omp end task
|
2019-09-06 00:33:23 +08:00
|
|
|
|
|
|
|
! 2.9.3 taskloop-simd-clause -> taskloop-clause |
|
|
|
|
! simd-clause
|
|
|
|
|
|
|
|
!$omp taskloop simd
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end taskloop simd
|
|
|
|
|
|
|
|
!$omp taskloop simd reduction(+:a)
|
|
|
|
do i = 1, N
|
|
|
|
a = a + 3.14
|
|
|
|
enddo
|
|
|
|
!ERROR: Unmatched END TASKLOOP directive
|
|
|
|
!$omp end taskloop
|
|
|
|
|
2020-08-06 02:20:26 +08:00
|
|
|
!ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP SIMD directive
|
2019-09-06 00:33:23 +08:00
|
|
|
!$omp taskloop simd num_tasks(3) grainsize(2)
|
|
|
|
do i = 1,N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
|
|
|
|
!ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
|
2020-11-05 16:55:06 +08:00
|
|
|
!ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
|
2019-09-06 00:33:23 +08:00
|
|
|
!$omp taskloop simd simdlen(-1) aligned(a:-2)
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
2019-08-07 02:59:40 +08:00
|
|
|
end program
|