-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[flang][OpenMP] Don't allow DO CONCURRENT inside of a loop nest #144506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I don't think DO CONCURRENT fits the definition of a Canonical Loop Nest (OpenMP 6.0 section 6.4.1). Fixes llvm#144178
if (loop->IsDoConcurrent()) { | ||
auto &stmt = | ||
std::get<parser::Statement<parser::NonLabelDoStmt>>(loop->t); | ||
context_.Say(stmt.source, | ||
"DO CONCURRENT loops cannot form part of a loop nest."_err_en_US); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DO CONCURRENT is allowed in the LOOP construct, although, IIUC, only as the top-level loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ab3fba8 allows do concurrent as a single loop construct but not as part of a loop nest. Does that match your understanding of the standard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's allowed in any worksharing-loop construct, only in the LOOP construct [6.0:424:1] "The collapsed loop may be a DO CONCURRENT loop." No other constructs in that chapter have this annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out.
If the collapsed loop is a DO CONCURRENT loop, neither the data-sharing attribute clauses nor the collapse clause may be specified.
I am taking this to mean that DO CONCURRENT is allowed with LOOP, but not when LOOP has a COLLAPSE clause. "Collapsed loop" seems elsewhere to refer to anything enclosed by the LOOP construct.
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-openmp Author: Tom Eccles (tblah) ChangesI don't think DO CONCURRENT fits the definition of a Canonical Loop Nest (OpenMP 6.0 section 6.4.1). Fixes #144178 Full diff: https://github.com/llvm/llvm-project/pull/144506.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index b5f8667fe36f2..05568cc0ba0ae 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1952,6 +1952,13 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
if (outer.has_value()) {
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
+ // DO CONCURRENT is allowed for loop constructs but not loop nests
+ if (loop->IsDoConcurrent() && GetContext().associatedLoopLevel != 1) {
+ auto &stmt =
+ std::get<parser::Statement<parser::NonLabelDoStmt>>(loop->t);
+ context_.Say(stmt.source,
+ "DO CONCURRENT loops cannot form part of a loop nest."_err_en_US);
+ }
// go through all the nested do-loops and resolve index variables
const parser::Name *iv{GetLoopIndex(*loop)};
if (iv) {
diff --git a/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90 b/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90
new file mode 100644
index 0000000000000..71e1928e1f245
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90
@@ -0,0 +1,19 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+integer :: i, j
+!$omp parallel do collapse(2)
+do i = 1, 1
+ ! ERROR: DO CONCURRENT loops cannot form part of a loop nest.
+ do concurrent (j = 1:2)
+ print *, j
+ end do
+end do
+
+!$omp parallel do
+do i = 1, 1
+ ! This should not lead to an error because it is not part of a loop nest:
+ do concurrent (j = 1:2)
+ print *, j
+ end do
+end do
+end
|
This reverts commit ab3fba8.
There's some obscure language in OpenMP 6.0: > If the collapsed loop is a DO CONCURRENT loop, neither the > data-sharing attribute clauses nor the collapse clause may be specified. From the surrounding context, I think "collapsed loop" just means the loop that the LOOP construct applies to. So I will interpret this to mean that DO CONCURRENT can only be used with the LOOP construct if it does not contain the COLLAPSE clause. This also fixes a bug where the associated clause was never cleared after it was set.
I don't think DO CONCURRENT fits the definition of a Canonical Loop Nest (OpenMP 6.0 section 6.4.1).
It is however explicitly allowed for the LOOP construct (6.0 section 13.8).
There's some obscure language in OpenMP 6.0 for the LOOP construct:
From the surrounding context, I think "collapsed loop" just means the
loop that the LOOP construct applies to. So I will interpret this to
mean that DO CONCURRENT can only be used with the LOOP construct if it
does not contain the COLLAPSE clause.
This also fixes a bug where the associated clause was never cleared
after it was set.
Fixes #144178