Skip to content

Commit

Permalink
[Flang][OpenMP] Restrict check to worksharing construct reductions
Browse files Browse the repository at this point in the history
The outer context private check for reduction variables was firing
for all constructs. This check is not applicable to non-worksharing
constructs.

OpenMP 5.2: Section 5.5.8
A list item that appears in a reduction clause on a worksharing construct
must be shared in the parallel region to which a correspodning worksharing
region binds.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D144824
  • Loading branch information
kiranchandramohan committed Mar 9, 2023
1 parent 99d053a commit 460c2ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
10 changes: 8 additions & 2 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,13 @@ void OmpStructureChecker::CheckReductionTypeList(
CheckIntentInPointerAndDefinable(
ompObjectList, llvm::omp::Clause::OMPC_reduction);
CheckReductionArraySection(ompObjectList);
CheckMultipleAppearanceAcrossContext(ompObjectList);
// If this is a worksharing construct then ensure the reduction variable
// is not private in the parallel region that it binds to.
OmpDirectiveSet workshareSet{llvm::omp::Directive::OMPD_do,
llvm::omp::Directive::OMPD_sections, llvm::omp::Directive::OMPD_do_simd};
if (workshareSet.test(GetContext().directive)) {
CheckSharedBindingInOuterContext(ompObjectList);
}
}

void OmpStructureChecker::CheckIntentInPointerAndDefinable(
Expand Down Expand Up @@ -2026,7 +2032,7 @@ void OmpStructureChecker::CheckReductionArraySection(
}
}

void OmpStructureChecker::CheckMultipleAppearanceAcrossContext(
void OmpStructureChecker::CheckSharedBindingInOuterContext(
const parser::OmpObjectList &redObjectList) {
// TODO: Verify the assumption here that the immediately enclosing region is
// the parallel region to which the worksharing construct having reduction
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class OmpStructureChecker
const parser::OmpObjectList &, const llvm::omp::Clause);
void CheckArraySection(const parser::ArrayElement &arrayElement,
const parser::Name &name, const llvm::omp::Clause clause);
void CheckMultipleAppearanceAcrossContext(
void CheckSharedBindingInOuterContext(
const parser::OmpObjectList &ompObjectList);
const parser::OmpObjectList *GetOmpObjectList(const parser::OmpClause &);
void CheckPredefinedAllocatorRestriction(const parser::CharBlock &source,
Expand Down
46 changes: 10 additions & 36 deletions flang/test/Semantics/OpenMP/reduction07.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,24 @@ program omp_reduction
!$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 = a + 10
!$omp end workshare
!$omp end parallel

!$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 = a + 10
!$omp end single
!$omp end parallel

!$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(iand:a)
a = a + 10
!$omp end single
!$omp end parallel

!$omp parallel reduction(iand:a)
!$omp end parallel

!$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 = ieor(a, 10)
!$omp end sections
!$omp end parallel

!$omp parallel private(a)
!$omp parallel reduction(ieor:a)
!$omp end parallel
!$omp end parallel

!$omp task firstprivate(a)
!$omp parallel do reduction(+:a)
do i=1,10
a=a+j
end do
!$omp end parallel do
!$omp end task

end program omp_reduction

0 comments on commit 460c2ea

Please sign in to comment.