Skip to content

Commit 0e0bee2

Browse files
authored
[OpenMP] Fix distributed barrier hang for OMP_WAIT_POLICY=passive (#83058)
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
1 parent d2a9df2 commit 0e0bee2

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,9 +5708,8 @@ void __kmp_free_team(kmp_root_t *root,
57085708
}
57095709
#endif
57105710
// first check if thread is sleeping
5711-
kmp_flag_64<> fl(&th->th.th_bar[bs_forkjoin_barrier].bb.b_go, th);
5712-
if (fl.is_sleeping())
5713-
fl.resume(__kmp_gtid_from_thread(th));
5711+
if (th->th.th_sleep_loc)
5712+
__kmp_null_resume_wrapper(th);
57145713
KMP_CPU_PAUSE();
57155714
}
57165715
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %libomp-compile
2+
// RUN: env OMP_WAIT_POLICY=passive \
3+
// RUN: KMP_FORKJOIN_BARRIER_PATTERN='linear,linear' %libomp-run
4+
// RUN: env OMP_WAIT_POLICY=passive \
5+
// RUN: KMP_FORKJOIN_BARRIER_PATTERN='tree,tree' %libomp-run
6+
// RUN: env OMP_WAIT_POLICY=passive \
7+
// RUN: KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper' %libomp-run
8+
// RUN: env OMP_WAIT_POLICY=passive \
9+
// RUN: KMP_FORKJOIN_BARRIER_PATTERN='dist,dist' %libomp-run
10+
//
11+
// LLVM ISSUE 80664: https://github.com/llvm/llvm-project/issues/80664
12+
//
13+
// Distributed barrier + OMP_WAIT_POLICY=passive hangs in library termination
14+
// Reason: the resume logic in __kmp_free_team() was faulty and, when checking
15+
// for sleep status, didn't look at correct location for distributed barrier.
16+
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
20+
int a = 0;
21+
22+
void test_omp_barrier() {
23+
#pragma omp parallel
24+
{
25+
#pragma omp task
26+
{
27+
#pragma omp atomic
28+
a++;
29+
}
30+
}
31+
}
32+
33+
int main() {
34+
test_omp_barrier();
35+
printf("a = %d\n", a);
36+
return EXIT_SUCCESS;
37+
}

0 commit comments

Comments
 (0)