Add MembedHolder for SimulatorBuilder.
authorejjordan <ejjordan@kth.se>
Tue, 21 Apr 2020 14:23:38 +0000 (17:23 +0300)
committerJoe Jordan <ejjordan12@gmail.com>
Fri, 26 Jun 2020 10:54:08 +0000 (10:54 +0000)
Implement SimulatorBuilder.add(MembedHolder&&)

Refs #3567

src/gromacs/mdrun/runner.cpp
src/gromacs/mdrun/simulatorbuilder.cpp
src/gromacs/mdrun/simulatorbuilder.h

index 1378888adfe2c18b97149725caea18e3b38c47dc..ceaa1b3c68daac840d1cdcdd807238280a8706ae 100644 (file)
@@ -1641,6 +1641,7 @@ int Mdrunner::mdrunner()
         GMX_ASSERT(stopHandlerBuilder_, "Runner must provide StopHandlerBuilder to simulator.");
         SimulatorBuilder simulatorBuilder;
 
+        simulatorBuilder.add(MembedHolder(membed));
         simulatorBuilder.add(std::move(stopHandlerBuilder_));
 
         // build and run simulator object based on user-input
@@ -1648,10 +1649,9 @@ int Mdrunner::mdrunner()
                 useModularSimulator, fplog, cr, ms, mdlog, static_cast<int>(filenames.size()),
                 filenames.data(), oenv, mdrunOptions, startingBehavior, vsite.get(), constr.get(),
                 enforcedRotation ? enforcedRotation->getLegacyEnfrot() : nullptr, deform.get(),
-                mdModules_->outputProvider(), mdModules_->notifier(), inputrec, imdSession.get(),
-                pull_work, swap, &mtop, globalState.get(), &observablesHistory, mdAtoms.get(),
-                &nrnb, wcycle, fr, &enerd, &ekind, &runScheduleWork, replExParams, membed,
-                walltime_accounting, doRerun);
+                mdModules_->outputProvider(), mdModules_->notifier(), inputrec, imdSession.get(), pull_work,
+                swap, &mtop, globalState.get(), &observablesHistory, mdAtoms.get(), &nrnb, wcycle,
+                fr, &enerd, &ekind, &runScheduleWork, replExParams, walltime_accounting, doRerun);
         simulator->run();
 
         if (fr->pmePpCommGpu)
index 7f52cc13295e6eca99ab90299861e43713036a31..e3078f864203aee0d5c475e278163f25a594af37 100644 (file)
@@ -87,7 +87,6 @@ std::unique_ptr<ISimulator> SimulatorBuilder::build(bool                     use
                                                     gmx_ekindata_t*          ekind,
                                                     MdrunScheduleWorkload*   runScheduleWork,
                                                     const ReplicaExchangeParameters& replExParams,
-                                                    gmx_membed_t*                    membed,
                                                     gmx_walltime_accounting* walltime_accounting,
                                                     bool                     doRerun)
 {
@@ -95,15 +94,19 @@ std::unique_ptr<ISimulator> SimulatorBuilder::build(bool                     use
     {
         throw APIError("You must add a StopHandlerBuilder before calling build().");
     }
+    if (!membedHolder_)
+    {
+        throw APIError("You must add a MembedHolder before calling build().");
+    }
 
     if (useModularSimulator)
     {
         // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
         return std::unique_ptr<ModularSimulator>(new ModularSimulator(
-                fplog, cr, ms, mdlog, nfile, fnm, oenv, mdrunOptions, startingBehavior, vsite,
-                constr, enforcedRotation, deform, outputProvider, mdModulesNotifier, inputrec,
-                imdSession, pull_work, swap, top_global, state_global, observablesHistory, mdAtoms,
-                nrnb, wcycle, fr, enerd, ekind, runScheduleWork, replExParams, membed,
+                fplog, cr, ms, mdlog, nfile, fnm, oenv, mdrunOptions, startingBehavior, vsite, constr,
+                enforcedRotation, deform, outputProvider, mdModulesNotifier, inputrec, imdSession,
+                pull_work, swap, top_global, state_global, observablesHistory, mdAtoms, nrnb,
+                wcycle, fr, enerd, ekind, runScheduleWork, replExParams, membedHolder_->membed(),
                 walltime_accounting, std::move(stopHandlerBuilder_), doRerun));
     }
     // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
@@ -111,8 +114,8 @@ std::unique_ptr<ISimulator> SimulatorBuilder::build(bool                     use
             fplog, cr, ms, mdlog, nfile, fnm, oenv, mdrunOptions, startingBehavior, vsite, constr,
             enforcedRotation, deform, outputProvider, mdModulesNotifier, inputrec, imdSession,
             pull_work, swap, top_global, state_global, observablesHistory, mdAtoms, nrnb, wcycle,
-            fr, enerd, ekind, runScheduleWork, replExParams, membed, walltime_accounting,
-            std::move(stopHandlerBuilder_), doRerun));
+            fr, enerd, ekind, runScheduleWork, replExParams, membedHolder_->membed(),
+            walltime_accounting, std::move(stopHandlerBuilder_), doRerun));
 }
 
 } // namespace gmx
