2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declares the checkpoint handler class.
39 * This class sets the signal to checkpoint based on the elapsed simulation time,
40 * and handles the signal if it is received. When handling the signal (via
41 * decideIfCheckpointingThisStep()), it is deciding whether a checkpoint should be saved
42 * at the current step. This can be due to a received signal, or if the current simulation
43 * step is the last. This information can be queried via the isCheckpointingStep() function.
45 * The setting and handling is implemented in private functions. They are only called
46 * if a respective boolean is true. For the trivial case of no checkpointing (or no checkpoint
47 * signal setting on any other rank than master), the translation unit of the calling
48 * function is therefore never left. In the future, this will be achieved by adding
49 * (or not adding) handlers / setters to the task graph.
51 * \author Pascal Merz <pascal.merz@colorado.edu>
53 * \ingroup module_mdlib
55 #ifndef GMX_MDLIB_CHECKPOINTHANDLER_H
56 #define GMX_MDLIB_CHECKPOINTHANDLER_H
60 #include "gromacs/compat/pointers.h"
61 #include "gromacs/mdlib/simulationsignal.h"
63 struct gmx_walltime_accounting;
67 /*! \brief Checkpoint signals
69 * Signals set and read by CheckpointHandler. Possible signals include
71 * * do checkpoint (at next NS step)
73 enum class CheckpointSignal
80 * \brief Class handling the checkpoint signal
82 * Master rank sets the checkpointing signal periodically
83 * All ranks receive checkpointing signal and set the respective flag
85 class CheckpointHandler final
88 /*! \brief CheckpointHandler constructor
90 * Needs a non-null pointer to the signal which is reduced by compute_globals, and
91 * (const) references to data it needs to determine whether a signal needs to be
94 CheckpointHandler(compat::not_null<SimulationSignal*> signal,
95 bool simulationsShareState,
96 bool neverUpdateNeighborList,
98 bool writeFinalCheckpoint,
99 real checkpointingPeriod);
101 /*! \brief Decides whether a checkpointing signal needs to be set
103 * Checkpointing signal is set based on the elapsed run time and the checkpointing
106 void setSignal(gmx_walltime_accounting* walltime_accounting) const
108 if (rankCanSetSignal_)
110 setSignalImpl(walltime_accounting);
114 /*! \brief Decides whether a checkpoint shall be written at this step
116 * Checkpointing is done if this is not the initial step, and
117 * * a signal has been set and the current step is a neighborlist creation
119 * * the current step is the last step and a the simulation is writing
122 * \todo Change these bools to enums to make calls more self-explanatory
124 void decideIfCheckpointingThisStep(bool bNS, bool bFirstStep, bool bLastStep)
126 if (checkpointingIsActive_)
128 decideIfCheckpointingThisStepImpl(bNS, bFirstStep, bLastStep);
132 //! Query decision in decideIfCheckpointingThisStep()
133 bool isCheckpointingStep() const { return checkpointThisStep_; }
136 void setSignalImpl(gmx_walltime_accounting* walltime_accounting) const;
138 void decideIfCheckpointingThisStepImpl(bool bNS, bool bFirstStep, bool bLastStep);
140 SimulationSignal& signal_;
141 bool checkpointThisStep_;
142 int numberOfNextCheckpoint_;
144 const bool rankCanSetSignal_;
145 const bool checkpointingIsActive_;
146 const bool writeFinalCheckpoint_;
147 const bool neverUpdateNeighborlist_;
148 const real checkpointingPeriod_;
152 #endif // GMX_MDLIB_CHECKPOINTHANDLER_H