Skip to content

Commit 0160d81

Browse files
HighW4y2H3llMatzeB
andauthored
[OpenMP] Rename worker threads for improved debuggability (#102065)
Rename the worker threads "openmp_worker" --------- Co-authored-by: h2h <[email protected]> Co-authored-by: Matthias Braun <[email protected]>
1 parent 13cc94e commit 0160d81

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

openmp/runtime/cmake/LibompDefinitions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function(libomp_get_definitions_flags cppflags)
2323
else()
2424
libomp_append(cppflags_local "-D _GNU_SOURCE")
2525
libomp_append(cppflags_local "-D _REENTRANT")
26+
# or use HAVE_PTHREAD_SETNAME_NP from top-level cmake/config-ix.cmake
27+
libomp_append(cppflags_local "-D LIBOMP_HAVE_LINUX_PTHREAD_SETNAME" LIBOMP_HAVE_LINUX_PTHREAD_SETNAME)
2628
endif()
2729

2830
# CMake doesn't include CPPFLAGS from environment, but we will.

openmp/runtime/cmake/config-ix.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ if(${LIBOMP_FORTRAN_MODULES})
101101
libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
102102
endif()
103103

104+
# Check non-posix pthread API here before CMAKE_REQUIRED_DEFINITIONS gets messed up
105+
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
106+
check_symbol_exists(pthread_setname_np "pthread.h" LIBOMP_HAVE_LINUX_PTHREAD_SETNAME)
107+
endif()
108+
104109
# Check for Unix shared memory
105110
check_symbol_exists(shm_open "sys/mman.h" LIBOMP_HAVE_SHM_OPEN_NO_LRT)
106111
if (NOT LIBOMP_HAVE_SHM_OPEN_NO_LRT)

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,13 @@ void __kmp_create_worker(int gtid, kmp_info_t *th, size_t stack_size) {
878878
KMP_SYSFAIL("pthread_create", status);
879879
}
880880

881+
#ifdef LIBOMP_HAVE_LINUX_PTHREAD_SETNAME
882+
// Rename worker threads for improved debuggability
883+
if (!KMP_UBER_GTID(gtid)) {
884+
pthread_setname_np(handle, "openmp_worker");
885+
}
886+
#endif
887+
881888
th->th.th_info.ds.ds_thread = handle;
882889

883890
#ifdef KMP_THREAD_ATTR

0 commit comments

Comments
 (0)