Use only HardwareTopology for thread affinity
authorTeemu Murtola <teemu.murtola@gmail.com>
Fri, 13 May 2016 14:57:38 +0000 (17:57 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 May 2016 14:45:50 +0000 (16:45 +0200)
Pass only HardwareTopology to thread affinity setting code, instead of
full gmx_hw_info_t.  This reduces coupling, removes some uses of
nthreads_hw_avail, and makes things simpler to test.

Change-Id: I04c8233dddb26cef0ee385c9249ba2aab5ac01b4

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

index 39e1abbdb8f750ada458eff30feafad290717ca5..442bd9235d3c24e0c41c3de026bccd58a4d76184 100644 (file)
@@ -85,7 +85,7 @@ static bool invalidWithinSimulation(const t_commrec *cr, bool invalidLocally)
 static bool
 get_thread_affinity_layout(FILE *fplog,
                            const t_commrec *cr,
-                           const gmx_hw_info_t * hwinfo,
+                           const gmx::HardwareTopology &hwTop,
                            int   threads,
                            bool  automatic,
                            int pin_offset, int * pin_stride,
@@ -97,8 +97,6 @@ get_thread_affinity_layout(FILE *fplog,
     bool                         haveTopology;
     bool                         invalidValue;
 
-    const gmx::HardwareTopology &hwTop = *hwinfo->hardwareTopology;
-
     haveTopology = (hwTop.supportLevel() >= gmx::HardwareTopology::SupportLevel::Basic);
 
     if (pin_offset < 0)
@@ -131,7 +129,7 @@ get_thread_affinity_layout(FILE *fplog,
     else
     {
         /* topology information not available or invalid, ignore it */
-        hwThreads       = hwinfo->nthreads_hw_avail;
+        hwThreads       = hwTop.machine().logicalProcessorCount;
         *localityOrder  = NULL;
     }
     // Only warn about the first problem per node.  Otherwise, the first test
@@ -332,10 +330,10 @@ static bool set_affinity(const t_commrec *cr, int nthread_local, int thread0_id_
    if only PME is using threads.
  */
 void
-gmx_set_thread_affinity(FILE                *fplog,
-                        const t_commrec     *cr,
-                        const gmx_hw_opt_t  *hw_opt,
-                        const gmx_hw_info_t *hwinfo)
+gmx_set_thread_affinity(FILE                        *fplog,
+                        const t_commrec             *cr,
+                        const gmx_hw_opt_t          *hw_opt,
+                        const gmx::HardwareTopology &hwTop)
 {
     int        thread0_id_node,
                nthread_local, nthread_node;
@@ -404,7 +402,7 @@ gmx_set_thread_affinity(FILE                *fplog,
 
     bool automatic = (hw_opt->thread_affinity == threadaffAUTO);
     bool validLayout
-        = get_thread_affinity_layout(fplog, cr, hwinfo, nthread_node, automatic,
+        = get_thread_affinity_layout(fplog, cr, hwTop, nthread_node, automatic,
                                      offset, &core_pinning_stride, &localityOrder);
     gmx::scoped_guard_sfree localityOrderGuard(localityOrder);
 
index 8ca8854bf2d35f08c4b5e939a3cc2e98d0394c7b..c96ea5be0ab03351ce07496bef983bf8d13f508b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include <cstdio>
 
-#include "gromacs/hardware/hw_info.h"
 #include "gromacs/utility/basedefinitions.h"
 
+struct gmx_hw_opt_t;
 struct t_commrec;
 
+namespace gmx
+{
+class HardwareTopology;
+}
+
 /*! \brief
  * Sets the thread affinity using the requested setting stored in hw_opt.
- *
- * The hardware topology is requested from hwinfo, when present.
  */
 void
-gmx_set_thread_affinity(FILE                *fplog,
-                        const t_commrec     *cr,
-                        const gmx_hw_opt_t  *hw_opt,
-                        const gmx_hw_info_t *hwinfo);
+gmx_set_thread_affinity(FILE                        *fplog,
+                        const t_commrec             *cr,
+                        const gmx_hw_opt_t          *hw_opt,
+                        const gmx::HardwareTopology &hwTop);
 
 /*! \brief
  * Checks the process affinity mask and if it is found to be non-zero,
index 3294776ff121cf4b9ee740de07be997e6636fe2d..dbb6977776efe04e72b164291d50e4e0c69acf61 100644 (file)
@@ -1229,7 +1229,7 @@ int mdrunner(gmx_hw_opt_t *hw_opt,
                                       hw_opt, hwinfo->nthreads_hw_avail, TRUE);
 
         /* Set the CPU affinity */
-        gmx_set_thread_affinity(fplog, cr, hw_opt, hwinfo);
+        gmx_set_thread_affinity(fplog, cr, hw_opt, *hwinfo->hardwareTopology);
     }
 
     /* Initiate PME if necessary,