index 6a12a3695719cdff68f6e9de84be38bbd7775124..d39a561861f0a11625cacc371adf8ae787ee14e8 100644 (file)
@@ -54,7 +54,6 @@ struct gmx_mtop_t;
 struct gmx_membed_t;
 struct gmx_multisim_t;
 struct gmx_output_env_t;
-struct gmx_vsite_t;
 struct gmx_wallcycle;
 struct gmx_walltime_accounting;
 struct ObservablesHistory;
@@ -82,6 +81,24 @@ class ISimulator;
 class StopHandlerBuilder;
 struct MdrunOptions;
 
+/*! \brief Membed SimulatorBuilder parameter type.
+ *
+ * Does not (yet) encapsulate ownership semantics of resources. Simulator is
+ * not (necessarily) granted ownership of resources. Client is responsible for
+ * maintaining the validity of resources for the life time of the Simulator,
+ * then for cleaning up those resources.
+ */
+class MembedHolder
+{
+public:
+    explicit MembedHolder(gmx_membed_t* membed) : membed_(membed) {}
+
+    gmx_membed_t* membed() { return membed_; }
+
+private:
+    gmx_membed_t* membed_;
+};
+
 /*! \libinternal
  * \brief Class preparing the creation of Simulator objects
  *
@@ -91,6 +108,11 @@ struct MdrunOptions;
 class SimulatorBuilder
 {
 public:
+    void add(MembedHolder&& membedHolder)
+    {
+        membedHolder_ = std::make_unique<MembedHolder>(membedHolder);
+    }
+
     void add(std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder)
     {
         stopHandlerBuilder_ = std::move(stopHandlerBuilder);
@@ -106,28 +128,27 @@ public:
      *
      * \return  Unique pointer to a Simulator object
      */
-    std::unique_ptr<ISimulator> build(bool                     useModularSimulator,
-                                      FILE*                    fplog,
-                                      t_commrec*               cr,
-                                      const gmx_multisim_t*    ms,
-                                      const MDLogger&          mdlog,
-                                      int                      nfile,
-                                      const t_filenm*          fnm,
-                                      const gmx_output_env_t*  oenv,
-                                      const MdrunOptions&      mdrunOptions,
-                                      StartingBehavior         startingBehavior,
-                                      VirtualSitesHandler*     vsite,
-                                      Constraints*             constr,
-                                      gmx_enfrot*              enforcedRotation,
-                                      BoxDeformation*          deform,
-                                      IMDOutputProvider*       outputProvider,
-                                      const MdModulesNotifier& mdModulesNotifier,
-                                      t_inputrec*              inputrec,
-                                      ImdSession*              imdSession,
-                                      pull_t*                  pull_work,
-                                      t_swap*                  swap,
-                                      gmx_mtop_t*              top_global,
-
+    std::unique_ptr<ISimulator> build(bool                             useModularSimulator,
+                                      FILE*                            fplog,
+                                      t_commrec*                       cr,
+                                      const gmx_multisim_t*            ms,
+                                      const MDLogger&                  mdlog,
+                                      int                              nfile,
+                                      const t_filenm*                  fnm,
+                                      const gmx_output_env_t*          oenv,
+                                      const MdrunOptions&              mdrunOptions,
+                                      StartingBehavior                 startingBehavior,
+                                      VirtualSitesHandler*             vsite,
+                                      Constraints*                     constr,
+                                      gmx_enfrot*                      enforcedRotation,
+                                      BoxDeformation*                  deform,
+                                      IMDOutputProvider*               outputProvider,
+                                      const MdModulesNotifier&         mdModulesNotifier,
+                                      t_inputrec*                      inputrec,
+                                      ImdSession*                      imdSession,
+                                      pull_t*                          pull_work,
+                                      t_swap*                          swap,
+                                      gmx_mtop_t*                      top_global,
                                       t_state*                         state_global,
                                       ObservablesHistory*              observablesHistory,
                                       MDAtoms*                         mdAtoms,
@@ -138,13 +159,14 @@ public:
                                       gmx_ekindata_t*                  ekind,
                                       MdrunScheduleWorkload*           runScheduleWork,
                                       const ReplicaExchangeParameters& replExParams,
-                                      gmx_membed_t*                    membed,
                                       gmx_walltime_accounting*         walltime_accounting,
                                       bool                             doRerun);
 
 private:
+    std::unique_ptr<MembedHolder>       membedHolder_;
     std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder_;
 };
+
 } // namespace gmx
 
 #endif // GMX_MDRUN_SIMULATORBUILDER_SIMULATORBUILDER_H