Clarify t_inputrec allocation logic in runner.cpp.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Thu, 27 Aug 2020 11:09:23 +0000 (14:09 +0300)
committerM. Eric Irrgang <ericirrgang@gmail.com>
Thu, 27 Aug 2020 11:09:47 +0000 (14:09 +0300)
Closes #3637

src/gromacs/mdrun/runner.cpp

index 28abfc24cc3615394e3bc4d2a2c8f3dad0bcc873..903d64f4322aca6115b5f8e84bfa2e09ec2b12ec 100644 (file)
@@ -769,6 +769,8 @@ int Mdrunner::mdrunner()
     // Print citation requests after all software/hardware printing
     pleaseCiteGromacs(fplog);
 
+    // Note: legacy program logic relies on checking whether these pointers are assigned.
+    // Objects may or may not be allocated later.
     std::unique_ptr<t_inputrec> inputrec;
     std::unique_ptr<t_state>    globalState;
 
@@ -776,10 +778,11 @@ int Mdrunner::mdrunner()
 
     if (isSimulationMasterRank)
     {
+        // Allocate objects to be initialized by later function calls.
         /* Only the master rank has the global state */
         globalState = std::make_unique<t_state>();
+        inputrec    = std::make_unique<t_inputrec>();
 
-        inputrec = std::make_unique<t_inputrec>();
         /* Read (nearly) all data required for the simulation
          * and keep the partly serialized tpr contents to send to other ranks later
          */
@@ -841,6 +844,8 @@ int Mdrunner::mdrunner()
         /* now broadcast everything to the non-master nodes/threads: */
         if (!isSimulationMasterRank)
         {
+            // Until now, only the master rank has a non-null pointer.
+            // On non-master ranks, allocate the object that will receive data in the following call.
             inputrec = std::make_unique<t_inputrec>();
         }
         init_parallel(cr->mpiDefaultCommunicator, MASTER(cr), inputrec.get(), &mtop,