1/*
2 * This file is part of the GROMACS molecular simulation package.
3 *
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
10 *
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
15 *
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25 *
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
33 *
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
36 */
37/*! \libinternal \file
38 *
39 * \brief This file declares helper functionality for legacy option handling for mdrun
40 *
41 * \author Berk Hess <hess@kth.se>
42 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
43 * \author Erik Lindahl <erik@kth.se>
44 * \author Mark Abraham <mark.j.abraham@gmail.com>
45 *
46 * \ingroup module_mdrun
47 * \inlibraryapi
48 */
49#ifndef GMX_MDRUN_LEGACYMDRUNOPTIONS_H
50#define GMX_MDRUN_LEGACYMDRUNOPTIONS_H
51
52#include "gromacs/commandline/filenm.h"
53#include "gromacs/commandline/pargs.h"
54#include "gromacs/domdec/domdec.h"
55#include "gromacs/hardware/hw_info.h"
56#include "gromacs/mdlib/mdrun.h"
57#include "gromacs/mdrun/logging.h"
58
59#include "replicaexchange.h"
60
61struct gmx_multisim_t;
62
63namespace gmx
64{
65
66/*! \libinternal
67 * \brief This class provides the same command-line option
68 * functionality to both CLI and API sessions.
69 *
70 * This class should not exist, but is necessary now to introduce
71 * support for the CLI and API without duplicating code. It should be
72 * eliminated following the TODOs below.
73 *
74 * \todo Modules in mdrun should acquire proper option handling so
75 * that all of these declarations and defaults are local to the
76 * modules.
77 *
78 * \todo Contextual aspects, such as working directory, MPI
79 * environment, and environment variable handling are more properly
80 * the role of SimulationContext, and should be moved there */
81class LegacyMdrunOptions
82{
83    public:
84        //! Ongoing collection of mdrun options
85        MdrunOptions                     mdrunOptions;
86        //! Options for the domain decomposition.
87        DomdecOptions                    domdecOptions;
88        //! Parallelism-related user options.
89        gmx_hw_opt_t                     hw_opt;
90        //! Command-line override for the duration of a neighbor list with the Verlet scheme.
91        int                              nstlist_cmdline = 0;
92        //! Parameters for replica-exchange simulations.
93        ReplicaExchangeParameters        replExParams;
94
95        //! Filename options to fill from command-line argument values.
96        std::vector<t_filenm> filenames =
97        {{{ efTPR, nullptr,     nullptr,     ffREAD },
98          { efTRN, "-o",        nullptr,     ffWRITE },
99          { efCOMPRESSED, "-x", nullptr,     ffOPTWR },
100          { efCPT, "-cpi",      nullptr,     ffOPTRD | ffALLOW_MISSING },
101          { efCPT, "-cpo",      nullptr,     ffOPTWR },
102          { efSTO, "-c",        "confout",   ffWRITE },
103          { efEDR, "-e",        "ener",      ffWRITE },
104          { efLOG, "-g",        "md",        ffWRITE },
105          { efXVG, "-dhdl",     "dhdl",      ffOPTWR },
106          { efXVG, "-field",    "field",     ffOPTWR },
107          { efXVG, "-table",    "table",     ffOPTRD },
108          { efXVG, "-tablep",   "tablep",    ffOPTRD },
109          { efXVG, "-tableb",   "table",     ffOPTRDMULT },
110          { efTRX, "-rerun",    "rerun",     ffOPTRD },
111          { efXVG, "-tpi",      "tpi",       ffOPTWR },
112          { efXVG, "-tpid",     "tpidist",   ffOPTWR },
113          { efEDI, "-ei",       "sam",       ffOPTRD },
114          { efXVG, "-eo",       "edsam",     ffOPTWR },
115          { efXVG, "-devout",   "deviatie",  ffOPTWR },
116          { efXVG, "-runav",    "runaver",   ffOPTWR },
117          { efXVG, "-px",       "pullx",     ffOPTWR },
118          { efXVG, "-pf",       "pullf",     ffOPTWR },
119          { efXVG, "-ro",       "rotation",  ffOPTWR },
120          { efLOG, "-ra",       "rotangles", ffOPTWR },
121          { efLOG, "-rs",       "rotslabs",  ffOPTWR },
122          { efLOG, "-rt",       "rottorque", ffOPTWR },
123          { efMTX, "-mtx",      "nm",        ffOPTWR },
124          { efRND, "-multidir", nullptr,     ffOPTRDMULT},
125          { efXVG, "-awh",      "awhinit",   ffOPTRD },
126          { efDAT, "-membed",   "membed",    ffOPTRD },
127          { efTOP, "-mp",       "membed",    ffOPTRD },
128          { efNDX, "-mn",       "membed",    ffOPTRD },
129          { efXVG, "-if",       "imdforces", ffOPTWR },
130          { efXVG, "-swap",     "swapions",  ffOPTWR }}};
131
132        //! Print a warning if any force is larger than this (in kJ/mol nm).
133        real                             pforce = -1;
134
135        /*! \brief Output context for writing text files
136         *
137         * \todo Clarify initialization, ownership, and lifetime. */
138        gmx_output_env_t                *oenv = nullptr;
139
140        //! Handle to file used for logging.
141        LogFilePtr logFileGuard = nullptr;
142
143        /*! \brief Command line options, defaults, docs and storage for them to fill. */
144        /*! \{ */
145        rvec              realddxyz                                               = {0, 0, 0};
146        const char       *ddrank_opt_choices[static_cast<int>(DdRankOrder::nr)+1] =
147        { nullptr, "interleave", "pp_pme", "cartesian", nullptr };
148        const char       *dddlb_opt_choices[static_cast<int>(DlbOption::nr)+1] =
149        { nullptr, "auto", "no", "yes", nullptr };
150        const char       *thread_aff_opt_choices[threadaffNR+1] =
151        { nullptr, "auto", "on", "off", nullptr };
152        const char       *nbpu_opt_choices[5] =
153        { nullptr, "auto", "cpu", "gpu", nullptr };
154        const char       *pme_opt_choices[5] =
155        { nullptr, "auto", "cpu", "gpu", nullptr };
156        const char       *pme_fft_opt_choices[5] =
157        { nullptr, "auto", "cpu", "gpu", nullptr };
158        const char       *bonded_opt_choices[5] =
159        { nullptr, "auto", "cpu", "gpu", nullptr };
160        gmx_bool          bTryToAppendFiles     = TRUE;
161        const char       *gpuIdsAvailable       = "";
162        const char       *userGpuTaskAssignment = "";
163
164        ImdOptions       &imdOptions = mdrunOptions.imdOptions;
165
166        t_pargs           pa[48] = {
167
168            { "-dd",      FALSE, etRVEC, {&realddxyz},
169              "Domain decomposition grid, 0 is optimize" },
170            { "-ddorder", FALSE, etENUM, {ddrank_opt_choices},
171              "DD rank order" },
172            { "-npme",    FALSE, etINT, {&domdecOptions.numPmeRanks},
173              "Number of separate ranks to be used for PME, -1 is guess" },
174            { "-nt",      FALSE, etINT, {&hw_opt.nthreads_tot},
175              "Total number of threads to start (0 is guess)" },
176            { "-ntmpi",   FALSE, etINT, {&hw_opt.nthreads_tmpi},
177              "Number of thread-MPI ranks to start (0 is guess)" },
178            { "-ntomp",   FALSE, etINT, {&hw_opt.nthreads_omp},
179              "Number of OpenMP threads per MPI rank to start (0 is guess)" },
180            { "-ntomp_pme", FALSE, etINT, {&hw_opt.nthreads_omp_pme},
181              "Number of OpenMP threads per MPI rank to start (0 is -ntomp)" },
182            { "-pin",     FALSE, etENUM, {thread_aff_opt_choices},
183              "Whether mdrun should try to set thread affinities" },
184            { "-pinoffset", FALSE, etINT, {&hw_opt.core_pinning_offset},
185              "The lowest logical core number to which mdrun should pin the first thread" },
186            { "-pinstride", FALSE, etINT, {&hw_opt.core_pinning_stride},
187              "Pinning distance in logical cores for threads, use 0 to minimize the number of threads per physical core" },
188            { "-gpu_id",  FALSE, etSTR, {&gpuIdsAvailable},
189              "List of unique GPU device IDs available to use" },
190            { "-gputasks",  FALSE, etSTR, {&userGpuTaskAssignment},
191              "List of GPU device IDs, mapping each PP task on each node to a device" },
192            { "-ddcheck", FALSE, etBOOL, {&domdecOptions.checkBondedInteractions},
193              "Check for all bonded interactions with DD" },
194            { "-ddbondcomm", FALSE, etBOOL, {&domdecOptions.useBondedCommunication},
195              "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
196            { "-rdd",     FALSE, etREAL, {&domdecOptions.minimumCommunicationRange},
197              "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
198            { "-rcon",    FALSE, etREAL, {&domdecOptions.constraintCommunicationRange},
199              "Maximum distance for P-LINCS (nm), 0 is estimate" },
200            { "-dlb",     FALSE, etENUM, {dddlb_opt_choices},
201              "Dynamic load balancing (with DD)" },
202            { "-dds",     FALSE, etREAL, {&domdecOptions.dlbScaling},
203              "Fraction in (0,1) by whose reciprocal the initial DD cell size will be increased in order to "
204              "provide a margin in which dynamic load balancing can act while preserving the minimum cell size." },
205            { "-ddcsx",   FALSE, etSTR, {&domdecOptions.cellSizeX},
206              "HIDDENA string containing a vector of the relative sizes in the x "
207              "direction of the corresponding DD cells. Only effective with static "
208              "load balancing." },
209            { "-ddcsy",   FALSE, etSTR, {&domdecOptions.cellSizeY},
210              "HIDDENA string containing a vector of the relative sizes in the y "
211              "direction of the corresponding DD cells. Only effective with static "
212              "load balancing." },
213            { "-ddcsz",   FALSE, etSTR, {&domdecOptions.cellSizeZ},
214              "HIDDENA string containing a vector of the relative sizes in the z "
215              "direction of the corresponding DD cells. Only effective with static "
216              "load balancing." },
217            { "-gcom",    FALSE, etINT, {&mdrunOptions.globalCommunicationInterval},
218              "Global communication frequency" },
219            { "-nb",      FALSE, etENUM, {nbpu_opt_choices},
220              "Calculate non-bonded interactions on" },
221            { "-nstlist", FALSE, etINT, {&nstlist_cmdline},
222              "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
223            { "-tunepme", FALSE, etBOOL, {&mdrunOptions.tunePme},
224              "Optimize PME load between PP/PME ranks or GPU/CPU (only with the Verlet cut-off scheme)" },
225            { "-pme",     FALSE, etENUM, {pme_opt_choices},
226              "Perform PME calculations on" },
227            { "-pmefft", FALSE, etENUM, {pme_fft_opt_choices},
228              "Perform PME FFT calculations on" },
229            { "-bonded",     FALSE, etENUM, {bonded_opt_choices},
230              "Perform bonded calculations on" },
231            { "-v",       FALSE, etBOOL, {&mdrunOptions.verbose},
232              "Be loud and noisy" },
233            { "-pforce",  FALSE, etREAL, {&pforce},
234              "Print all forces larger than this (kJ/mol nm)" },
235            { "-reprod",  FALSE, etBOOL, {&mdrunOptions.reproducible},
236              "Try to avoid optimizations that affect binary reproducibility" },
237            { "-cpt",     FALSE, etREAL, {&mdrunOptions.checkpointOptions.period},
238              "Checkpoint interval (minutes)" },
239            { "-cpnum",   FALSE, etBOOL, {&mdrunOptions.checkpointOptions.keepAndNumberCheckpointFiles},
240              "Keep and number checkpoint files" },
241            { "-append",  FALSE, etBOOL, {&bTryToAppendFiles},
242              "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
243            { "-nsteps",  FALSE, etINT64, {&mdrunOptions.numStepsCommandline},
244              "Run this number of steps (-1 means infinite, -2 means use mdp option, smaller is invalid)" },
245            { "-maxh",   FALSE, etREAL, {&mdrunOptions.maximumHoursToRun},
246              "Terminate after 0.99 times this time (hours)" },
247            { "-replex",  FALSE, etINT, {&replExParams.exchangeInterval},
248              "Attempt replica exchange periodically with this period (steps)" },
249            { "-nex",  FALSE, etINT, {&replExParams.numExchanges},
250              "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion).  -nex zero or not specified gives neighbor replica exchange." },
251            { "-reseed",  FALSE, etINT, {&replExParams.randomSeed},
252              "Seed for replica exchange, -1 is generate a seed" },
253            { "-imdport",    FALSE, etINT, {&imdOptions.port},
254              "HIDDENIMD listening port" },
255            { "-imdwait",  FALSE, etBOOL, {&imdOptions.wait},
256              "HIDDENPause the simulation while no IMD client is connected" },
257            { "-imdterm",  FALSE, etBOOL, {&imdOptions.terminatable},
258              "HIDDENAllow termination of the simulation from IMD client" },
259            { "-imdpull",  FALSE, etBOOL, {&imdOptions.pull},
260              "HIDDENAllow pulling in the simulation from IMD client" },
261            { "-rerunvsite", FALSE, etBOOL, {&mdrunOptions.rerunConstructVsites},
262              "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
263            { "-confout", FALSE, etBOOL, {&mdrunOptions.writeConfout},
264              "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
265            { "-stepout", FALSE, etINT, {&mdrunOptions.verboseStepPrintInterval},
266              "HIDDENFrequency of writing the remaining wall clock time for the run" },
267            { "-resetstep", FALSE, etINT, {&mdrunOptions.timingOptions.resetStep},
268              "HIDDENReset cycle counters after these many time steps" },
269            { "-resethway", FALSE, etBOOL, {&mdrunOptions.timingOptions.resetHalfway},
270              "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
271        };
272        /*! \} */
273
274        //! Handle to communication object.
275        t_commrec        *cr = nullptr;
276        //! Multi-simulation object.
277        gmx_multisim_t   *ms = nullptr;
278
279        //! Parses the command-line input and prepares to start mdrun.
280        int updateFromCommandLine(int argc, char **argv, ArrayRef<const char *> desc);
281
282        ~LegacyMdrunOptions();
283};
284
285} // end namespace gmx
286
287#endif
288