Merge branch release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / gmx_thread_affinity.c
index ce89e4130f6a251dc31b787c0b25134ced6e5976..5d1b3659ab361bc33fd0c9dcbb92eeefe339326e 100644 (file)
@@ -188,15 +188,8 @@ gmx_set_thread_affinity(FILE                *fplog,
     int        nth_affinity_set, thread_id_node, thread_id,
                nthread_local, nthread_node, nthread_hw_max, nphyscore;
     int        offset;
-    /* these are inherently global properties that are shared among all threads
-     */
-    static const int          *locality_order;
-    static int                 rc;
-    static gmx_bool            have_locality_order = FALSE;
-    static tMPI_Thread_mutex_t locality_order_mtx  =
-        TMPI_THREAD_MUTEX_INITIALIZER;
-    static tMPI_Thread_cond_t  locality_order_cond =
-        TMPI_THREAD_COND_INITIALIZER;
+    const int *locality_order;
+    int        rc;
 
     if (hw_opt->thread_affinity == threadaffOFF)
     {
@@ -217,7 +210,7 @@ gmx_set_thread_affinity(FILE                *fplog,
                       "Can not set thread affinities on the current platform. On NUMA systems this\n"
                       "can cause performance degradation. If you think your platform should support\n"
                       "setting affinities, contact the GROMACS developers.");
-#endif /* __APPLE__ */
+#endif  /* __APPLE__ */
         return;
     }
 
@@ -275,65 +268,10 @@ gmx_set_thread_affinity(FILE                *fplog,
         md_print_info(cr, fplog, "Applying core pinning offset %d\n", offset);
     }
 
-    /* hw_opt is shared among tMPI threads, so for thread safety we need to do
-     * the layout detection only on master as core_pinning_stride is an in-out
-     * parameter and gets auto-set depending on its initial value.
-     * This
-     * This is not thread-safe with multi-simulations, but that's anyway not
-     * supported by tMPI. */
-    if (SIMMASTER(cr))
-    {
-        int ret;
-        int i;
-
-        ret = tMPI_Thread_mutex_lock(&locality_order_mtx);
-        if (ret != 0)
-        {
-            goto locality_order_err;
-        }
-        rc = get_thread_affinity_layout(fplog, cr, hwinfo,
-                                        nthread_node,
-                                        offset, &hw_opt->core_pinning_stride,
-                                        &locality_order);
-        have_locality_order = TRUE;
-        ret                 = tMPI_Thread_cond_broadcast(&locality_order_cond);
-        if (ret != 0)
-        {
-            tMPI_Thread_mutex_unlock(&locality_order_mtx);
-            goto locality_order_err;
-        }
-        ret = tMPI_Thread_mutex_unlock(&locality_order_mtx);
-        if (ret != 0)
-        {
-            goto locality_order_err;
-        }
-    }
-    else
-    {
-        int ret;
-        /* all other threads wait for the locality order data. */
-        ret = tMPI_Thread_mutex_lock(&locality_order_mtx);
-        if (ret != 0)
-        {
-            goto locality_order_err;
-        }
-
-        while (!have_locality_order)
-        {
-            ret = tMPI_Thread_cond_wait(&locality_order_cond,
-                                        &locality_order_mtx);
-            if (ret != 0)
-            {
-                tMPI_Thread_mutex_unlock(&locality_order_mtx);
-                goto locality_order_err;
-            }
-        }
-        ret = tMPI_Thread_mutex_unlock(&locality_order_mtx);
-        if (ret != 0)
-        {
-            goto locality_order_err;
-        }
-    }
+    rc = get_thread_affinity_layout(fplog, cr, hwinfo,
+                                    nthread_node,
+                                    offset, &hw_opt->core_pinning_stride,
+                                    &locality_order);
 
     if (rc != 0)
     {
@@ -422,15 +360,6 @@ gmx_set_thread_affinity(FILE                *fplog,
         }
     }
     return;
-
-locality_order_err:
-    /* any error in affinity setting shouldn't be fatal, but should generate
-       a warning */
-    md_print_warn(NULL, fplog,
-                  "WARNING: Obtaining affinity information failed due to a basic system error: %s.\n"
-                  "         This can cause performance degradation! ",
-                  strerror(errno));
-    return;
 }
 
 /* Check the process affinity mask and if it is found to be non-zero,