[Openmp-commits] [PATCH] D80577: [OpenMP] Fixed taskloop recursive splitting so that taskloop tasks have same parent tasks.

Andrey Churbanov via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue May 26 10:50:00 PDT 2020


AndreyChurbanov created this revision.
AndreyChurbanov added reviewers: hbae, tlwilmar.
AndreyChurbanov added a project: OpenMP.
Herald added subscribers: openmp-commits, sstefan1, jfb, guansong, yaxunl.
Herald added a reviewer: jdoerfert.

The "taskloop nowait" was broken because of taskloop tasks had different parent tasks if recursive splitting algorithm used.

The patch fixes this making all generated tasks have same parent task regardless of generating thread and task (taskloop tasks can be generated by different threads at different levels of recursive splitting process), this is done for both actual taskloop tasks and auxiliary tasks used for recursive splitting of iteration space.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80577

Files:
  openmp/runtime/src/kmp_tasking.cpp
  openmp/runtime/test/tasking/omp_taskloop_taskwait.c


Index: openmp/runtime/test/tasking/omp_taskloop_taskwait.c
===================================================================
--- /dev/null
+++ openmp/runtime/test/tasking/omp_taskloop_taskwait.c
@@ -0,0 +1,30 @@
+// RUN: %libomp-compile-and-run
+#include <stdio.h>
+#include <omp.h>
+int main()
+{
+  enum {ITERS = 500};
+  enum {SIZE = 5};
+  int err = 0;
+  #pragma omp parallel num_threads(2) reduction(+:err)
+  {
+    int r = 0;
+    int i;
+    #pragma omp taskloop grainsize(SIZE) shared(r) nogroup
+    for(i=0; i<ITERS; i++) {
+      #pragma omp atomic
+        ++r;
+    }
+    #pragma omp taskwait
+    printf("%d\n", r);
+    if (r != ITERS)
+      err++;
+  } // end of parallel
+  if (err != 0) {
+    printf("failed, err = %d\n", err);
+    return 1;
+  } else {
+    printf("passed\n");
+    return 0;
+  }
+}
Index: openmp/runtime/src/kmp_tasking.cpp
===================================================================
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -3898,14 +3898,13 @@
 kmp_task_t *__kmp_task_dup_alloc(kmp_info_t *thread, kmp_task_t *task_src) {
   kmp_task_t *task;
   kmp_taskdata_t *taskdata;
-  kmp_taskdata_t *taskdata_src;
-  kmp_taskdata_t *parent_task = thread->th.th_current_task;
+  kmp_taskdata_t *taskdata_src = KMP_TASK_TO_TASKDATA(task_src);
+  kmp_taskdata_t *parent_task = taskdata_src->td_parent; // same parent task
   size_t shareds_offset;
   size_t task_size;
 
   KA_TRACE(10, ("__kmp_task_dup_alloc(enter): Th %p, source task %p\n", thread,
                 task_src));
-  taskdata_src = KMP_TASK_TO_TASKDATA(task_src);
   KMP_DEBUG_ASSERT(taskdata_src->td_flags.proxy ==
                    TASK_FULL); // it should not be proxy task
   KMP_DEBUG_ASSERT(taskdata_src->td_flags.tasktype == TASK_EXPLICIT);
@@ -4280,7 +4279,6 @@
                           void *codeptr_ra,
 #endif
                           void *task_dup) {
-#if KMP_DEBUG
   kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
   KMP_DEBUG_ASSERT(task != NULL);
   KMP_DEBUG_ASSERT(num_tasks > num_t_min);
@@ -4288,7 +4286,6 @@
                 " %lld, extras %lld, i=%lld,%lld(%d), dup %p\n",
                 gtid, taskdata, num_tasks, grainsize, extras, *lb, *ub, st,
                 task_dup));
-#endif
   p_task_dup_t ptask_dup = (p_task_dup_t)task_dup;
   kmp_uint64 lower = *lb;
   kmp_info_t *thread = __kmp_threads[gtid];
@@ -4332,9 +4329,14 @@
   *ub = ub0; // adjust upper bound for the 1st half
 
   // create auxiliary task for 2nd half of the loop
+  // make sure new task has same parent task as the pattern task
+  kmp_taskdata_t *current_task = thread->th.th_current_task;
+  thread->th.th_current_task = taskdata->td_parent;
   kmp_task_t *new_task =
       __kmpc_omp_task_alloc(loc, gtid, 1, 3 * sizeof(void *),
                             sizeof(__taskloop_params_t), &__kmp_taskloop_task);
+  // restore current task
+  thread->th.th_current_task = current_task;
   __taskloop_params_t *p = (__taskloop_params_t *)new_task->shareds;
   p->task = next_task;
   p->lb = (kmp_uint64 *)((char *)next_task + lower_offset);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80577.266269.patch
Type: text/x-patch
Size: 3109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200526/e3566d44/attachment-0001.bin>


More information about the Openmp-commits mailing list