[Openmp-commits] [openmp] [OpenMP] Fix build with `LIBOMP_OMPT_OPTIONAL=OFF` (PR #235734)
Jan André Reuter via Openmp-commits
openmp-commits at lists.llvm.org
Mon Oct 26 04:46:02 PDT 2026
https://github.com/Thyre created https://github.com/llvm/llvm-project/pull/235734
Since #95602, `__kmp_barrier_template` and `__kmp_join_barrier` compute the barrier kind and wait state inside an `OMPT_OPTIONAL` block to provide tools with specific information about the encountered kind of barrier. However, both the kind and wait state are used in non-optional OpenMP builds as well. This breaks the build when OMPT support is enabled but optional OMPT support is disabled.
To fix this, move the computation out of the `OMPT_OPTIONAL` block, so it is guarded only by `OMPT_SUPPORT`. OpenMP 6.0 Section 33.31 requires an implementation to maintain an approximate thread state information for each thread while the OMPT interface is active. As such, updating the flag is not optional, unlike the `sync_region[_wait]` callbacks.
Fixes #234164
>From c08070bd3871fe912f57c4f49648d937d253ec1c Mon Sep 17 00:00:00 2001
From: Jan Andre Reuter <jan at zyten.de>
Date: Mon, 26 Oct 2026 12:18:47 +0100
Subject: [PATCH] [OpenMP] Fix build with `LIBOMP_OMPT_OPTIONAL=OFF`
Since #95602, `__kmp_barrier_template` and `__kmp_join_barrier` compute
the barrier kind and wait state inside an `OMPT_OPTIONAL` block to
provide tools with specific information about the encountered kind of
barrier. However, both the kind and wait state are used in non-optional
OpenMP builds as well. This breaks the build when OMPT support is
enabled but optional OMPT support is disabled.
To fix this, move the computation out of the `OMPT_OPTIONAL` block, so
it is guarded only by `OMPT_SUPPORT`. OpenMP 6.0 Section 33.31 requires
an implementation to maintain an approximate thread state information
for each thread while the OMPT interface is active. As such, updating
the flag is not optional, unlike the `sync_region[_wait]` callbacks.
Fixes #234164
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
Signed-off-by: Jan Andre Reuter <jan at zyten.de>
---
openmp/runtime/src/kmp_barrier.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/openmp/runtime/src/kmp_barrier.cpp b/openmp/runtime/src/kmp_barrier.cpp
index f80f2e180fb611..dfcdb6abf22a41 100644
--- a/openmp/runtime/src/kmp_barrier.cpp
+++ b/openmp/runtime/src/kmp_barrier.cpp
@@ -1828,11 +1828,13 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
kmp_team_t *team = this_thr->th.th_team;
int status = 0;
is_cancellable<cancellable> cancelled;
-#if OMPT_SUPPORT && OMPT_OPTIONAL
+#if OMPT_SUPPORT
+ ompt_sync_region_t barrier_kind;
+#if OMPT_OPTIONAL
ompt_data_t *my_task_data;
ompt_data_t *my_parallel_data;
void *return_address;
- ompt_sync_region_t barrier_kind;
+#endif
#endif
KA_TRACE(15, ("__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
@@ -1840,11 +1842,11 @@ static int __kmp_barrier_template(enum barrier_type bt, int gtid, int is_split,
#if OMPT_SUPPORT
if (ompt_enabled.enabled) {
+ barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
#if OMPT_OPTIONAL
my_task_data = OMPT_CUR_TASK_DATA(this_thr);
my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
- barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
if (ompt_enabled.ompt_callback_sync_region) {
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
@@ -2278,6 +2280,9 @@ void __kmp_join_barrier(int gtid) {
#if OMPT_SUPPORT
if (ompt_enabled.enabled) {
+ ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
+ if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
+ ompt_state = ompt_state_wait_barrier_teams;
#if OMPT_OPTIONAL
ompt_data_t *my_task_data;
ompt_data_t *my_parallel_data;
@@ -2290,11 +2295,8 @@ void __kmp_join_barrier(int gtid) {
my_task_data = OMPT_CUR_TASK_DATA(this_thr);
my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
- ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
- if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league) {
+ if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
sync_kind = ompt_sync_region_barrier_teams;
- ompt_state = ompt_state_wait_barrier_teams;
- }
if (ompt_enabled.ompt_callback_sync_region) {
ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
More information about the Openmp-commits
mailing list