[Openmp-commits] [PATCH] D152883: [OpenMP] Fix the issue where `num_threads` still takes effect incorrectly

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jun 14 08:46:34 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG85592d3d4d40: [OpenMP] Fix the issue where `num_threads` still takes effect incorrectly (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152883

Files:
  openmp/runtime/src/kmp_runtime.cpp
  openmp/runtime/test/parallel/bug63197.c


Index: openmp/runtime/test/parallel/bug63197.c
===================================================================
--- /dev/null
+++ openmp/runtime/test/parallel/bug63197.c
@@ -0,0 +1,17 @@
+// RUN: %libomp-compile-and-run | FileCheck %s
+
+#include <omp.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+#pragma omp parallel num_threads(3) if (false)
+#pragma omp single
+  { printf("BBB %2d\n", omp_get_num_threads()); }
+
+#pragma omp parallel
+#pragma omp single
+  { printf("CCC %2d\n", omp_get_num_threads()); }
+  return 0;
+}
+
+// CHECK-NOT: CCC  3
Index: openmp/runtime/src/kmp_runtime.cpp
===================================================================
--- openmp/runtime/src/kmp_runtime.cpp
+++ openmp/runtime/src/kmp_runtime.cpp
@@ -1153,6 +1153,9 @@
   // Reset for next parallel region
   this_thr->th.th_set_proc_bind = proc_bind_default;
 
+  // Reset num_threads for next parallel region
+  this_thr->th.th_set_nproc = 0;
+
 #if OMPT_SUPPORT
   ompt_data_t ompt_parallel_data = ompt_data_none;
   void *codeptr = OMPT_LOAD_RETURN_ADDRESS(global_tid);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152883.531358.patch
Type: text/x-patch
Size: 1085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230614/6955cc1f/attachment.bin>


More information about the Openmp-commits mailing list