aboutsummaryrefslogtreecommitdiff
path: root/openmp/runtime/src
diff options
context:
space:
mode:
authorShilei Tian <i@tianshilei.me>2023-06-14 11:45:49 -0400
committerShilei Tian <i@tianshilei.me>2023-06-14 11:46:12 -0400
commit85592d3d4d402b99df32bcc711bca56a8a593c97 (patch)
tree3700eba12361be6971ceea9ba7b9fce8ffa20262 /openmp/runtime/src
parent27fac4a72ae54a471471a69c0ad999585ccbb026 (diff)
downloadllvm-85592d3d4d402b99df32bcc711bca56a8a593c97.zip
llvm-85592d3d4d402b99df32bcc711bca56a8a593c97.tar.gz
llvm-85592d3d4d402b99df32bcc711bca56a8a593c97.tar.bz2
[OpenMP] Fix the issue where `num_threads` still takes effect incorrectly
This patch fixes the issue that, if we have a compile-time serialized parallel region (such as `if (0)`) with `num_threads`, followed by a regular parallel region, the regular parallel region will pick up the value set in the serialized parallel region incorrectly. The reason is, in the front end, if we can prove a parallel region has to serialized, instead of emitting `__kmpc_fork_call`, the front end directly emits `__kmpc_serialized_parallel`, body, and `__kmpc_end_serialized_parallel`. However, this "optimization" doesn't consider the case where `num_threads` is used such that `__kmpc_push_num_threads` is still emitted. Since we don't reset the value in `__kmpc_serialized_parallel`, it will affect the next parallel region followed by it. Fix #63197. Reviewed By: tlwilmar Differential Revision: https://reviews.llvm.org/D152883
Diffstat (limited to 'openmp/runtime/src')
-rw-r--r--openmp/runtime/src/kmp_runtime.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 54d2805..03956ac 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -1153,6 +1153,9 @@ void __kmp_serialized_parallel(ident_t *loc, kmp_int32 global_tid) {
// 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);