[Openmp-commits] [PATCH] D87271: [OpenMP] Fix if0 task with dependencies

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Sep 7 22:25:10 PDT 2020


jlpeyton created this revision.
jlpeyton added a reviewer: AndreyChurbanov.
jlpeyton added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
jlpeyton requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

The current GOMP interface for if0 tasks does not take into
account task dependencies. Add the check and wait for dependencies.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=46573


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87271

Files:
  openmp/runtime/src/kmp_gsupport.cpp
  openmp/runtime/test/tasking/taskdep_if0.c


Index: openmp/runtime/test/tasking/taskdep_if0.c
===================================================================
--- /dev/null
+++ openmp/runtime/test/tasking/taskdep_if0.c
@@ -0,0 +1,39 @@
+// RUN: %libomp-compile-and-run
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <omp.h>
+#include "omp_my_sleep.h"
+
+int a = 0;
+
+void task1() {
+  my_sleep(0.5);
+  a = 10;
+}
+
+void task2() {
+  a++;
+}
+
+int main(int argc, char** argv)
+{
+  #pragma omp parallel shared(argc) num_threads(2)
+  {
+    #pragma omp single
+    {
+      #pragma omp task depend(out: a)
+      task1();
+
+      #pragma omp task if(0) depend(inout: a)
+      task2();
+    }
+  }
+  if (a != 11) {
+    fprintf(stderr, "fail: expected 11, but a is %d\n", a);
+    exit(1);
+  } else {
+    printf("pass\n");
+  }
+  return 0;
+}
Index: openmp/runtime/src/kmp_gsupport.cpp
===================================================================
--- openmp/runtime/src/kmp_gsupport.cpp
+++ openmp/runtime/src/kmp_gsupport.cpp
@@ -1233,6 +1233,15 @@
       OMPT_STORE_RETURN_ADDRESS(gtid);
     }
 #endif
+    if (gomp_flags & 8) {
+      KMP_ASSERT(depend);
+      kmp_gomp_depends_info_t gomp_depends(depend);
+      kmp_int32 ndeps = gomp_depends.get_num_deps();
+      kmp_depend_info_t dep_list[ndeps];
+      for (kmp_int32 i = 0; i < ndeps; i++)
+        dep_list[i] = gomp_depends.get_kmp_depend(i);
+      __kmpc_omp_wait_deps(&loc, gtid, ndeps, dep_list, 0, NULL);
+    }
 
     __kmpc_omp_task_begin_if0(&loc, gtid, task);
     func(data);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87271.290408.patch
Type: text/x-patch
Size: 1530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200908/179bc8ec/attachment-0001.bin>


More information about the Openmp-commits mailing list