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

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Sep 10 14:15:23 PDT 2020


jlpeyton updated this revision to Diff 291081.
jlpeyton added a comment.

Added enum for GOMP task flags.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87271/new/

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
@@ -17,6 +17,12 @@
 #include "ompt-specific.h"
 #endif
 
+enum {
+  KMP_GOMP_TASK_UNTIED_FLAG = 1,
+  KMP_GOMP_TASK_FINAL_FLAG = 2,
+  KMP_GOMP_TASK_DEPENDS_FLAG = 8
+};
+
 // This class helps convert gomp dependency info into
 // kmp_depend_info_t structures
 class kmp_gomp_depends_info_t {
@@ -1164,11 +1170,11 @@
   KA_TRACE(20, ("GOMP_task: T#%d\n", gtid));
 
   // The low-order bit is the "untied" flag
-  if (!(gomp_flags & 1)) {
+  if (!(gomp_flags & KMP_GOMP_TASK_UNTIED_FLAG)) {
     input_flags->tiedness = 1;
   }
   // The second low-order bit is the "final" flag
-  if (gomp_flags & 2) {
+  if (gomp_flags & KMP_GOMP_TASK_FINAL_FLAG) {
     input_flags->final = 1;
   }
   input_flags->native = 1;
@@ -1206,7 +1212,7 @@
 #endif
 
   if (if_cond) {
-    if (gomp_flags & 8) {
+    if (gomp_flags & KMP_GOMP_TASK_DEPENDS_FLAG) {
       KMP_ASSERT(depend);
       kmp_gomp_depends_info_t gomp_depends(depend);
       kmp_int32 ndeps = gomp_depends.get_num_deps();
@@ -1233,6 +1239,15 @@
       OMPT_STORE_RETURN_ADDRESS(gtid);
     }
 #endif
+    if (gomp_flags & KMP_GOMP_TASK_DEPENDS_FLAG) {
+      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.291081.patch
Type: text/x-patch
Size: 2531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200910/c4b27806/attachment.bin>


More information about the Openmp-commits mailing list