aboutsummaryrefslogtreecommitdiff
path: root/openmp
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2017-06-13 17:16:12 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2017-06-13 17:16:12 +0000
commitd330e630dbf0a29179b594a287d16cab77e5941d (patch)
tree61447a57f1d330cd8044e3a1fce8155cebd6debe /openmp
parentb3a8d20e27b41be00e1876c606d43c5794815e0b (diff)
downloadllvm-d330e630dbf0a29179b594a287d16cab77e5941d.zip
llvm-d330e630dbf0a29179b594a287d16cab77e5941d.tar.gz
llvm-d330e630dbf0a29179b594a287d16cab77e5941d.tar.bz2
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 llvm-svn: 305306
Diffstat (limited to 'openmp')
-rw-r--r--openmp/runtime/src/kmp.h3
-rw-r--r--openmp/runtime/src/z_Linux_util.cpp6
2 files changed, 9 insertions, 0 deletions
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index cab0d04..f2f0cdc 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -3268,6 +3268,9 @@ extern int __kmp_aux_set_affinity_mask_proc(int proc, void **mask);
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();
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index 2f83c02..a0d1639 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -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;