[Openmp-commits] [PATCH] D49996: [OpenMP] Fix tasking + parallel bug

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Jul 30 11:12:48 PDT 2018


jlpeyton created this revision.
jlpeyton added reviewers: grokos, Hahnfeld.
jlpeyton added a project: OpenMP.
Herald added a subscriber: guansong.

>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


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D49996

Files:
  runtime/src/kmp_tasking.cpp
  runtime/test/tasking/bug_36720.c


Index: runtime/test/tasking/bug_36720.c
===================================================================
--- /dev/null
+++ runtime/test/tasking/bug_36720.c
@@ -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;
+}
Index: runtime/src/kmp_tasking.cpp
===================================================================
--- runtime/src/kmp_tasking.cpp
+++ runtime/src/kmp_tasking.cpp
@@ -1228,6 +1228,8 @@
                                   kmp_routine_entry_t task_entry) {
   kmp_task_t *retval;
   kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
+  if (!TCR_4(__kmp_init_middle))
+    __kmp_middle_initialize();
 
   input_flags->native = FALSE;
 // __kmp_task_alloc() sets up all other runtime flags


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49996.158015.patch
Type: text/x-patch
Size: 1420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20180730/fe1da028/attachment.bin>


More information about the Openmp-commits mailing list