Gromacs  2025.0-dev-20241011-013a99c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::StopHandlerBuilder Class Referencefinal

#include <gromacs/mdlib/stophandler.h>

Description

Class preparing the creation of a StopHandler.

An object of this helper class (owned by the runner) allows to register stop conditions outside of the actual simulation run via registerStopCondition(), accepting a std::function object. It then builds a StopHandler object inside do_md, once it can bind to required local data.

The registered stop conditions plus the standard MD stop conditions (stop based on received signal from OS [SIGINT / SIGTERM] or based on maximal run time) are then called by the Stophandler every step to determine whether the simulation should be stopped. The registered functions need to be of type std::function<StopSignal()>, i.e. not taking any input arguments and returning a StopSignal signal which will get propagated to all ranks. If the function needs input arguments, these need to be bound (e.g. via lambda capturing) before being registered with the StopHandlerBuilder.

Public Member Functions

void registerStopCondition (std::function< StopSignal()> stopCondition)
 Register stop condition. More...
 
std::unique_ptr< StopHandlergetStopHandlerMD (compat::not_null< SimulationSignal * > signal, bool simulationShareState, bool isMain, int nstList, bool makeBinaryReproducibleSimulation, int nstSignalComm, real maximumHoursToRun, bool neverUpdateNeighborList, FILE *fplog, const int64_t &step, const gmx_bool &bNS, gmx_walltime_accounting *walltime_accounting)
 Create StopHandler. More...
 

Member Function Documentation

std::unique_ptr< StopHandler > gmx::StopHandlerBuilder::getStopHandlerMD ( compat::not_null< SimulationSignal * >  signal,
bool  simulationShareState,
bool  isMain,
int  nstList,
bool  makeBinaryReproducibleSimulation,
int  nstSignalComm,
real  maximumHoursToRun,
bool  neverUpdateNeighborList,
FILE *  fplog,
const int64_t &  step,
const gmx_bool bNS,
gmx_walltime_accounting walltime_accounting 
)

Create StopHandler.

Gets called in the scope of the integrator (aka do_md()) to get a pointer to the StopHandler for the current simulations. Adds the standard MD stop conditions (e.g. gmx::StopConditionTime, gmx::StopConditionSignal) to the currently registered stop conditions. Initializes a new StopHandler with this extended vector of stop conditions. It is the caller's responsibility to make sure arguments passed by pointer or reference remain valid for the lifetime of the returned StopHandler.

void gmx::StopHandlerBuilder::registerStopCondition ( std::function< StopSignal()>  stopCondition)

Register stop condition.

This allows code in the scope of the StopHandlerBuilder (runner level) to inject stop conditions in simulations. Stop conditions are defined as argument-less functions which return a StopSignal. The return value of this function is then propagated to all ranks, and allows to stop the simulation at the next global communication step (returned signal StopSignal::stopImmediately), or at the next NS step (returned signal StopSignal::stopAtNextNSStep, allows for exact continuation).

Arguments needed by the stop condition function need to be bound / captured. If these arguments are captured by reference or using a pointer, it is the registrant's responsibility to ensure that these arguments do not go out of scope during the lifetime of the StopHandlerBuilder.


The documentation for this class was generated from the following files: