1a2106e2b2e5057f188d81a949660c793b00d356
[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 by the current rank 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 unlike the other workload descriptors, these flags are also used on
57  * dedicated PME ranks, hence the content is rank-specific (at least when it
58  * comes to flags related to PME).
59  *
60  * Note that the contents of an object of this type is valid for
61  * a single step and it is expected to be set at the beginning each step.
62  *
63  */
64 class StepWorkload
65 {
66 public:
67     //! Whether the state has changed, always set unless TPI is used.
68     bool stateChanged = false;
69     //! Whether the box might have changed
70     bool haveDynamicBox = false;
71     //! Whether neighbor searching needs to be done this step
72     bool doNeighborSearch = false;
73     //! Whether the slow forces need to be computed this step (in addition to the faster forces)
74     bool computeSlowForces = false;
75     //! Whether virial needs to be computed this step
76     bool computeVirial = false;
77     //! Whether energies need to be computed this step this step
78     bool computeEnergy = false;
79     //! Whether (any) forces need to be computed this step, not only energies
80     bool computeForces = false;
81     //! Whether only the MTS combined force buffers are needed and not the separate normal force buffer.
82     bool useOnlyMtsCombinedForceBuffer = false;
83     //! Whether nonbonded forces need to be computed this step
84     bool computeNonbondedForces = false;
85     //! Whether listed forces need to be computed this step
86     bool computeListedForces = false;
87     //! Whether this step DHDL needs to be computed
88     bool computeDhdl = false;
89     /*! \brief Whether coordinate buffer ops are done on the GPU this step
90      * \note This technically belongs to DomainLifetimeWorkload but due
91      * to needing the flag before DomainLifetimeWorkload is built we keep
92      * it here for now.
93      */
94     bool useGpuXBufferOps = false;
95     //! Whether force buffer ops are done on the GPU this step
96     bool useGpuFBufferOps = false;
97     //! Whether PME forces are reduced with other contributions on the GPU this step
98     bool useGpuPmeFReduction = false; // TODO: add this flag to the internal PME GPU data structures too
99     //! Whether GPU coordinates halo exchange is active this step
100     bool useGpuXHalo = false;
101     //! Whether GPU forces halo exchange is active this step
102     bool useGpuFHalo = false;
103     //! Whether GPU PME work is computed on the current rank this step (can be false on PP-only ranks or on fast steps with MTS)
104     bool haveGpuPmeOnThisRank = false;
105     //! Whether to combine the forces for multiple time stepping before the halo exchange
106     bool combineMtsForcesBeforeHaloExchange = false;
107 };
108
109 /*! \libinternal
110  * \brief Describes work done on this domain on every step of its lifetime,
111  * but which might change after the next domain paritioning.
112  *
113  * This work description is based on the SimulationWorkload in the context of the
114  * current particle interactions assigned to this domain. The latter might change
115  * after the next domain partitioning.
116  *
117  * An object of this type is updated every domain decomposition / neighbour search step
118  * and reflects what work is required during the lifetime of a domain;
119  * e.g. whether there are bonded interactions in this PP task.
120  *
121  */
122 class DomainLifetimeWorkload
123 {
124 public:
125     //! Whether the current nstlist step-range has bonded work to run on a GPU.
126     bool haveGpuBondedWork = false;
127     //! Whether the current nstlist step-range has bonded work to run on the CPU.
128     bool haveCpuBondedWork = false;
129     //! Whether the current nstlist step-range has listed (bonded + restraints) forces work to run on the CPU.
130     bool haveCpuListedForceWork = false;
131     //! Whether the current nstlist step-range has special forces on the CPU.
132     bool haveSpecialForces = false;
133     //! Whether there are currently any local forces to be computed on the CPU
134     bool haveCpuLocalForceWork = false;
135
136     //! Whether the current nstlist step-range Free energy work on the CPU.
137     bool haveFreeEnergyWork = false;
138     //! Whether the CPU force buffer has contributions to local atoms that need to be reduced on the GPU (with DD).
139     // This depends on whether there are CPU-based force tasks
140     // or when DD is active the halo exchange has resulted in contributions
141     // from the non-local part.
142     bool haveLocalForceContribInCpuBuffer = false;
143     //! Whether the CPU force buffer has contributions to nonlocal atoms that need to be reduced on the GPU (with DD).
144     bool haveNonLocalForceContribInCpuBuffer = false;
145 };
146
147 /*! \libinternal
148  * \brief Manage what computation is required during the simulation.
149  *
150  * Holds information on the type of workload constant for the entire
151  * simulation, and independent of the particle interactions handled
152  * on any specific domain.
153  *
154  * An object of this type is constructed at the beginning of the
155  * simulation and is expected to not change.
156  * Additionally, the initialization is uniform across ranks of a
157  * simulation, even with MPMD decomposition and separate PME ranks.
158  */
159 class SimulationWorkload
160 {
161 public:
162     //! Whether to compute nonbonded pair interactions
163     bool computeNonbonded = false;
164     //! Whether nonbonded pair forces are to be computed at slow MTS steps only
165     bool computeNonbondedAtMtsLevel1 = false;
166     //! Whether total dipole needs to be computed
167     bool computeMuTot = false;
168     //! If we have calculation of short range nonbondeds on CPU
169     bool useCpuNonbonded = false;
170     //! If we have calculation of short range nonbondeds on GPU
171     bool useGpuNonbonded = false;
172     //! If we have calculation of long range PME in GPU
173     bool useCpuPme = false;
174     //! If we have calculation of long range PME in GPU
175     bool useGpuPme = false;
176     //! If PME FFT solving is done on GPU.
177     bool useGpuPmeFft = false;
178     //! If bonded interactions are calculated on GPU.
179     bool useGpuBonded = false;
180     //! If update and constraint solving is performed on GPU.
181     bool useGpuUpdate = false;
182     //! If buffer operations are performed on GPU.
183     bool useGpuBufferOps = false;
184     //! If PP domain decomposition is active.
185     bool havePpDomainDecomposition = false;
186     //! If domain decomposition halo exchange is performed on CPU (in CPU-only runs or with staged GPU communication).
187     bool useCpuHaloExchange = false;
188     //! If domain decomposition halo exchange is performed on GPU.
189     bool useGpuHaloExchange = false;
190     //! If separate PME rank(s) are used.
191     bool haveSeparatePmeRank = false;
192     //! If PP-PME communication is done purely on CPU (in CPU-only runs or with staged GPU communication).
193     bool useCpuPmePpCommunication = false;
194     //! If direct PP-PME communication between GPU is used.
195     bool useGpuPmePpCommunication = false;
196     //! If direct GPU-GPU communication is enabled.
197     bool useGpuDirectCommunication = false;
198     //! If there is an Ewald surface (dipole) term to compute
199     bool haveEwaldSurfaceContribution = false;
200     //! Whether to use multiple time stepping
201     bool useMts = false;
202 };
203
204 class MdrunScheduleWorkload
205 {
206 public:
207     //! Workload descriptor for information constant for an entire run
208     SimulationWorkload simulationWork;
209
210     //! Workload descriptor for information constant for an nstlist range of steps
211     DomainLifetimeWorkload domainWork;
212
213     //! Workload descriptor for information that may change per-step
214     StepWorkload stepWork;
215 };
216
217 } // namespace gmx
218
219 #endif // GMX_MDTYPES_SIMULATION_WORKLOAD_H