[Openmp-commits] [openmp] ae04446 - [openmp][runtime] Fixed hang for explicit task inside a taskloop.

via Openmp-commits openmp-commits at lists.llvm.org
Mon Mar 23 10:08:13 PDT 2020


Author: AndreyChurbanov
Date: 2020-03-23T20:07:30+03:00
New Revision: ae044467ede146556b6a424f4486ebbbc920e95f

URL: https://github.com/llvm/llvm-project/commit/ae044467ede146556b6a424f4486ebbbc920e95f
DIFF: https://github.com/llvm/llvm-project/commit/ae044467ede146556b6a424f4486ebbbc920e95f.diff

LOG: [openmp][runtime] Fixed hang for explicit task inside a taskloop.

Added missed initialization of td_last_tied field for taskloop tasks.

Differential Revision: https://reviews.llvm.org/D75673

Added: 
    openmp/runtime/test/tasking/omp_task_red_taskloop.c

Modified: 
    openmp/runtime/src/kmp_tasking.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 15ffc1454fe9..6dae9dc73e7a 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -3923,9 +3923,12 @@ kmp_task_t *__kmp_task_dup_alloc(kmp_info_t *thread, kmp_task_t *task_src) {
   }
   taskdata->td_alloc_thread = thread;
   taskdata->td_parent = parent_task;
-  taskdata->td_taskgroup =
-      parent_task
-          ->td_taskgroup; // task inherits the taskgroup from the parent task
+  // task inherits the taskgroup from the parent task
+  taskdata->td_taskgroup = parent_task->td_taskgroup;
+  // tied task needs to initialize the td_last_tied at creation,
+  // untied one does this when it is scheduled for execution
+  if (taskdata->td_flags.tiedness == TASK_TIED)
+    taskdata->td_last_tied = taskdata;
 
   // Only need to keep track of child task counts if team parallel and tasking
   // not serialized

diff  --git a/openmp/runtime/test/tasking/omp_task_red_taskloop.c b/openmp/runtime/test/tasking/omp_task_red_taskloop.c
new file mode 100644
index 000000000000..89c66256da73
--- /dev/null
+++ b/openmp/runtime/test/tasking/omp_task_red_taskloop.c
@@ -0,0 +1,57 @@
+// RUN: %libomp-compile-and-run
+
+#include <stdio.h>
+#include <omp.h>
+
+int r;
+
+int work(int k, int l)
+{
+  return k + l + 1;
+}
+void bar(int i) {
+  #pragma omp taskgroup task_reduction(+:r)
+ { int th_gen = omp_get_thread_num();
+  #pragma omp task in_reduction(+:r) firstprivate(i, th_gen)
+  {
+    r += work(i, 0);
+printf("executing task (%d, 0), th %d (gen by th %d)\n", i, omp_get_thread_num(), th_gen);
+  }
+  #pragma omp task in_reduction(+:r) firstprivate(i, th_gen)
+  {
+    r += work(i, 1);
+printf("executing task (%d, 1), th %d (gen by th %d)\n", i, omp_get_thread_num(), th_gen);
+  }
+ }
+}
+int foo() {
+  int i;
+  int th_gen = omp_get_thread_num();
+  #pragma omp taskgroup task_reduction(+:r)
+  {
+    bar(0);
+  }
+printf("th %d passed bar0\n", th_gen);
+  #pragma omp taskloop reduction(+:r) firstprivate(th_gen)
+  for (i = 1; i < 4; ++i) {
+    bar(i);
+printf("th %d (gen by th %d) passed bar%d in taskloop\n", omp_get_thread_num(), th_gen, i);
+//  #pragma omp task in_reduction(+:r)
+    r += i;
+  }
+  return 0;
+}
+// res = 2*((1+2)+(2+3)+(3+4)+(4+5)+1+2+3) = 60
+#define res 60
+int main()
+{
+  r = 0;
+  #pragma omp parallel num_threads(2)
+    foo();
+  if (r == res) {
+    return 0;
+  } else {
+    printf("error r = %d (!= %d)\n", r, res);
+    return 1;
+  }
+}


        


More information about the Openmp-commits mailing list