pull_work_(pull_work)
{
GMX_ASSERT(DOMAINDECOMP(cr), "Domain decomposition Helper constructed in non-DD simulation");
+ GMX_ASSERT(checkBondedInteractionsCallback_,
+ "Domain decomposition needs a callback to check the number of bonded "
+ "interactions.");
}
void DomDecHelper::setup()
SignallerBuilder<TrajectorySignaller>* trajectorySignallerBuilder,
TrajectoryElementBuilder* trajectoryElementBuilder,
std::vector<ICheckpointHelperClient*>* checkpointClients,
- CheckBondedInteractionsCallbackPtr* checkBondedInteractionsCallback,
compat::not_null<StatePropagatorData*> statePropagatorDataPtr,
compat::not_null<EnergyData*> energyDataPtr,
FreeEnergyPerturbationData* freeEnergyPerturbationDataPtr,
bool hasReadEkinState,
TopologyHolder::Builder* topologyHolderBuilder,
- SimulationSignals* signals)
+ GlobalCommunicationHelper* globalCommunicationHelper)
{
auto forceElement = buildForces(neighborSearchSignallerBuilder, energySignallerBuilder,
statePropagatorDataPtr, energyDataPtr,
std::function<void()> needToCheckNumberOfBondedInteractions;
if (legacySimulatorData_->inputrec->eI == eiMD)
{
- auto computeGlobalsElement = std::make_unique<ComputeGlobalsElement<ComputeGlobalsAlgorithm::LeapFrog>>(
- statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr, signals,
- nstglobalcomm_, legacySimulatorData_->fplog, legacySimulatorData_->mdlog,
- legacySimulatorData_->cr, legacySimulatorData_->inputrec, legacySimulatorData_->mdAtoms,
- legacySimulatorData_->nrnb, legacySimulatorData_->wcycle, legacySimulatorData_->fr,
- legacySimulatorData_->top_global, legacySimulatorData_->constr, hasReadEkinState);
+ auto computeGlobalsElement =
+ std::make_unique<ComputeGlobalsElement<ComputeGlobalsAlgorithm::LeapFrog>>(
+ statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
+ globalCommunicationHelper->simulationSignals(),
+ globalCommunicationHelper->nstglobalcomm(), legacySimulatorData_->fplog,
+ legacySimulatorData_->mdlog, legacySimulatorData_->cr,
+ legacySimulatorData_->inputrec, legacySimulatorData_->mdAtoms,
+ legacySimulatorData_->nrnb, legacySimulatorData_->wcycle,
+ legacySimulatorData_->fr, legacySimulatorData_->top_global,
+ legacySimulatorData_->constr, hasReadEkinState);
topologyHolderBuilder->registerClient(computeGlobalsElement.get());
energySignallerBuilder->registerSignallerClient(compat::make_not_null(computeGlobalsElement.get()));
trajectorySignallerBuilder->registerSignallerClient(
compat::make_not_null(computeGlobalsElement.get()));
- *checkBondedInteractionsCallback =
- computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback();
+ globalCommunicationHelper->setCheckBondedInteractionsCallback(
+ computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback());
auto propagator = std::make_unique<Propagator<IntegrationStep::LeapFrog>>(
legacySimulatorData_->inputrec->delta_t, statePropagatorDataPtr,
{
auto computeGlobalsElement =
std::make_unique<ComputeGlobalsElement<ComputeGlobalsAlgorithm::VelocityVerlet>>(
- statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr, signals,
- nstglobalcomm_, legacySimulatorData_->fplog, legacySimulatorData_->mdlog,
- legacySimulatorData_->cr, legacySimulatorData_->inputrec,
- legacySimulatorData_->mdAtoms, legacySimulatorData_->nrnb,
- legacySimulatorData_->wcycle, legacySimulatorData_->fr,
- legacySimulatorData_->top_global, legacySimulatorData_->constr, hasReadEkinState);
+ statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
+ globalCommunicationHelper->simulationSignals(),
+ globalCommunicationHelper->nstglobalcomm(), legacySimulatorData_->fplog,
+ legacySimulatorData_->mdlog, legacySimulatorData_->cr,
+ legacySimulatorData_->inputrec, legacySimulatorData_->mdAtoms,
+ legacySimulatorData_->nrnb, legacySimulatorData_->wcycle,
+ legacySimulatorData_->fr, legacySimulatorData_->top_global,
+ legacySimulatorData_->constr, hasReadEkinState);
topologyHolderBuilder->registerClient(computeGlobalsElement.get());
energySignallerBuilder->registerSignallerClient(compat::make_not_null(computeGlobalsElement.get()));
trajectorySignallerBuilder->registerSignallerClient(
compat::make_not_null(computeGlobalsElement.get()));
- *checkBondedInteractionsCallback =
- computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback();
+ globalCommunicationHelper->setCheckBondedInteractionsCallback(
+ computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback());
auto propagatorVelocities = std::make_unique<Propagator<IntegrationStep::VelocitiesOnly>>(
legacySimulatorData_->inputrec->delta_t * 0.5, statePropagatorDataPtr,
legacySimulatorData_->cr, legacySimulatorData_->mdlog, legacySimulatorData_->mdrunOptions,
legacySimulatorData_->inputrec, legacySimulatorData_->nrnb, legacySimulatorData_->wcycle,
legacySimulatorData_->fr, legacySimulatorData_->walltime_accounting);
+ GlobalCommunicationHelper globalCommunicationHelper(nstglobalcomm_, &algorithm.signals_);
/* When restarting from a checkpoint, it can be appropriate to
* initialize ekind from quantities in the checkpoint. Otherwise,
* compute_globals must initialize ekind before the simulation
*/
const bool simulationsShareState = false;
algorithm.stopHandler_ = legacySimulatorData_->stopHandlerBuilder->getStopHandlerMD(
- compat::not_null<SimulationSignal*>(&algorithm.signals_[eglsSTOPCOND]),
+ compat::not_null<SimulationSignal*>(&(*globalCommunicationHelper.simulationSignals())[eglsSTOPCOND]),
simulationsShareState, MASTER(legacySimulatorData_->cr),
legacySimulatorData_->inputrec->nstlist, legacySimulatorData_->mdrunOptions.reproducible,
- nstglobalcomm_, legacySimulatorData_->mdrunOptions.maximumHoursToRun,
+ globalCommunicationHelper.nstglobalcomm(), legacySimulatorData_->mdrunOptions.maximumHoursToRun,
legacySimulatorData_->inputrec->nstlist == 0, legacySimulatorData_->fplog,
algorithm.stophandlerCurrentStep_, algorithm.stophandlerIsNSStep_,
legacySimulatorData_->walltime_accounting);
*/
// TODO: Make a CheckpointHelperBuilder
std::vector<ICheckpointHelperClient*> checkpointClients;
- CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback = nullptr;
- auto integrator = buildIntegrator(
+ auto integrator = buildIntegrator(
&neighborSearchSignallerBuilder, &lastStepSignallerBuilder, &energySignallerBuilder,
&loggingSignallerBuilder, &trajectorySignallerBuilder, &trajectoryElementBuilder,
- &checkpointClients, &checkBondedInteractionsCallback, statePropagatorDataPtr,
- energyDataPtr, freeEnergyPerturbationDataPtr, hasReadEkinState, &topologyHolderBuilder,
- &algorithm.signals_);
+ &checkpointClients, statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
+ hasReadEkinState, &topologyHolderBuilder, &globalCommunicationHelper);
FreeEnergyPerturbationData::Element* freeEnergyPerturbationElement = nullptr;
if (algorithm.freeEnergyPerturbationData_)
if (DOMAINDECOMP(legacySimulatorData_->cr))
{
- GMX_ASSERT(checkBondedInteractionsCallback,
- "Domain decomposition needs a callback for check the number of bonded "
- "interactions.");
algorithm.domDecHelper_ = std::make_unique<DomDecHelper>(
legacySimulatorData_->mdrunOptions.verbose,
legacySimulatorData_->mdrunOptions.verboseStepPrintInterval, statePropagatorDataPtr,
- algorithm.topologyHolder_.get(), std::move(checkBondedInteractionsCallback),
- nstglobalcomm_, legacySimulatorData_->fplog, legacySimulatorData_->cr,
- legacySimulatorData_->mdlog, legacySimulatorData_->constr, legacySimulatorData_->inputrec,
- legacySimulatorData_->mdAtoms, legacySimulatorData_->nrnb,
+ algorithm.topologyHolder_.get(),
+ globalCommunicationHelper.moveCheckBondedInteractionsCallback(),
+ globalCommunicationHelper.nstglobalcomm(), legacySimulatorData_->fplog,
+ legacySimulatorData_->cr, legacySimulatorData_->mdlog, legacySimulatorData_->constr,
+ legacySimulatorData_->inputrec, legacySimulatorData_->mdAtoms, legacySimulatorData_->nrnb,
legacySimulatorData_->wcycle, legacySimulatorData_->fr, legacySimulatorData_->vsite,
legacySimulatorData_->imdSession, legacySimulatorData_->pull_work);
neighborSearchSignallerBuilder.registerSignallerClient(
const bool simulationsShareResetCounters = false;
algorithm.resetHandler_ = std::make_unique<ResetHandler>(
- compat::make_not_null<SimulationSignal*>(&algorithm.signals_[eglsRESETCOUNTERS]),
+ compat::make_not_null<SimulationSignal*>(
+ &(*globalCommunicationHelper.simulationSignals())[eglsRESETCOUNTERS]),
simulationsShareResetCounters, legacySimulatorData_->inputrec->nsteps,
MASTER(legacySimulatorData_->cr), legacySimulatorData_->mdrunOptions.timingOptions.resetHalfway,
legacySimulatorData_->mdrunOptions.maximumHoursToRun, legacySimulatorData_->mdlog,
// Add checkpoint helper here since we need a pointer to the trajectory element and
// need to register it with the lastStepSignallerBuilder
auto checkpointHandler = std::make_unique<CheckpointHandler>(
- compat::make_not_null<SimulationSignal*>(&algorithm.signals_[eglsCHKPT]),
+ compat::make_not_null<SimulationSignal*>(
+ &(*globalCommunicationHelper.simulationSignals())[eglsCHKPT]),
simulationsShareState, legacySimulatorData_->inputrec->nstlist == 0,
MASTER(legacySimulatorData_->cr), legacySimulatorData_->mdrunOptions.writeConfout,
legacySimulatorData_->mdrunOptions.checkpointOptions.period);
return std::make_unique<SignallerCallback>(
[this](Step step, Time gmx_unused time) { this->nextNSStep_ = step; });
}
+
+GlobalCommunicationHelper::GlobalCommunicationHelper(int nstglobalcomm, SimulationSignals* simulationSignals) :
+ nstglobalcomm_(nstglobalcomm),
+ simulationSignals_(simulationSignals)
+{
+}
+
+int GlobalCommunicationHelper::nstglobalcomm() const
+{
+ return nstglobalcomm_;
+}
+
+SimulationSignals* GlobalCommunicationHelper::simulationSignals()
+{
+ return simulationSignals_;
+}
+
+void GlobalCommunicationHelper::setCheckBondedInteractionsCallback(CheckBondedInteractionsCallbackPtr ptr)
+{
+ checkBondedInteractionsCallbackPtr_ = std::move(ptr);
+}
+
+CheckBondedInteractionsCallbackPtr GlobalCommunicationHelper::moveCheckBondedInteractionsCallback()
+{
+ return std::move(checkBondedInteractionsCallbackPtr_);
+}
+
} // namespace gmx
gmx_walltime_accounting* walltime_accounting;
};
+/*! \internal
+ * \brief Helper container with data connected to global communication
+ *
+ * This includes data that needs to be shared between elements involved in
+ * global communication. This will become obsolete as soon as global
+ * communication is moved to a client system (#3421).
+ */
+class GlobalCommunicationHelper
+{
+public:
+ //! Constructor
+ GlobalCommunicationHelper(int nstglobalcomm, SimulationSignals* simulationSignals);
+
+ //! Get the compute globals communication period
+ [[nodiscard]] int nstglobalcomm() const;
+ //! Get a pointer to the signals vector
+ [[nodiscard]] SimulationSignals* simulationSignals();
+
+ //! Set the callback to check the number of bonded interactions
+ void setCheckBondedInteractionsCallback(CheckBondedInteractionsCallbackPtr ptr);
+ //! Move the callback to check the number of bonded interactions
+ [[nodiscard]] CheckBondedInteractionsCallbackPtr moveCheckBondedInteractionsCallback();
+
+private:
+ //! Compute globals communication period
+ const int nstglobalcomm_;
+ //! Signal vector (used by stop / reset / checkpointing signaller)
+ SimulationSignals* simulationSignals_;
+ //! Callback to check the number of bonded interactions
+ CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallbackPtr_;
+};
+
/*!\internal
* \brief Builder for ModularSimulatorAlgorithm objects
*
SignallerBuilder<TrajectorySignaller>* trajectorySignallerBuilder,
TrajectoryElementBuilder* trajectoryElementBuilder,
std::vector<ICheckpointHelperClient*>* checkpointClients,
- CheckBondedInteractionsCallbackPtr* checkBondedInteractionsCallback,
compat::not_null<StatePropagatorData*> statePropagatorDataPtr,
compat::not_null<EnergyData*> energyDataPtr,
FreeEnergyPerturbationData* freeEnergyPerturbationDataPtr,
bool hasReadEkinState,
TopologyHolder::Builder* topologyHolderBuilder,
- SimulationSignals* signals);
+ GlobalCommunicationHelper* globalCommunicationHelper);
//! Build the force element - can be normal forces or shell / flex constraints
std::unique_ptr<ISimulatorElement>