[Openmp-commits] [openmp] r338313 - [OpenMP] Fix tasking + parallel bug

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Mon Jul 30 14:47:56 PDT 2018


Author: jlpeyton
Date: Mon Jul 30 14:47:56 2018
New Revision: 338313

URL: http://llvm.org/viewvc/llvm-project?rev=338313&view=rev
Log:
[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

Added:
    openmp/trunk/runtime/test/tasking/bug_36720.c
Modified:
    openmp/trunk/runtime/src/kmp_tasking.cpp

Modified: openmp/trunk/runtime/src/kmp_tasking.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_tasking.cpp?rev=338313&r1=338312&r2=338313&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_tasking.cpp (original)
+++ openmp/trunk/runtime/src/kmp_tasking.cpp Mon Jul 30 14:47:56 2018
@@ -1025,6 +1025,9 @@ kmp_task_t *__kmp_task_alloc(ident_t *lo
   kmp_taskdata_t *parent_task = thread->th.th_current_task;
   size_t shareds_offset;
 
+  if (!TCR_4(__kmp_init_middle))
+    __kmp_middle_initialize();
+
   KA_TRACE(10, ("__kmp_task_alloc(enter): T#%d loc=%p, flags=(0x%x) "
                 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
                 gtid, loc_ref, *((kmp_int32 *)flags), sizeof_kmp_task_t,

Added: openmp/trunk/runtime/test/tasking/bug_36720.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/tasking/bug_36720.c?rev=338313&view=auto
==============================================================================
--- openmp/trunk/runtime/test/tasking/bug_36720.c (added)
+++ openmp/trunk/runtime/test/tasking/bug_36720.c Mon Jul 30 14:47:56 2018
@@ -0,0 +1,34 @@
+// RUN: %libomp-compile-and-run
+
+/*
+Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=36720
+
+Assertion failure at kmp_runtime.cpp(1715): nthreads > 0.
+OMP: Error #13: Assertion failure at kmp_runtime.cpp(1715).
+
+The assertion fails even with OMP_NUM_THREADS=1. If the second task is removed,
+everything runs to completion. If the "omp parallel for" directives are removed
+from inside the tasks, once again everything runs fine.
+*/
+
+#define N 1024
+
+int main() {
+  #pragma omp task
+  {
+    #pragma omp parallel for
+    for (int i = 0; i < N; i++)
+      (void)0;
+  }
+
+  #pragma omp task
+  {
+    #pragma omp parallel for
+    for (int i = 0; i < N; ++i)
+      (void)0;
+  }
+
+  #pragma omp taskwait
+
+  return 0;
+}




More information about the Openmp-commits mailing list