Allow creating mock HardwareTopology objects
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 14 May 2016 04:06:59 +0000 (07:06 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 May 2016 15:17:11 +0000 (17:17 +0200)
Make it possible to create basic hardware topologies for testing,
instead of detecting the actual physical topology.

Change-Id: Icf6aef48ccd8543c941d00a2b6a01e2eb301cd1f

src/gromacs/hardware/hardwaretopology.cpp
src/gromacs/hardware/hardwaretopology.h

index ac7750138c1b6b6f6c3389f991569af3996db7ce..4501a86b3e9c5b3894232cd338dafc6a9b6ca7a5 100644 (file)
@@ -593,11 +593,7 @@ HardwareTopology HardwareTopology::detect()
 {
     HardwareTopology result;
 
-    // Default values for machine and numa stuff
-    result.machine_.logicalProcessorCount   = 0;
-    result.machine_.numa.baseLatency        = 0.0;
-    result.machine_.numa.maxRelativeLatency = 0.0;
-    result.supportLevel_                    = SupportLevel::None;
+    result.supportLevel_ = SupportLevel::None;
 
 #if GMX_HWLOC
     parseHwLoc(&result.machine_, &result.supportLevel_);
@@ -623,12 +619,29 @@ HardwareTopology HardwareTopology::detect()
     return result;
 }
 
+HardwareTopology::Machine::Machine()
+{
+    logicalProcessorCount   = 0;
+    numa.baseLatency        = 0.0;
+    numa.maxRelativeLatency = 0.0;
+}
+
 
 HardwareTopology::HardwareTopology()
     : supportLevel_(SupportLevel::None)
 {
 }
 
+HardwareTopology::HardwareTopology(int logicalProcessorCount)
+    : supportLevel_(SupportLevel::None)
+{
+    if (logicalProcessorCount > 0)
+    {
+        machine_.logicalProcessorCount = logicalProcessorCount;
+        supportLevel_                  = SupportLevel::LogicalProcessorCount;
+    }
+}
+
 int HardwareTopology::numberOfCores() const
 {
     if (supportLevel() >= SupportLevel::Basic)
index 590f8a7f3815333ed1245e86d12a93a619e36ad9..6432246adc18675832c4219c7305adfc8d152ffb 100644 (file)
@@ -177,6 +177,8 @@ class HardwareTopology
          */
         struct Machine
         {
+            Machine();
+
             int                            logicalProcessorCount; //!< Number of logical processors in system
             std::vector<LogicalProcessor>  logicalProcessors;     //!< Map logical processors to socket/core
             std::vector<Socket>            sockets;               //!< All the sockets in the system
@@ -191,6 +193,14 @@ class HardwareTopology
          */
         static HardwareTopology detect();
 
+        /*! \brief Creates a topology with given number of logical cores.
+         *
+         * The support level will be either None or LogicalProcessorCount.
+         *
+         * Intended for testing of code that uses the hardware topology.
+         */
+        explicit HardwareTopology(int logicalProcessorCount);
+
         /*! \brief Check what topology information that is available and valid
          *
          *  The amount of hardware topology information that can be detected depends