[Openmp-commits] [openmp] r305306 - Reset initial affinity in children processes
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jun 13 10:16:13 PDT 2017
Author: jlpeyton
Date: Tue Jun 13 12:16:12 2017
New Revision: 305306
URL: http://llvm.org/viewvc/llvm-project?rev=305306&view=rev
Log:
Reset initial affinity in children processes
If OpenMP is initialized before fork()-ing occurs and affinity is set to
something like compact, then the master thread will be pinned to a single HW
thread/core after initialization. If the master (or any other thread) then
forks N processes, all N processes will then be pinned to that same single HW
thread/core. To reset the affinity for the new child process, the atfork
handler for the child process can call kmp_set_thread_affinity_mask_initial()
to reset its affinity to the initial affinity of the application before it
re-initializes libomp. The parent process will not be affected and still
keeps its affinity setting.
Differential Revision: https://reviews.llvm.org/D34118
Modified:
openmp/trunk/runtime/src/kmp.h
openmp/trunk/runtime/src/z_Linux_util.cpp
Modified: openmp/trunk/runtime/src/kmp.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp.h?rev=305306&r1=305305&r2=305306&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp.h (original)
+++ openmp/trunk/runtime/src/kmp.h Tue Jun 13 12:16:12 2017
@@ -3268,6 +3268,9 @@ extern int __kmp_aux_set_affinity_mask_p
extern int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask);
extern int __kmp_aux_get_affinity_mask_proc(int proc, void **mask);
extern void __kmp_balanced_affinity(int tid, int team_size);
+#if KMP_OS_LINUX
+extern int kmp_set_thread_affinity_mask_initial(void);
+#endif
#endif /* KMP_AFFINITY_SUPPORTED */
extern void __kmp_cleanup_hierarchy();
Modified: openmp/trunk/runtime/src/z_Linux_util.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/z_Linux_util.cpp?rev=305306&r1=305305&r2=305306&view=diff
==============================================================================
--- openmp/trunk/runtime/src/z_Linux_util.cpp (original)
+++ openmp/trunk/runtime/src/z_Linux_util.cpp Tue Jun 13 12:16:12 2017
@@ -1280,6 +1280,12 @@ static void __kmp_atfork_child(void) {
++__kmp_fork_count;
+#if KMP_AFFINITY_SUPPORTED && KMP_OS_LINUX
+ // reset the affinity in the child to the initial thread
+ // affinity in the parent
+ kmp_set_thread_affinity_mask_initial();
+#endif
+
__kmp_init_runtime = FALSE;
#if KMP_USE_MONITOR
__kmp_init_monitor = 0;
More information about the Openmp-commits
mailing list