73fd19a54ae6114404fb44f71bb6043c8cec46c1
[alexxy/gromacs.git] / src / gromacs / mdtypes / simulation_workload.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018,2019,2020,2021, 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 Declares step, domain-lifetime, and run workload managers.
37  *
38  * \author Mark Abraham <mark.j.abraham@gmail.com>
39  * \author Szilárd Páll <pall.szilard@gmail.com>
40  * \ingroup module_mdlib
41  * \inlibraryapi
42  */
43 #ifndef GMX_MDTYPES_SIMULATION_WORKLOAD_H
44 #define GMX_MDTYPES_SIMULATION_WORKLOAD_H
45
46 namespace gmx
47 {
48
49 /*! \libinternal
50  * \brief Describes work done on this domain that may change per-step.
51  *
52  * This work description is based on the SimulationWorkload in the context of the
53  * current particle interactions assigned to this domain as well as other
54  * factors that may change during the lifetime of a domain.
55  *
56  * Note that the contents of an object of this type is valid for
57  * a single step and it is expected to be set at the beginning each step.
58  *
59  * The initial set of flags map the legacy force flags to boolean flags;
60  * these have the role of directing per-step compute tasks undertaken by a PP rank.
61  *
62  */
63 class StepWorkload
64 {
65 public:
66     //! Whether the state has changed, always set unless TPI is used.
67     bool stateChanged = false;
68     //! Whether the box might have changed
69     bool haveDynamicBox = false;
70     //! Whether neighbor searching needs to be done this step
71     bool doNeighborSearch = false;
72     //! Whether the slow forces need to be computed this step (in addition to the faster forces)
73     bool computeSlowForces = false;
74     //! Whether virial needs to be computed this step
75     bool computeVirial = false;
76     //! Whether energies need to be computed this step this step
77     bool computeEnergy = false;
78     //! Whether (any) forces need to be computed this step, not only energies
79     bool computeForces = false;
80     //! Whether only the MTS combined force buffers are needed and not the separate normal force buffer.
81     bool useOnlyMtsCombinedForceBuffer = false;
82     //! Whether nonbonded forces need to be computed this step
83     bool computeNonbondedForces = false;
84     //! Whether listed forces need to be computed this step
85     bool computeListedForces = false;
86     //! Whether this step DHDL needs to be computed
87     bool computeDhdl = false;
88     /*! \brief Whether coordinate buffer ops are done on the GPU this step
89      * \note This technically belongs to DomainLifetimeWorkload but due
90      * to needing the flag before DomainLifetimeWorkload is built we keep
91      * it here for now.
92      */
93     bool useGpuXBufferOps = false;
94     //! Whether force buffer ops are done on the GPU this step
95     bool useGpuFBufferOps = false;
96     //! Whether PME forces are reduced with other contributions on the GPU this step
97     bool useGpuPmeFReduction = false; // TODO: add this flag to the internal PME GPU data structures too
98     //! Whether GPU coordinates halo exchange is active this step
99     bool useGpuXHalo = false;
100     //! Whether GPU forces halo exchange is active this step
101     bool useGpuFHalo = false;
102     //! Whether GPU PME work is compute this step (can be false also on fast steps with MTS)
103     bool haveGpuPmeOnThisRank = false;
104 };
105
106 /*! \libinternal
107  * \brief Describes work done on this domain on every step of its lifetime,
108  * but which might change after the next domain paritioning.
109  *
110  * This work description is based on the SimulationWorkload in the context of the
111  * current particle interactions assigned to this domain. The latter might change
112  * after the next domain partitioning.
113  *
114  * An object of this type is updated every domain decomposition / neighbour search step
115  * and reflects what work is required during the lifetime of a domain;
116  * e.g. whether there are bonded interactions in this PP task.
117  *
118  */
119 class DomainLifetimeWorkload
120 {
121 public:
122     //! Whether the current nstlist step-range has bonded work to run on a GPU.
123     bool haveGpuBondedWork = false;
124     //! Whether the current nstlist step-range has bonded work to run on the CPU.
125     bool haveCpuBondedWork = false;
126     //! Whether the current nstlist step-range has listed (bonded + restraints) forces work to run on the CPU.
127     bool haveCpuListedForceWork = false;
128     //! Whether the current nstlist step-range has special forces on the CPU.
129     bool haveSpecialForces = false;
130     //! Whether there are currently any local forces to be computed on the CPU
131     bool haveCpuLocalForceWork = false;
132
133     //! Whether the current nstlist step-range Free energy work on the CPU.
134     bool haveFreeEnergyWork = false;
135     //! Whether the CPU force buffer has contributions to local atoms that need to be reduced on the GPU (with DD).
136     // This depends on whether there are CPU-based force tasks
137     // or when DD is active the halo exchange has resulted in contributions
138     // from the non-local part.
139     bool haveLocalForceContribInCpuBuffer = false;
140     //! Whether the CPU force buffer has contributions to nonlocal atoms that need to be reduced on the GPU (with DD).
141     bool haveNonLocalForceContribInCpuBuffer = false;
142 };
143
144 /*! \libinternal
145  * \brief Manage what computation is required during the simulation.
146  *
147  * Holds information on the type of workload constant for the entire
148  * simulation, and independent of the particle interactions handled
149  * on any specific domain.
150  *
151  * An object of this type is constructed at the beginning of the
152  * simulation and is expected to not change.
153  * Additionally, the initialization is uniform across ranks of a
154  * simulation, even with MPMD decomposition and separate PME ranks.
155  */
156 class SimulationWorkload
157 {
158 public:
159     //! Whether to compute nonbonded pair interactions
160     bool computeNonbonded = false;
161     //! Wether nonbonded pair forces are to be computed at slow MTS steps only
162     bool computeNonbondedAtMtsLevel1 = false;
163     //! Whether total dipole needs to be computed
164     bool computeMuTot = false;
165     //! If we have calculation of short range nonbondeds on CPU
166     bool useCpuNonbonded = false;
167     //! If we have calculation of short range nonbondeds on GPU
168     bool useGpuNonbonded = false;
169     //! If we have calculation of long range PME in GPU
170     bool useCpuPme = false;
171     //! If we have calculation of long range PME in GPU
172     bool useGpuPme = false;
173     //! If PME FFT solving is done on GPU.
174     bool useGpuPmeFft = false;
175     //! If bonded interactions are calculated on GPU.
176     bool useGpuBonded = false;
177     //! If update and constraint solving is performed on GPU.
178     bool useGpuUpdate = false;
179     //! If buffer operations are performed on GPU.
180     bool useGpuBufferOps = false;
181     //! If domain decomposition halo exchange is performed on GPU.
182     bool useGpuHaloExchange = false;
183     //! If direct PP-PME communication between GPU is used.
184     bool useGpuPmePpCommunication = false;
185     //! If direct GPU-GPU communication is enabled.
186     bool useGpuDirectCommunication = false;
187     //! If there is an Ewald surface (dipole) term to compute
188     bool haveEwaldSurfaceContribution = false;
189 };
190
191 class MdrunScheduleWorkload
192 {
193 public:
194     //! Workload descriptor for information constant for an entire run
195     SimulationWorkload simulationWork;
196
197     //! Workload descriptor for information constant for an nstlist range of steps
198     DomainLifetimeWorkload domainWork;
199
200     //! Workload descriptor for information that may change per-step
201     StepWorkload stepWork;
202 };
203
204 } // namespace gmx
205
206 #endif // GMX_MDTYPES_SIMULATION_WORKLOAD_H