[Openmp-commits] [openmp] 5e111c5 - [openmp] Fixed taskloop recursive splitting so that taskloop tasks have

via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 1 07:53:19 PDT 2020


Author: AndreyChurbanov
Date: 2020-06-01T17:51:02+03:00
New Revision: 5e111c5df8efde39c62d5e6906f590311782e30b

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

LOG: [openmp] Fixed taskloop recursive splitting so that taskloop tasks have
same parent tasks.

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

Added: 
    openmp/runtime/test/tasking/omp_taskloop_taskwait.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 6e584731a85f..a8da6146064c 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -3898,14 +3898,13 @@ void __kmp_fulfill_event(kmp_event_t *event) {
 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 __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task,
                           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 @@ void __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task,
                 " %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 @@ void __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task,
   *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);

diff  --git a/openmp/runtime/test/tasking/omp_taskloop_taskwait.c b/openmp/runtime/test/tasking/omp_taskloop_taskwait.c
new file mode 100644
index 000000000000..6cb226461c8e
--- /dev/null
+++ b/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;
+  }
+}


        


More information about the Openmp-commits mailing list