[Openmp-commits] [openmp] [OpenMP] Fix distributed barrier hang for OMP_WAIT_POLICY=passive (PR #83058)
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Mon Feb 26 13:39:42 PST 2024
https://github.com/jpeyton52 updated https://github.com/llvm/llvm-project/pull/83058
>From d10e1b505a4cbd7632d2bc83de9a00a2cc83b9c2 Mon Sep 17 00:00:00 2001
From: Jonathan Peyton <jonathan.l.peyton at intel.com>
Date: Mon, 26 Feb 2024 14:23:46 -0600
Subject: [PATCH 1/2] [OpenMP] Fix distributed barrier hang for
OMP_WAIT_POLICY=passive
The resume thread logic inside __kmp_free_team() is faulty. Only
checking b_go for sleep status doesn't wake up distributed barrier.
Change to generic check for th_sleep_loc and calling
__kmp_null_resume_wrapper().
Fixes: #80664
---
openmp/runtime/src/kmp_runtime.cpp | 5 ++-
.../runtime/test/barrier/llvm-issue-80664.c | 34 +++++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
create mode 100644 openmp/runtime/test/barrier/llvm-issue-80664.c
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index fc5e8405a415ed..7edb0b440acc7f 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -5708,9 +5708,8 @@ void __kmp_free_team(kmp_root_t *root,
}
#endif
// first check if thread is sleeping
- kmp_flag_64<> fl(&th->th.th_bar[bs_forkjoin_barrier].bb.b_go, th);
- if (fl.is_sleeping())
- fl.resume(__kmp_gtid_from_thread(th));
+ if (th->th.th_sleep_loc)
+ __kmp_null_resume_wrapper(th);
KMP_CPU_PAUSE();
}
}
diff --git a/openmp/runtime/test/barrier/llvm-issue-80664.c b/openmp/runtime/test/barrier/llvm-issue-80664.c
new file mode 100644
index 00000000000000..c56052eafbea9d
--- /dev/null
+++ b/openmp/runtime/test/barrier/llvm-issue-80664.c
@@ -0,0 +1,34 @@
+// RUN: %libomp-compile
+// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='linear,linear' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='tree,tree' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='dist,dist' %libomp-run
+//
+// LLVM ISSUE 80664: https://github.com/llvm/llvm-project/issues/80664
+//
+// Distributed barrier + OMP_WAIT_POLICY=passive hangs in library termination
+// Reason: the resume logic in __kmp_free_team() was faulty and, when checking
+// for sleep status, didn't look at correct location for distributed barrier.
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int a = 0;
+
+void test_omp_barrier()
+{
+ #pragma omp parallel
+ {
+ #pragma omp task
+ {
+ #pragma omp atomic
+ a++;
+ }
+ }
+}
+
+int main() {
+ test_omp_barrier();
+ printf("a = %d\n", a);
+ return EXIT_SUCCESS;
+}
>From e5b253772686f2fe1eef6e1eb183425b1adc2c71 Mon Sep 17 00:00:00 2001
From: Jonathan Peyton <jonathan.l.peyton at intel.com>
Date: Mon, 26 Feb 2024 15:36:14 -0600
Subject: [PATCH 2/2] Fixup clang formatting issues with test file
---
.../runtime/test/barrier/llvm-issue-80664.c | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/openmp/runtime/test/barrier/llvm-issue-80664.c b/openmp/runtime/test/barrier/llvm-issue-80664.c
index c56052eafbea9d..79aa228afa6be0 100644
--- a/openmp/runtime/test/barrier/llvm-issue-80664.c
+++ b/openmp/runtime/test/barrier/llvm-issue-80664.c
@@ -1,8 +1,12 @@
// RUN: %libomp-compile
-// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='linear,linear' %libomp-run
-// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='tree,tree' %libomp-run
-// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper' %libomp-run
-// RUN: env OMP_WAIT_POLICY=passive KMP_FORKJOIN_BARRIER_PATTERN='dist,dist' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive \
+// RUN: KMP_FORKJOIN_BARRIER_PATTERN='linear,linear' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive \
+// RUN: KMP_FORKJOIN_BARRIER_PATTERN='tree,tree' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive \
+// RUN: KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper' %libomp-run
+// RUN: env OMP_WAIT_POLICY=passive \
+// RUN: KMP_FORKJOIN_BARRIER_PATTERN='dist,dist' %libomp-run
//
// LLVM ISSUE 80664: https://github.com/llvm/llvm-project/issues/80664
//
@@ -15,13 +19,12 @@
int a = 0;
-void test_omp_barrier()
-{
- #pragma omp parallel
+void test_omp_barrier() {
+#pragma omp parallel
{
- #pragma omp task
+#pragma omp task
{
- #pragma omp atomic
+#pragma omp atomic
a++;
}
}
More information about the Openmp-commits
mailing list