Skip to content

Commit 9c9eebf

Browse files
author
Jonathan Peyton
committed
[OpenMP] Fix tasking + parallel bug
From the bug report, the runtime needs to initialize the nproc variables (inside middle init) for each root when the task is encountered, otherwise, a segfault can occur. Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=36720 Differential Revision: https://reviews.llvm.org/D49996 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@338313 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 72133c3 commit 9c9eebf

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

runtime/src/kmp_tasking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,9 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
10251025
kmp_taskdata_t *parent_task = thread->th.th_current_task;
10261026
size_t shareds_offset;
10271027

1028+
if (!TCR_4(__kmp_init_middle))
1029+
__kmp_middle_initialize();
1030+
10281031
KA_TRACE(10, ("__kmp_task_alloc(enter): T#%d loc=%p, flags=(0x%x) "
10291032
"sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
10301033
gtid, loc_ref, *((kmp_int32 *)flags), sizeof_kmp_task_t,

runtime/test/tasking/bug_36720.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %libomp-compile-and-run
2+
3+
/*
4+
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=36720
5+
6+
Assertion failure at kmp_runtime.cpp(1715): nthreads > 0.
7+
OMP: Error #13: Assertion failure at kmp_runtime.cpp(1715).
8+
9+
The assertion fails even with OMP_NUM_THREADS=1. If the second task is removed,
10+
everything runs to completion. If the "omp parallel for" directives are removed
11+
from inside the tasks, once again everything runs fine.
12+
*/
13+
14+
#define N 1024
15+
16+
int main() {
17+
#pragma omp task
18+
{
19+
#pragma omp parallel for
20+
for (int i = 0; i < N; i++)
21+
(void)0;
22+
}
23+
24+
#pragma omp task
25+
{
26+
#pragma omp parallel for
27+
for (int i = 0; i < N; ++i)
28+
(void)0;
29+
}
30+
31+
#pragma omp taskwait
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)