Merge branch 'release-2018' into master
[alexxy/gromacs.git] / src / programs / mdrun / runner.cpp
index a4d390e2039f1321e54c900f875480e5582cb587..b84e5e4df795607744998c2a28caa3f94c0f157d 100644 (file)
@@ -444,9 +444,9 @@ int Mdrunner::mdrunner()
 
     /* CAUTION: threads may be started later on in this function, so
        cr doesn't reflect the final parallel state right now */
-    gmx::MDModules mdModules;
-    t_inputrec     inputrecInstance;
-    t_inputrec    *inputrec = &inputrecInstance;
+    std::unique_ptr<gmx::MDModules> mdModules(new gmx::MDModules);
+    t_inputrec                      inputrecInstance;
+    t_inputrec                     *inputrec = &inputrecInstance;
     snew(mtop, 1);
 
     if (mdrunOptions.continuationOptions.appendFiles)
@@ -682,7 +682,7 @@ int Mdrunner::mdrunner()
     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
 
     // TODO: Error handling
-    mdModules.assignOptionsToModules(*inputrec->params, nullptr);
+    mdModules->assignOptionsToModules(*inputrec->params, nullptr);
 
     if (fplog != nullptr)
     {
@@ -1152,7 +1152,7 @@ int Mdrunner::mdrunner()
     {
         /* Initiate forcerecord */
         fr                 = mk_forcerec();
-        fr->forceProviders = mdModules.initForceProviders();
+        fr->forceProviders = mdModules->initForceProviders();
         init_forcerec(fplog, mdlog, fr, fcd,
                       inputrec, mtop, cr, box,
                       opt2fn("-table", nfile, fnm),
@@ -1325,7 +1325,7 @@ int Mdrunner::mdrunner()
                                      oenv,
                                      mdrunOptions,
                                      vsite, constr,
-                                     mdModules.outputProvider(),
+                                     mdModules->outputProvider(),
                                      inputrec, mtop,
                                      fcd,
                                      globalState.get(),
@@ -1378,6 +1378,7 @@ int Mdrunner::mdrunner()
     // As soon as we destroy GPU contexts after mdrunner() exits, these lines should go.
     mdAtoms.reset(nullptr);
     globalState.reset(nullptr);
+    mdModules.reset(nullptr);   // destruct force providers here as they might also use the GPU
 
     /* Free GPU memory and set a physical node tMPI barrier (which should eventually go away) */
     free_gpu_resources(fr, cr);