[Openmp-commits] [openmp] r305513 - Set affinity to none/false in child processes

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Thu Jun 15 14:51:07 PDT 2017


Author: jlpeyton
Date: Thu Jun 15 16:51:07 2017
New Revision: 305513

URL: http://llvm.org/viewvc/llvm-project?rev=305513&view=rev
Log:
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

Modified:
    openmp/trunk/runtime/src/z_Linux_util.cpp

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=305513&r1=305512&r2=305513&view=diff
==============================================================================
--- openmp/trunk/runtime/src/z_Linux_util.cpp (original)
+++ openmp/trunk/runtime/src/z_Linux_util.cpp Thu Jun 15 16:51:07 2017
@@ -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




More information about the Openmp-commits mailing list