[Flang][OpenMP] Provide an error when the minus operator is used in a reduction

OpenMP 5.2 standard has deprecated the usage of the minus operation in
reductions. The minus operation also is an unpleasant feature with
varied interpretations.

The patch also changes the usage of the minus operator in some existing testcases.

Discussed in https://discourse.llvm.org/t/openmp-runtime-problem-with-subtraction-reduction/64404

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D132060
This commit is contained in:
Kiran Chandramohan 2022-08-18 14:34:45 +00:00
parent 23f60d43a2
commit 495b8e104d
8 changed files with 51 additions and 42 deletions

View File

@ -1924,13 +1924,17 @@ bool OmpStructureChecker::CheckIntrinsicOperator(
switch (op) {
case parser::DefinedOperator::IntrinsicOperator::Add:
case parser::DefinedOperator::IntrinsicOperator::Subtract:
case parser::DefinedOperator::IntrinsicOperator::Multiply:
case parser::DefinedOperator::IntrinsicOperator::AND:
case parser::DefinedOperator::IntrinsicOperator::OR:
case parser::DefinedOperator::IntrinsicOperator::EQV:
case parser::DefinedOperator::IntrinsicOperator::NEQV:
return true;
case parser::DefinedOperator::IntrinsicOperator::Subtract:
context_.Say(GetContext().clauseSource,
"The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause."_err_en_US,
ContextDirectiveAsFortran());
break;
default:
context_.Say(GetContext().clauseSource,
"Invalid reduction operator in REDUCTION clause."_err_en_US,

View File

@ -1,15 +0,0 @@
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! CHECK: not yet implemented: Reduction of some intrinsic operators is not supported
subroutine reduction_subtract
integer :: x
!$omp parallel
!$omp do reduction(-:x)
do i=1, 100
x = x - i
end do
!$omp end do
!$omp end parallel
print *, x
end subroutine

View File

@ -42,11 +42,11 @@ program omp_firstprivate
!$omp end do
!$omp end parallel
!$omp parallel reduction(-:a)
!$omp parallel reduction(*:a)
!ERROR: FIRSTPRIVATE variable 'a' is PRIVATE in outer context
!$omp do firstprivate(a,b)
do i = 1, 10
c(i) = c(i) - a(i) * b(i) * i
c(i) = c(i) * a(i) * b(i) * i
end do
!$omp end do
!$omp end parallel
@ -59,10 +59,10 @@ program omp_firstprivate
!$omp end sections
!$omp end parallel
!$omp parallel reduction(-:a)
!$omp parallel reduction(*:a)
!ERROR: FIRSTPRIVATE variable 'a' is PRIVATE in outer context
!$omp task firstprivate(a,b)
c = c - a * b
c = c * a * b
!$omp end task
!$omp end parallel

View File

@ -0,0 +1,13 @@
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
! OpenMP Version 5.2
! Minus operation is deprecated in reduction
subroutine reduction_subtract
integer :: x
!ERROR: The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause.
!$omp do reduction(-:x)
do i=1, 100
x = x - i
end do
!$omp end do
end subroutine

View File

@ -8,30 +8,36 @@ program omp_reduction
integer :: j = 10
!ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive
!$omp parallel do reduction(+:k), reduction(-:k)
!$omp parallel do reduction(+:k), reduction(*:k)
do i = 1, 10
k = k + 1
k = k * 3
end do
!$omp end parallel do
!ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive
!$omp parallel do reduction(+:k), reduction(-:j), reduction(+:k)
!$omp parallel do reduction(+:k), reduction(*:j), reduction(+:k)
do i = 1, 10
k = k + 1
j = j * 3
end do
!$omp end parallel do
!ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive
!$omp parallel do reduction(+:j), reduction(-:k), reduction(+:k)
!$omp parallel do reduction(+:j), reduction(*:k), reduction(+:k)
do i = 1, 10
j = j + 1
k = k + 1
k = k * 3
end do
!$omp end parallel do
!ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive
!$omp parallel do reduction(+:j), reduction(-:k), private(k)
!$omp parallel do reduction(+:j), reduction(*:k), private(k)
do i = 1, 10
j = j + 1
k = k + 1
k = k * 3
end do
!$omp end parallel do
end program omp_reduction

View File

@ -14,7 +14,7 @@ program omp_Reduction
!$omp end parallel do
!ERROR: Variable 'c' on the REDUCTION clause is not definable
!$omp parallel do reduction(-:/c/)
!$omp parallel do reduction(*:/c/)
do i = 1, 10
l = k + 1
end do

View File

@ -3,7 +3,7 @@
! 2.15.3.6 Reduction Clause
program omp_reduction
integer :: i,j,l
integer :: a,i,j,l
integer :: k = 10
!$omp parallel private(k)
!ERROR: REDUCTION variable 'k' is PRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
@ -15,7 +15,7 @@ program omp_reduction
!$omp end parallel
!$omp parallel private(j),reduction(-:k)
!$omp parallel private(j),reduction(+:k)
!ERROR: REDUCTION variable 'k' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp do reduction(+:k)
do i = 1, 10
@ -37,9 +37,10 @@ program omp_reduction
!$omp parallel private(l,j),firstprivate(k)
!ERROR: REDUCTION variable 'k' is FIRSTPRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!ERROR: REDUCTION variable 'j' is PRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp sections reduction(ior:k) reduction(-:j)
!$omp sections reduction(ior:k) reduction(*:j)
do i = 1, 10
k = k + 1
k = ior(k, 1)
j = j * 3
end do
!$omp end sections
!$omp end parallel
@ -69,36 +70,36 @@ program omp_reduction
!$omp parallel reduction(+:a)
!ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp sections reduction(-:a)
a = 10
!$omp sections reduction(*:a)
a = a + 10
!$omp end sections
!$omp end parallel
!$omp parallel reduction(-:a)
!$omp parallel reduction(*:a)
!$omp end parallel
!$omp parallel reduction(+:a)
!ERROR: REDUCTION clause is not allowed on the WORKSHARE directive
!ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp workshare reduction(-:a)
a = 10
!$omp workshare reduction(*:a)
a = a + 10
!$omp end workshare
!$omp end parallel
!$omp parallel reduction(-:a)
!$omp parallel reduction(*:a)
!$omp end parallel
!$omp parallel reduction(+:a)
!ERROR: REDUCTION clause is not allowed on the SINGLE directive
!ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp single reduction(-:a)
a = 10
!$omp single reduction(*:a)
a = a + 10
!$omp end single
!$omp end parallel
!$omp parallel reduction(-:a)
!$omp parallel reduction(+:a)
!$omp end parallel
@ -106,7 +107,7 @@ a = 10
!ERROR: REDUCTION clause is not allowed on the SINGLE directive
!ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp single reduction(iand:a)
a = 10
a = a + 10
!$omp end single
!$omp end parallel
@ -115,8 +116,8 @@ a = 10
!$omp parallel reduction(ieor:a)
!ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind.
!$omp sections reduction(-:a)
a = 10
!$omp sections reduction(+:a)
a = ieor(a, 10)
!$omp end sections
!$omp end parallel

View File

@ -66,7 +66,7 @@ program omp_reduction
!$omp end do
!$omp end parallel
!$omp do reduction(-:k) reduction(*:j) reduction(-:l)
!$omp do reduction(+:k) reduction(*:j) reduction(+:l)
!DEF: /omp_reduction/OtherConstruct7/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
do i=1,10
!DEF: /omp_reduction/OtherConstruct7/k (OmpReduction) HostAssoc INTEGER(4)