Gromacs  2023.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Enumerations | Functions
stophandler.h File Reference
#include <functional>
#include <memory>
#include <vector>
#include "gromacs/compat/pointers.h"
#include "gromacs/mdlib/sighandler.h"
#include "gromacs/mdlib/simulationsignal.h"
+ Include dependency graph for stophandler.h:


Declares StopHandler, a helper class and two stop conditions.

These classes encapsulate the setting and handling of stop signals.

StopHandler lives during the lifetime of do_md. It checks via registered stop conditions whether the simulation should be stopped at the next possible step or at the next possible neighbor-searching step. It communicates this via signal to all ranks and communicates this to do_md via stoppingAfterCurrentStep().

StopHandlerBuilder is owned by the runner, and allows to register stop conditions at a higher level, outside of do_md. Within do_md, it is creating a StopHandler object by binding local data and passing a reference to the stop conditions.

Here, we are implementing two stop conditions: StopConditionTime sets a stop condition based on the elapsed time (only relevant if the -maxh flag was set), while StopConditionSignal sets stop conditions via signals received from the operating systems (SIGINT / SIGTERM).

The stop conditions are stored as function pointers created by a lambda expression. They bind to required local data, in the case of StopConditionTime and StopConditionSignal these are partially owned by do_md. This requires these function pointers to be deleted at the end of do_md(). This is achieved by having the do_md() specific function pointers owned by StopHandler, which in turn is owned (via unique_ptr) by do_md().

Pascal Merz


class  gmx::StopHandler
 Class handling the stop signal. More...
class  gmx::StopConditionSignal
 Class setting the stop signal based on gmx_get_stop_condition() More...
class  gmx::StopConditionTime
 Class setting the stop signal based on maximal run time. More...
class  gmx::StopHandlerBuilder
 Class preparing the creation of a StopHandler. More...


enum  gmx::StopSignal : int { noSignal = 0, stopAtNextNSStep = 1, stopImmediately = -1 }
 Stop signals. More...


static StopSignal gmx::convertToStopSignal (signed char sig)
 Convert signed char (as used by SimulationSignal) to StopSignal enum. More...