Pass number of local threads to thread affinity
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 14 May 2016 04:13:13 +0000 (07:13 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 May 2016 17:09:05 +0000 (20:09 +0300)
This removes some mdrun-specific logic from threadaffinity.cpp and makes
it independent of gmx_omp_nthreads, reducing coupling.  It also
simplifies unit testing.

Change-Id: Id881a7fabbe7fb48bd187d3d903aea08e418d1c2

src/gromacs/mdrunutility/threadaffinity.cpp
src/gromacs/mdrunutility/threadaffinity.h
src/programs/mdrun/runner.cpp

index 442bd9235d3c24e0c41c3de026bccd58a4d76184..db3da28fbe4200cb966ac103561faedc8f8fa88c 100644 (file)
@@ -52,7 +52,6 @@
 #include "gromacs/gmxlib/md_logging.h"
 #include "gromacs/hardware/hardwaretopology.h"
 #include "gromacs/hardware/hw_info.h"
-#include "gromacs/mdlib/gmx_omp_nthreads.h"
 #include "gromacs/mdtypes/commrec.h"
 #include "gromacs/utility/basenetwork.h"
 #include "gromacs/utility/cstringutil.h"
@@ -333,10 +332,10 @@ void
 gmx_set_thread_affinity(FILE                        *fplog,
                         const t_commrec             *cr,
                         const gmx_hw_opt_t          *hw_opt,
-                        const gmx::HardwareTopology &hwTop)
+                        const gmx::HardwareTopology &hwTop,
+                        int                          nthread_local)
 {
-    int        thread0_id_node,
-               nthread_local, nthread_node;
+    int        thread0_id_node, nthread_node;
     int *      localityOrder = nullptr;
 
     if (hw_opt->thread_affinity == threadaffOFF)
@@ -360,16 +359,6 @@ gmx_set_thread_affinity(FILE                        *fplog,
         return;
     }
 
-    /* threads on this MPI process or TMPI thread */
-    if (cr->duty & DUTY_PP)
-    {
-        nthread_local = gmx_omp_nthreads_get(emntNonbonded);
-    }
-    else
-    {
-        nthread_local = gmx_omp_nthreads_get(emntPME);
-    }
-
     /* map the current process to cores */
     thread0_id_node = 0;
     nthread_node    = nthread_local;
index c96ea5be0ab03351ce07496bef983bf8d13f508b..72f4270090305e23687302ee3254b8e05481224d 100644 (file)
@@ -61,7 +61,8 @@ void
 gmx_set_thread_affinity(FILE                        *fplog,
                         const t_commrec             *cr,
                         const gmx_hw_opt_t          *hw_opt,
-                        const gmx::HardwareTopology &hwTop);
+                        const gmx::HardwareTopology &hwTop,
+                        int                          nthread_local);
 
 /*! \brief
  * Checks the process affinity mask and if it is found to be non-zero,
index dbb6977776efe04e72b164291d50e4e0c69acf61..2e7f7f0201ec3abfce474e4f490700ec88d34ccc 100644 (file)
@@ -1228,8 +1228,20 @@ int mdrunner(gmx_hw_opt_t *hw_opt,
         gmx_check_thread_affinity_set(fplog, cr,
                                       hw_opt, hwinfo->nthreads_hw_avail, TRUE);
 
+        int nthread_local;
+        /* threads on this MPI process or TMPI thread */
+        if (cr->duty & DUTY_PP)
+        {
+            nthread_local = gmx_omp_nthreads_get(emntNonbonded);
+        }
+        else
+        {
+            nthread_local = gmx_omp_nthreads_get(emntPME);
+        }
+
         /* Set the CPU affinity */
-        gmx_set_thread_affinity(fplog, cr, hw_opt, *hwinfo->hardwareTopology);
+        gmx_set_thread_affinity(fplog, cr, hw_opt, *hwinfo->hardwareTopology,
+                                nthread_local);
     }
 
     /* Initiate PME if necessary,