Use common device context header for OpenCL
[alexxy/gromacs.git] / src / gromacs / mdrun / simulationinpututility.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  * \brief Utilities for interacting with SimulationInput.
37  *
38  * \author M. Eric Irrgang <ericirrgang@gmail.com>
39  * \ingroup module_mdrun
40  */
41
42 #ifndef GMX_MDRUN_SIMULATIONINPUTUTILITY_H
43 #define GMX_MDRUN_SIMULATIONINPUTUTILITY_H
44
45 #include <memory>
46
47 #include "gromacs/mdtypes/checkpointdata.h"
48 #include "gromacs/utility/mdmodulenotification.h"
49
50 #include "simulationinput.h"
51
52 // Forward declarations for types from other modules that are opaque to the public API.
53 // TODO: Document the sources of these symbols or import a (self-documenting) fwd header.
54 struct gmx_mtop_t;
55 struct t_commrec;
56 struct t_fileio;
57 struct t_inputrec;
58 class t_state;
59 struct ObservablesHistory;
60 struct PartialDeserializedTprFile;
61
62 namespace gmx
63 {
64
65 /*! \brief Get the global simulation input.
66  *
67  * Acquire global simulation data structures from the SimulationInput handle.
68  * Note that global data is returned in the calling thread. In parallel
69  * computing contexts, the client is responsible for calling only where needed.
70  *
71  * Example:
72  *    if (SIMMASTER(cr))
73  *    {
74  *        // Only the master rank has the global state
75  *        globalState = globalSimulationState(simulationInput);
76  *
77  *        // Read (nearly) all data required for the simulation
78  *        applyGlobalInputRecord(simulationInput, inputrec);
79  *        applyGlobalTopology(simulationInput, &mtop);
80  *     }
81  *
82  * \todo Factor the logic for global/local and master-rank-checks.
83  * The SimulationInput utilities should behave properly for the various distributed data scenarios.
84  * Consider supplying data directly to the consumers rather than exposing the
85  * implementation details of the legacy aggregate types.
86  *
87  * \{
88  */
89 // TODO: Remove this monolithic detail as member data can be separately cached and managed. (#3374)
90 // Note that clients still need tpxio.h for PartialDeserializedTprFile.
91 void applyGlobalSimulationState(const SimulationInput&      simulationInput,
92                                 PartialDeserializedTprFile* partialDeserializedTpr,
93                                 t_state*                    globalState,
94                                 t_inputrec*                 inputrec,
95                                 gmx_mtop_t*                 globalTopology);
96 // TODO: Implement the following, pending further discussion re #3374.
97 std::unique_ptr<t_state> globalSimulationState(const SimulationInput&);
98 void                     applyGlobalInputRecord(const SimulationInput&, t_inputrec*);
99 void                     applyGlobalTopology(const SimulationInput&, gmx_mtop_t*);
100 //! \}
101
102 /*! \brief Initialize local stateful simulation data.
103  *
104  * Establish an invariant for the simulator at a trajectory point.
105  * Call on all ranks (after domain decomposition and task assignments).
106  *
107  * After this call, the simulator has all of the information it will
108  * receive in order to advance a trajectory from the current step.
109  * Checkpoint information has been applied, if applicable, and stateful
110  * data has been (re)initialized.
111  *
112  * \warning Mdrunner instances do not clearly distinguish between global and local
113  * versions of t_state.
114  *
115  * \todo Factor the distributed data aspects of simulation input data into the
116  *       SimulationInput implementation.
117  *
118  * \todo Consider refactoring to decouple the checkpoint facility from its consumers
119  *       (state, observablesHistory, mdModulesNotifier, and parts of ir).
120  *
121  * \warning It is the caller’s responsibility to make sure that
122  * preconditions are satisfied for the parameter objects.
123  *
124  * \see globalSimulationState()
125  * \see applyGlobalInputRecord()
126  * \see applyGlobalTopology()
127  */
128 void applyLocalState(const SimulationInput&         simulationInput,
129                      t_fileio*                      logfio,
130                      const t_commrec*               cr,
131                      int*                           dd_nc,
132                      t_inputrec*                    ir,
133                      t_state*                       state,
134                      ObservablesHistory*            observablesHistory,
135                      bool                           reproducibilityRequested,
136                      const MdModulesNotifier&       notifier,
137                      gmx::ReadCheckpointDataHolder* modularSimulatorCheckpointData,
138                      bool                           useModularSimulator);
139
140 } // end namespace gmx
141
142 #endif // GMX_MDRUN_SIMULATIONINPUTUTILITY_H