Misceleneous improvements to the Leap Frog tests
authorArtem Zhmurov <zhmurov@gmail.com>
Tue, 13 Aug 2019 14:59:11 +0000 (16:59 +0200)
committerArtem Zhmurov <zhmurov@gmail.com>
Sun, 25 Aug 2019 09:03:08 +0000 (11:03 +0200)
1. The contained with runnerss is made static so it will be
   initialized only once for the test case.
2. The member initializer is now only use constructor arguments,
   and hence does not impose requirements on the class fields
   ordering.
3. mdAtoms_.cFREEZE is set to nullptr explicetely, to make the
   code less sesitive to possible further changes in intialization
   of t_mdatoms.

Change-Id: I6e1db5cb3d5d81028480457989ce2e2b387018f4

src/gromacs/mdlib/tests/leapfrog.cpp
src/gromacs/mdlib/tests/leapfrogtestdata.cpp

index 7b88419c19e2aba7d042ae03dc91b1aaf10ba713..525ea949a7dbbc197c477412a24a075a928dd399 100644 (file)
@@ -125,8 +125,8 @@ class LeapFrogTest : public ::testing::TestWithParam<LeapFrogTestParameters>
 {
     public:
         //! Availiable runners (CPU and GPU versions of the Leap-Frog)
-        std::unordered_map <std::string, void(*)(LeapFrogTestData *testData,
-                                                 const int         numSteps)> runners_;
+        static std::unordered_map <std::string, void(*)(LeapFrogTestData *testData,
+                                                        const int         numSteps)> s_runners_;
         //! Reference data
         TestReferenceData                   refData_;
         //! Checker for reference data
@@ -134,14 +134,19 @@ class LeapFrogTest : public ::testing::TestWithParam<LeapFrogTestParameters>
 
         LeapFrogTest() :
             checker_(refData_.rootChecker())
+        {
+        }
+
+        //! Setup the runners one for all parameters sets
+        static void SetUpTestCase()
         {
             //
             // All runners should be registered here under appropriate conditions
             //
-            runners_["LeapFrogSimple"]  = integrateLeapFrogSimple;
-            if (GMX_GPU == GMX_GPU_CUDA && s_hasCompatibleGpus)
+            s_runners_["LeapFrogSimple"]  = integrateLeapFrogSimple;
+            if (GMX_GPU == GMX_GPU_CUDA && canComputeOnGpu())
             {
-                runners_["LeapFrogGpu"] = integrateLeapFrogGpu;
+                s_runners_["LeapFrogGpu"] = integrateLeapFrogGpu;
             }
         }
 
@@ -205,22 +210,15 @@ class LeapFrogTest : public ::testing::TestWithParam<LeapFrogTestParameters>
                 vRef.checkReal(v[ZZ], "ZZ");
             }
         }
-
-        //! Store whether any compatible GPUs exist.
-        static bool s_hasCompatibleGpus;
-        //! Before any test is run, work out whether any compatible GPUs exist.
-        static void SetUpTestCase()
-        {
-            s_hasCompatibleGpus = canComputeOnGpu();
-        }
 };
 
-bool LeapFrogTest::s_hasCompatibleGpus = false;
+std::unordered_map <std::string, void(*)(LeapFrogTestData *testData,
+                                         const int         numSteps)> LeapFrogTest::s_runners_;
 
 TEST_P(LeapFrogTest, SimpleIntegration)
 {
     // Cycle through all available runners
-    for (const auto &runner : runners_)
+    for (const auto &runner : s_runners_)
     {
         std::string            runnerName = runner.first;
 
index 38ae157c642c15c0b593118fe8c8566e9be34d73..caeaa64b592e5aba8b76500e0e2343a63b5d575b 100644 (file)
@@ -70,14 +70,14 @@ namespace test
 LeapFrogTestData::LeapFrogTestData(int numAtoms, real timestep, const rvec v0, const rvec f0) :
     numAtoms_(numAtoms),
     timestep_(timestep),
-    x0_(numAtoms_),
-    x_(numAtoms_),
-    xPrime_(numAtoms_),
-    v0_(numAtoms_),
-    v_(numAtoms_),
-    f_(numAtoms_),
-    inverseMasses_(numAtoms_),
-    inverseMassesPerDim_(numAtoms_)
+    x0_(numAtoms),
+    x_(numAtoms),
+    xPrime_(numAtoms),
+    v0_(numAtoms),
+    v_(numAtoms),
+    f_(numAtoms),
+    inverseMasses_(numAtoms),
+    inverseMassesPerDim_(numAtoms)
 {
     mdAtoms_.nr = numAtoms_;
 
@@ -143,6 +143,7 @@ LeapFrogTestData::LeapFrogTestData(int numAtoms, real timestep, const rvec v0, c
     mdAtoms_.homenr                   = numAtoms_;
     mdAtoms_.haveVsites               = false;
     mdAtoms_.havePartiallyFrozenAtoms = false;
+    mdAtoms_.cFREEZE                  = nullptr;
     snew(mdAtoms_.cTC, numAtoms_);
     for (int i = 0; i < numAtoms_; i++)
     {