Prepare legacy checkpoint for modular simulator checkpointing
[gromacs.git] / src / gromacs / modularsimulator / modularsimulator.h
bloba46b52ebdef235bc457101076b00528463f82bc5
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020, 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
36 * \brief Provides the modular simulator.
38 * Defines the ModularSimulator class. Provides checkUseModularSimulator() utility function
39 * to determine whether the ModularSimulator should be used.
41 * \author Pascal Merz <pascal.merz@me.com>
42 * \ingroup module_modularsimulator
44 * This header is currently the only part of the modular simulator module which is exposed.
45 * Mdrunner creates an object of type ModularSimulator (via SimulatorBuilder), and calls its
46 * run() method. Mdrunner also calls checkUseModularSimulator(...), which in turns calls a
47 * static method of ModularSimulator. This could easily become a free function if this requires
48 * more exposure than otherwise necessary.
50 #ifndef GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H
51 #define GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H
53 #include "gromacs/mdrun/isimulator.h"
55 struct t_fcdata;
57 namespace gmx
59 class ModularSimulatorAlgorithmBuilder;
60 class ReadCheckpointDataHolder;
62 /*! \libinternal
63 * \ingroup module_modularsimulator
64 * \brief The modular simulator
66 * Based on the input given, this simulator builds independent elements and
67 * signallers and stores them in a respective vector. The run function
68 * runs the simulation by, in turn, building a task list from the elements
69 * for a predefined number of steps, then running the task list, and repeating
70 * until the stop criterion is fulfilled.
72 class ModularSimulator final : public ISimulator
74 public:
75 //! Run the simulator
76 void run() override;
78 //! Check for disabled functionality
79 static bool isInputCompatible(bool exitOnFailure,
80 const t_inputrec* inputrec,
81 bool doRerun,
82 const gmx_mtop_t& globalTopology,
83 const gmx_multisim_t* ms,
84 const ReplicaExchangeParameters& replExParams,
85 const t_fcdata* fcd,
86 bool doEssentialDynamics,
87 bool doMembed);
89 // Only builder can construct
90 friend class SimulatorBuilder;
92 private:
93 //! Constructor
94 ModularSimulator(std::unique_ptr<LegacySimulatorData> legacySimulatorData,
95 std::unique_ptr<ReadCheckpointDataHolder> checkpointDataHolder);
97 //! Populate algorithm builder with elements
98 void addIntegrationElements(ModularSimulatorAlgorithmBuilder* builder);
100 //! Check for disabled functionality (during construction time)
101 void checkInputForDisabledFunctionality();
103 //! Pointer to legacy simulator data (TODO: Can we avoid using unique_ptr? #3628)
104 std::unique_ptr<LegacySimulatorData> legacySimulatorData_;
105 //! Input checkpoint data
106 std::unique_ptr<ReadCheckpointDataHolder> checkpointDataHolder_;
110 * \brief Whether or not to use the ModularSimulator
112 * GMX_DISABLE_MODULAR_SIMULATOR environment variable allows to disable modular simulator for
113 * all uses.
115 * See ModularSimulator::isInputCompatible() for function signature.
117 * \ingroup module_modularsimulator
119 template<typename... Ts>
120 auto checkUseModularSimulator(Ts&&... args)
121 -> decltype(ModularSimulator::isInputCompatible(std::forward<Ts>(args)...))
123 return ModularSimulator::isInputCompatible(std::forward<Ts>(args)...)
124 && getenv("GMX_DISABLE_MODULAR_SIMULATOR") == nullptr;
127 } // namespace gmx
129 #endif // GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H