[Openmp-commits] [PATCH] D70713: Fixed nonmonotonic dynamic schedule for case when #threads > #chunks in a loop.

Andrey Churbanov via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Nov 27 04:29:16 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd2fb41c2dd5: [openmp] Fixed nonmonotonic schedule when #threads > #chunks in a loop. (authored by AndreyChurbanov).

Changed prior to commit:
  https://reviews.llvm.org/D70713?vs=231052&id=231214#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70713

Files:
  openmp/runtime/src/kmp_dispatch.cpp
  openmp/runtime/test/worksharing/for/omp_nonmonotonic_dynamic1.c


Index: openmp/runtime/test/worksharing/for/omp_nonmonotonic_dynamic1.c
===================================================================
--- /dev/null
+++ openmp/runtime/test/worksharing/for/omp_nonmonotonic_dynamic1.c
@@ -0,0 +1,40 @@
+// RUN: %libomp-compile
+// RUN: env OMP_SCHEDULE=nonmonotonic:dynamic,10 %libomp-run
+
+// The test checks iterations distribution for OMP 5.0 nonmonotonic OMP_SCHEDULE
+// case #threads > #chunks (fallback to monotonic dynamic)
+
+#include <stdio.h>
+#include <omp.h>
+
+#define ITERS 100
+#define CHUNK 10
+int err = 0;
+
+int main(int argc, char **argv) {
+  int i, ch, it[ITERS];
+  omp_set_num_threads(16); // #threads is bigger than #chunks
+#pragma omp parallel for schedule(runtime)
+  for (i = 0; i < ITERS; ++i) {
+    it[i] = omp_get_thread_num();
+  }
+  // check that each chunk executed by single thread
+  for (ch = 0; ch < ITERS/CHUNK; ++ch) {
+    int iter = ch * CHUNK;
+    int nt = it[iter]; // thread number
+    for (i = 1; i < CHUNK; ++i) {
+#if _DEBUG
+      printf("iter %d: (%d %d)\n", iter + i, nt, it[iter + i]);
+#endif
+      if (nt != it[iter + i]) {
+        err++;
+      }
+    }
+  }
+  if (err > 0) {
+    printf("Failed, err = %d\n", err);
+    return 1;
+  }
+  printf("Passed\n");
+  return 0;
+}
Index: openmp/runtime/src/kmp_dispatch.cpp
===================================================================
--- openmp/runtime/src/kmp_dispatch.cpp
+++ openmp/runtime/src/kmp_dispatch.cpp
@@ -379,14 +379,15 @@
       }
       break;
     } else {
-      KD_TRACE(100, ("__kmp_dispatch_init_algorithm: T#%d falling-through to "
-                     "kmp_sch_static_balanced\n",
-                     gtid));
-      schedule = kmp_sch_static_balanced;
-      /* too few iterations: fall-through to kmp_sch_static_balanced */
+      /* too few chunks: switching to kmp_sch_dynamic_chunked */
+      schedule = kmp_sch_dynamic_chunked;
+      KD_TRACE(100, ("__kmp_dispatch_init_algorithm: T#%d switching to "
+                     "kmp_sch_dynamic_chunked\n",
+                      gtid));
+      if (pr->u.p.parm1 <= 0)
+        pr->u.p.parm1 = KMP_DEFAULT_CHUNK;
+      break;
     } // if
-    /* FALL-THROUGH to static balanced */
-    KMP_FALLTHROUGH();
   } // case
 #endif
   case kmp_sch_static_balanced: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70713.231214.patch
Type: text/x-patch
Size: 2293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20191127/e8ccd100/attachment-0001.bin>


More information about the Openmp-commits mailing list