Simplify mdrun tMPI thread spawning
[gromacs.git] / src / programs / mdrun / runner.h
blob2c458f0844e932635bced917692aa2cd80e8e42b
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2017,2018, 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 * \brief Declares the routine running the inetgrators.
39 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
40 * \ingroup module_mdlib
42 #ifndef GMX_MDLIB_RUNNER_H
43 #define GMX_MDLIB_RUNNER_H
45 #include <cstdio>
47 #include <array>
49 #include "gromacs/commandline/filenm.h"
50 #include "gromacs/domdec/domdec.h"
51 #include "gromacs/hardware/hw_info.h"
52 #include "gromacs/math/vec.h"
53 #include "gromacs/mdlib/mdrun.h"
54 #include "gromacs/utility/basedefinitions.h"
55 #include "gromacs/utility/real.h"
57 #include "repl_ex.h"
59 struct gmx_output_env_t;
60 struct ReplicaExchangeParameters;
61 struct t_commrec;
63 namespace gmx
66 /*! \libinternal \brief Runner object for supporting setup and execution of mdrun.
68 * This class has responsibility for the lifetime of data structures
69 * that exist for the life of the simulation, e.g. for logging and
70 * communication.
72 * \todo Most of the attributes should be declared by specific modules
73 * as command-line options. Accordingly, they do not conform to the
74 * naming scheme, because that would make for a lot of noise in the
75 * diff, only to have it change again when the options move to their
76 * modules.
78 * \todo Preparing logging and MPI contexts could probably be a
79 * higher-level responsibility, so that an Mdrunner would get made
80 * without needing to re-initialize these components (as currently
81 * happens always for the master rank, and differently for the spawned
82 * ranks with thread-MPI).
84 class Mdrunner
86 private:
87 //! Parallelism-related user options.
88 gmx_hw_opt_t hw_opt;
89 //! Filenames and properties from command-line argument values.
90 std::array<t_filenm, 34> filenames =
91 {{{ efTPR, nullptr, nullptr, ffREAD },
92 { efTRN, "-o", nullptr, ffWRITE },
93 { efCOMPRESSED, "-x", nullptr, ffOPTWR },
94 { efCPT, "-cpi", nullptr, ffOPTRD | ffALLOW_MISSING },
95 { efCPT, "-cpo", nullptr, ffOPTWR },
96 { efSTO, "-c", "confout", ffWRITE },
97 { efEDR, "-e", "ener", ffWRITE },
98 { efLOG, "-g", "md", ffWRITE },
99 { efXVG, "-dhdl", "dhdl", ffOPTWR },
100 { efXVG, "-field", "field", ffOPTWR },
101 { efXVG, "-table", "table", ffOPTRD },
102 { efXVG, "-tablep", "tablep", ffOPTRD },
103 { efXVG, "-tableb", "table", ffOPTRDMULT },
104 { efTRX, "-rerun", "rerun", ffOPTRD },
105 { efXVG, "-tpi", "tpi", ffOPTWR },
106 { efXVG, "-tpid", "tpidist", ffOPTWR },
107 { efEDI, "-ei", "sam", ffOPTRD },
108 { efXVG, "-eo", "edsam", ffOPTWR },
109 { efXVG, "-devout", "deviatie", ffOPTWR },
110 { efXVG, "-runav", "runaver", ffOPTWR },
111 { efXVG, "-px", "pullx", ffOPTWR },
112 { efXVG, "-pf", "pullf", ffOPTWR },
113 { efXVG, "-ro", "rotation", ffOPTWR },
114 { efLOG, "-ra", "rotangles", ffOPTWR },
115 { efLOG, "-rs", "rotslabs", ffOPTWR },
116 { efLOG, "-rt", "rottorque", ffOPTWR },
117 { efMTX, "-mtx", "nm", ffOPTWR },
118 { efRND, "-multidir", nullptr, ffOPTRDMULT},
119 { efXVG, "-awh", "awhinit", ffOPTRD },
120 { efDAT, "-membed", "membed", ffOPTRD },
121 { efTOP, "-mp", "membed", ffOPTRD },
122 { efNDX, "-mn", "membed", ffOPTRD },
123 { efXVG, "-if", "imdforces", ffOPTWR },
124 { efXVG, "-swap", "swapions", ffOPTWR }}};
125 /*! \brief Filename arguments.
127 * Provided for compatibility with old C-style code accessing
128 * command-line arguments that are file names. */
129 t_filenm *fnm = filenames.data();
130 /*! \brief Number of filename argument values.
132 * Provided for compatibility with old C-style code accessing
133 * command-line arguments that are file names. */
134 int nfile = filenames.size();
135 //! Output context for writing text files
136 gmx_output_env_t *oenv = nullptr;
137 //! Ongoing collection of mdrun options
138 MdrunOptions mdrunOptions;
139 //! Options for the domain decomposition.
140 DomdecOptions domdecOptions;
141 //! Target short-range interations for "cpu", "gpu", or "auto". Default is "auto".
142 const char *nbpu_opt = nullptr;
143 //! Target long-range interactions for "cpu", "gpu", or "auto". Default is "auto".
144 const char *pme_opt = nullptr;
145 //! Target long-range interactions FFT/solve stages for "cpu", "gpu", or "auto". Default is "auto".
146 const char *pme_fft_opt = nullptr;
147 //! Command-line override for the duration of a neighbor list with the Verlet scheme.
148 int nstlist_cmdline = 0;
149 //! Parameters for replica-exchange simulations.
150 ReplicaExchangeParameters replExParams;
151 //! Print a warning if any force is larger than this (in kJ/mol nm).
152 real pforce = -1;
153 //! Handle to file used for logging.
154 FILE *fplog;
155 //! Handle to communication data structure.
156 t_commrec *cr;
157 //! Handle to multi-simulation handler.
158 gmx_multisim_t *ms;
160 public:
161 /*! \brief Defaulted constructor.
163 * Note that when member variables are not present in the constructor
164 * member initialization list (which is true for the default constructor),
165 * then they are initialized with any default member initializer specified
166 * when they were declared, or default initialized. */
167 Mdrunner() = default;
168 //! Start running mdrun by calling its C-style main function.
169 int mainFunction(int argc, char *argv[]);
170 /*! \brief Driver routine, that calls the different simulation methods. */
171 int mdrunner();
172 //! Called when thread-MPI spawns threads.
173 t_commrec *spawnThreads(int numThreadsToLaunch) const;
174 /*! \brief Re-initializes the object after threads spawn.
176 * \todo Can this be refactored so that the Mdrunner on a spawned thread is
177 * constructed ready to use? */
178 void reinitializeOnSpawnedThread();
181 } // namespace gmx
183 #endif // GMX_MDLIB_RUNNER_H