From 51d71f488f5eea0b1e7b10f3b268a1688e8c9249 Mon Sep 17 00:00:00 2001 From: "M. Eric Irrgang" Date: Mon, 22 Jun 2020 16:27:52 +0300 Subject: [PATCH] SimulatorBuilder.add() for StopHandlerBuilder. Refs #3567 --- src/gromacs/mdrun/runner.cpp | 4 +- src/gromacs/mdrun/simulatorbuilder.cpp | 12 +++-- src/gromacs/mdrun/simulatorbuilder.h | 87 ++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 5a2e7a97fa..1378888adf 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1641,6 +1641,8 @@ int Mdrunner::mdrunner() GMX_ASSERT(stopHandlerBuilder_, "Runner must provide StopHandlerBuilder to simulator."); SimulatorBuilder simulatorBuilder; + simulatorBuilder.add(std::move(stopHandlerBuilder_)); + // build and run simulator object based on user-input auto simulator = simulatorBuilder.build( useModularSimulator, fplog, cr, ms, mdlog, static_cast(filenames.size()), @@ -1649,7 +1651,7 @@ int Mdrunner::mdrunner() 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, std::move(stopHandlerBuilder_), doRerun); + walltime_accounting, doRerun); simulator->run(); if (fr->pmePpCommGpu) diff --git a/src/gromacs/mdrun/simulatorbuilder.cpp b/src/gromacs/mdrun/simulatorbuilder.cpp index 0013091df0..7f52cc1329 100644 --- a/src/gromacs/mdrun/simulatorbuilder.cpp +++ b/src/gromacs/mdrun/simulatorbuilder.cpp @@ -89,9 +89,13 @@ std::unique_ptr SimulatorBuilder::build(bool use const ReplicaExchangeParameters& replExParams, gmx_membed_t* membed, gmx_walltime_accounting* walltime_accounting, - std::unique_ptr stopHandlerBuilder, - bool doRerun) + bool doRerun) { + if (!stopHandlerBuilder_) + { + throw APIError("You must add a StopHandlerBuilder before calling build()."); + } + if (useModularSimulator) { // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor @@ -100,7 +104,7 @@ std::unique_ptr SimulatorBuilder::build(bool use 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)); + walltime_accounting, std::move(stopHandlerBuilder_), doRerun)); } // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor return std::unique_ptr(new LegacySimulator( @@ -108,7 +112,7 @@ std::unique_ptr SimulatorBuilder::build(bool use 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)); + std::move(stopHandlerBuilder_), doRerun)); } } // namespace gmx diff --git a/src/gromacs/mdrun/simulatorbuilder.h b/src/gromacs/mdrun/simulatorbuilder.h index 1e51550ddb..6a12a36957 100644 --- a/src/gromacs/mdrun/simulatorbuilder.h +++ b/src/gromacs/mdrun/simulatorbuilder.h @@ -86,58 +86,65 @@ struct MdrunOptions; * \brief Class preparing the creation of Simulator objects * * Objects of this class build Simulator objects, which in turn are used to - * run molecular simulations. Currently, this only has a single public - * `build` function which takes all arguments needed to build the - * `LegacySimulator`. + * run molecular simulations. */ class SimulatorBuilder { public: + void add(std::unique_ptr stopHandlerBuilder) + { + stopHandlerBuilder_ = std::move(stopHandlerBuilder); + } + /*! \brief Build a Simulator object based on input data * * Return a pointer to a simulation object. The use of a parameter * pack insulates the builder from changes to the arguments of the * Simulator objects. * - * @return Unique pointer to a Simulator object + * \throws gmx::APIError if expected set-up methods have not been called before build() + * + * \return Unique pointer to a Simulator object */ - std::unique_ptr 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, - t_nrnb* nrnb, - gmx_wallcycle* wcycle, - t_forcerec* fr, - gmx_enerdata_t* enerd, - gmx_ekindata_t* ekind, - MdrunScheduleWorkload* runScheduleWork, - const ReplicaExchangeParameters& replExParams, - gmx_membed_t* membed, - gmx_walltime_accounting* walltime_accounting, - std::unique_ptr stopHandlerBuilder, - bool doRerun); -}; + std::unique_ptr 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, + t_nrnb* nrnb, + gmx_wallcycle* wcycle, + t_forcerec* fr, + gmx_enerdata_t* enerd, + gmx_ekindata_t* ekind, + MdrunScheduleWorkload* runScheduleWork, + const ReplicaExchangeParameters& replExParams, + gmx_membed_t* membed, + gmx_walltime_accounting* walltime_accounting, + bool doRerun); + +private: + std::unique_ptr stopHandlerBuilder_; +}; } // namespace gmx #endif // GMX_MDRUN_SIMULATORBUILDER_SIMULATORBUILDER_H -- 2.11.4.GIT