2020-02-14 22:02:29 +08:00
|
|
|
! RUN: %S/test_errors.sh %s %flang %t
|
2019-06-26 07:18:51 +08:00
|
|
|
! OPTIONS: -fopenmp
|
|
|
|
|
|
|
|
! 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-10 05:08:50 +08:00
|
|
|
! TODO: all the internal errors
|
|
|
|
|
2019-07-02 04:55:06 +08:00
|
|
|
integer :: b = 128
|
2019-07-10 05:08:50 +08:00
|
|
|
integer :: 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)
|
|
|
|
|
|
|
|
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 |
|
|
|
|
! proc-bind-clause
|
|
|
|
|
|
|
|
!$omp parallel
|
|
|
|
do i = 1, N
|
|
|
|
a = 3.14
|
|
|
|
enddo
|
|
|
|
!$omp end parallel
|
|
|
|
|
|
|
|
!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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
!ERROR: Internal: no symbol found for 'b'
|
|
|
|
!$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
|
|
|
|
|
2019-07-04 05:24:37 +08:00
|
|
|
!ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
|
2019-07-02 04:55:06 +08:00
|
|
|
!ERROR: A loop directive may not have both a LINEAR clause and an ORDERED clause with a parameter
|
|
|
|
!ERROR: Internal: no symbol found for 'b'
|
|
|
|
!ERROR: Internal: no symbol found for 'a'
|
2019-07-04 05:24:37 +08:00
|
|
|
!$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)
|
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
|
|
|
|
!ERROR: The COPYPRIVATE clause must not be used with the NOWAIT clause
|
|
|
|
!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
|
|
|
|
!$omp simd private(b) reduction(+:a)
|
|
|
|
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
|
|
|
|
|
|
|
|
!ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression
|
|
|
|
!ERROR: Internal: no symbol found for 'b'
|
|
|
|
!$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
|
|
|
|
!ERROR: Internal: no symbol found for 'b'
|
|
|
|
!$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
|
|
|
|
|
|
|
|
!ERROR: GRAINSIZE and NUM_TASKS are mutually exclusive and may not appear on the same TASKLOOP directive
|
|
|
|
!$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
|
|
|
|
!$omp taskloop num_tasks(3) num_tasks(2)
|
|
|
|
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
|
|
|
|
! !$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 ordered depend(source)
|
|
|
|
!ERROR: Internal: no symbol found for 'i'
|
|
|
|
!$omp ordered depend(sink:i-1)
|
|
|
|
!$omp flush (c)
|
|
|
|
!$omp cancel DO
|
|
|
|
!$omp cancellation point parallel
|
2019-08-13 07:08:10 +08:00
|
|
|
|
|
|
|
! 2.13.2 critical Construct
|
|
|
|
|
|
|
|
!ERROR: Internal: no symbol found for 'first'
|
|
|
|
!$omp critical (first)
|
|
|
|
a = 3.14
|
|
|
|
!ERROR: Internal: no symbol found for 'first'
|
|
|
|
!$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
|
|
|
|
|
|
|
|
!ERROR: REDUCTION clause is not allowed on the TASKLOOP SIMD directive
|
|
|
|
!$omp taskloop simd reduction(+:a)
|
|
|
|
do i = 1, N
|
|
|
|
a = a + 3.14
|
|
|
|
enddo
|
|
|
|
!ERROR: Unmatched END TASKLOOP directive
|
|
|
|
!$omp end taskloop
|
|
|
|
|
|
|
|
!ERROR: GRAINSIZE and NUM_TASKS are mutually exclusive and may not appear on the same TASKLOOP SIMD directive
|
|
|
|
!$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
|
|
|
|
!ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression
|
|
|
|
!ERROR: Internal: no symbol found for 'a'
|
|
|
|
!$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
|