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


git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@305513 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/runtime/src/z_Linux_util.cpp b/runtime/src/z_Linux_util.cpp
index a0d1639..914275a 100644
--- a/runtime/src/z_Linux_util.cpp
+++ b/runtime/src/z_Linux_util.cpp
@@ -1280,11 +1280,22 @@
 
   ++__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