aboutsummaryrefslogtreecommitdiff
path: root/openmp
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2017-06-15 21:51:07 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2017-06-15 21:51:07 +0000
commit072ccb72396a1b8143ecfe8214e000c542916cc0 (patch)
treeb879405e206336519e1c55da21dcec40d126ee0d /openmp
parent383971d2a7d38607c042660218c4bf7a2443a655 (diff)
downloadllvm-072ccb72396a1b8143ecfe8214e000c542916cc0.zip
llvm-072ccb72396a1b8143ecfe8214e000c542916cc0.tar.gz
llvm-072ccb72396a1b8143ecfe8214e000c542916cc0.tar.bz2
Set affinity to none/false in child processes
Reset affinity to none (false for proc-bind-var) so that threads in the child processes are not bound tightly, unless the user explicitly sets this in KMP_AFFINITY/OMP_PROC_BIND, in child processes. This can improve performance for scripting languages which fork for parallelism like Python's multiprocessing module. Differential Revision: https://reviews.llvm.org/D34154 llvm-svn: 305513
Diffstat (limited to 'openmp')
-rw-r--r--openmp/runtime/src/z_Linux_util.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index a0d1639..914275a 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -1280,11 +1280,22 @@ static void __kmp_atfork_child(void) {
++__kmp_fork_count;
-#if KMP_AFFINITY_SUPPORTED && KMP_OS_LINUX
+#if KMP_AFFINITY_SUPPORTED
+#if KMP_OS_LINUX
// reset the affinity in the child to the initial thread
// affinity in the parent
kmp_set_thread_affinity_mask_initial();
#endif
+ // Set default not to bind threads tightly in the child (we’re expecting
+ // over-subscription after the fork and this can improve things for
+ // scripting languages that use OpenMP inside process-parallel code).
+ __kmp_affinity_type = affinity_none;
+#if OMP_40_ENABLED
+ if (__kmp_nested_proc_bind.bind_types != NULL) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+ }
+#endif // OMP_40_ENABLED
+#endif // KMP_AFFINITY_SUPPORTED
__kmp_init_runtime = FALSE;
#if KMP_USE_MONITOR