diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/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); diff --git a/openmp/runtime/test/parallel/bug63197.c b/openmp/runtime/test/parallel/bug63197.c new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/parallel/bug63197.c @@ -0,0 +1,17 @@ +// RUN: %libomp-compile-and-run | FileCheck %s + +#include +#include + +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