Add TNG writing and reading support
[gromacs.git] / src / programs / mdrun / mdrun.cpp
blobec2f19d340705165c3a78098419404675ca9e438
1 /*
2 * This file is part of the GROMACS molecular simulation package.
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, 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.
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.
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.
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.
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.
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.
37 #include "mdrun_main.h"
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
43 #include <stdio.h>
45 #include "gromacs/legacyheaders/checkpoint.h"
46 #include "gromacs/legacyheaders/copyrite.h"
47 #include "gromacs/legacyheaders/gmx_fatal.h"
48 #include "gromacs/legacyheaders/macros.h"
49 #include "gromacs/legacyheaders/main.h"
50 #include "gromacs/legacyheaders/mdrun.h"
51 #include "gromacs/legacyheaders/network.h"
52 #include "gromacs/legacyheaders/readinp.h"
53 #include "gromacs/legacyheaders/typedefs.h"
55 #include "gromacs/commandline/pargs.h"
56 #include "gromacs/fileio/filenm.h"
58 int gmx_mdrun(int argc, char *argv[])
60 const char *desc[] = {
61 "[THISMODULE] is the main computational chemistry engine",
62 "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
63 "but it can also perform Stochastic Dynamics, Energy Minimization,",
64 "test particle insertion or (re)calculation of energies.",
65 "Normal mode analysis is another option. In this case [TT]mdrun[tt]",
66 "builds a Hessian matrix from single conformation.",
67 "For usual Normal Modes-like calculations, make sure that",
68 "the structure provided is properly energy-minimized.",
69 "The generated matrix can be diagonalized by [gmx-nmeig].[PAR]",
70 "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
71 "and distributes the topology over nodes if needed.",
72 "[TT]mdrun[tt] produces at least four output files.",
73 "A single log file ([TT]-g[tt]) is written, unless the option",
74 "[TT]-seppot[tt] is used, in which case each node writes a log file.",
75 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
76 "optionally forces.",
77 "The structure file ([TT]-c[tt]) contains the coordinates and",
78 "velocities of the last step.",
79 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
80 "pressure, etc, a lot of these things are also printed in the log file.",
81 "Optionally coordinates can be written to a compressed trajectory file",
82 "([TT]-x[tt]).[PAR]",
83 "The option [TT]-dhdl[tt] is only used when free energy calculation is",
84 "turned on.[PAR]",
85 "A simulation can be run in parallel using two different parallelization",
86 "schemes: MPI parallelization and/or OpenMP thread parallelization.",
87 "The MPI parallelization uses multiple processes when [TT]mdrun[tt] is",
88 "compiled with a normal MPI library or threads when [TT]mdrun[tt] is",
89 "compiled with the GROMACS built-in thread-MPI library. OpenMP threads",
90 "are supported when [TT]mdrun[tt] is compiled with OpenMP. Full OpenMP support",
91 "is only available with the Verlet cut-off scheme, with the (older)",
92 "group scheme only PME-only processes can use OpenMP parallelization.",
93 "In all cases [TT]mdrun[tt] will by default try to use all the available",
94 "hardware resources. With a normal MPI library only the options",
95 "[TT]-ntomp[tt] (with the Verlet cut-off scheme) and [TT]-ntomp_pme[tt],",
96 "for PME-only processes, can be used to control the number of threads.",
97 "With thread-MPI there are additional options [TT]-nt[tt], which sets",
98 "the total number of threads, and [TT]-ntmpi[tt], which sets the number",
99 "of thread-MPI threads.",
100 "Note that using combined MPI+OpenMP parallelization is almost always",
101 "slower than single parallelization, except at the scaling limit, where",
102 "especially OpenMP parallelization of PME reduces the communication cost.",
103 "OpenMP-only parallelization is much faster than MPI-only parallelization",
104 "on a single CPU(-die). Since we currently don't have proper hardware",
105 "topology detection, [TT]mdrun[tt] compiled with thread-MPI will only",
106 "automatically use OpenMP-only parallelization when you use up to 4",
107 "threads, up to 12 threads with Intel Nehalem/Westmere, or up to 16",
108 "threads with Intel Sandy Bridge or newer CPUs. Otherwise MPI-only",
109 "parallelization is used (except with GPUs, see below).",
110 "[PAR]",
111 "To quickly test the performance of the new Verlet cut-off scheme",
112 "with old [TT].tpr[tt] files, either on CPUs or CPUs+GPUs, you can use",
113 "the [TT]-testverlet[tt] option. This should not be used for production,",
114 "since it can slightly modify potentials and it will remove charge groups",
115 "making analysis difficult, as the [TT].tpr[tt] file will still contain",
116 "charge groups. For production simulations it is highly recommended",
117 "to specify [TT]cutoff-scheme = Verlet[tt] in the [TT].mdp[tt] file.",
118 "[PAR]",
119 "With GPUs (only supported with the Verlet cut-off scheme), the number",
120 "of GPUs should match the number of MPI processes or MPI threads,",
121 "excluding PME-only processes/threads. With thread-MPI, unless set on the command line, the number",
122 "of MPI threads will automatically be set to the number of GPUs detected.",
123 "To use a subset of the available GPUs, or to manually provide a mapping of",
124 "GPUs to PP ranks, you can use the [TT]-gpu_id[tt] option. The argument of [TT]-gpu_id[tt] is",
125 "a string of digits (without delimiter) representing device id-s of the GPUs to be used.",
126 "For example, \"[TT]02[tt]\" specifies using GPUs 0 and 2 in the first and second PP ranks per compute node",
127 "respectively. To select different sets of GPU-s",
128 "on different nodes of a compute cluster, use the [TT]GMX_GPU_ID[tt] environment",
129 "variable instead. The format for [TT]GMX_GPU_ID[tt] is identical to ",
130 "[TT]-gpu_id[tt], with the difference that an environment variable can have",
131 "different values on different compute nodes. Multiple MPI ranks on each node",
132 "can share GPUs. This is accomplished by specifying the id(s) of the GPU(s)",
133 "multiple times, e.g. \"[TT]0011[tt]\" for four ranks sharing two GPUs in this node.",
134 "This works within a single simulation, or a multi-simulation, with any form of MPI.",
135 "[PAR]",
136 "With the Verlet cut-off scheme and verlet-buffer-tolerance set,",
137 "the pair-list update interval nstlist can be chosen freely with",
138 "the option [TT]-nstlist[tt]. [TT]mdrun[tt] will then adjust",
139 "the pair-list cut-off to maintain accuracy.",
140 "By default [TT]mdrun[tt] will try to increase nstlist to improve",
141 "the performance. For CPU runs nstlist might increase to 20, for GPU",
142 "runs up till 40. But for medium to high parallelization or with",
143 "fast GPUs, a (user supplied) larger nstlist value can give much",
144 "better performance.",
145 "[PAR]",
146 "When using PME with separate PME nodes or with a GPU, the two major",
147 "compute tasks, the non-bonded force calculation and the PME calculation",
148 "run on different compute resources. If this load is not balanced,",
149 "some of the resources will be idle part of time. With the Verlet",
150 "cut-off scheme this load is automatically balanced when the PME load",
151 "is too high (but not when it is too low). This is done by scaling",
152 "the Coulomb cut-off and PME grid spacing by the same amount. In the first",
153 "few hundred steps different settings are tried and the fastest is chosen",
154 "for the rest of the simulation. This does not affect the accuracy of",
155 "the results, but it does affect the decomposition of the Coulomb energy",
156 "into particle and mesh contributions. The auto-tuning can be turned off",
157 "with the option [TT]-notunepme[tt].",
158 "[PAR]",
159 "[TT]mdrun[tt] pins (sets affinity of) threads to specific cores,",
160 "when all (logical) cores on a compute node are used by [TT]mdrun[tt],",
161 "even when no multi-threading is used,",
162 "as this usually results in significantly better performance.",
163 "If the queuing systems or the OpenMP library pinned threads, we honor",
164 "this and don't pin again, even though the layout may be sub-optimal.",
165 "If you want to have [TT]mdrun[tt] override an already set thread affinity",
166 "or pin threads when using less cores, use [TT]-pin on[tt].",
167 "With SMT (simultaneous multithreading), e.g. Intel Hyper-Threading,",
168 "there are multiple logical cores per physical core.",
169 "The option [TT]-pinstride[tt] sets the stride in logical cores for",
170 "pinning consecutive threads. Without SMT, 1 is usually the best choice.",
171 "With Intel Hyper-Threading 2 is best when using half or less of the",
172 "logical cores, 1 otherwise. The default value of 0 do exactly that:",
173 "it minimizes the threads per logical core, to optimize performance.",
174 "If you want to run multiple [TT]mdrun[tt] jobs on the same physical node,"
175 "you should set [TT]-pinstride[tt] to 1 when using all logical cores.",
176 "When running multiple [TT]mdrun[tt] (or other) simulations on the same physical",
177 "node, some simulations need to start pinning from a non-zero core",
178 "to avoid overloading cores; with [TT]-pinoffset[tt] you can specify",
179 "the offset in logical cores for pinning.",
180 "[PAR]",
181 "When [TT]mdrun[tt] is started using MPI with more than 1 process",
182 "or with thread-MPI with more than 1 thread, MPI parallelization is used.",
183 "By default domain decomposition is used, unless the [TT]-pd[tt]",
184 "option is set, which selects particle decomposition.",
185 "[PAR]",
186 "With domain decomposition, the spatial decomposition can be set",
187 "with option [TT]-dd[tt]. By default [TT]mdrun[tt] selects a good decomposition.",
188 "The user only needs to change this when the system is very inhomogeneous.",
189 "Dynamic load balancing is set with the option [TT]-dlb[tt],",
190 "which can give a significant performance improvement,",
191 "especially for inhomogeneous systems. The only disadvantage of",
192 "dynamic load balancing is that runs are no longer binary reproducible,",
193 "but in most cases this is not important.",
194 "By default the dynamic load balancing is automatically turned on",
195 "when the measured performance loss due to load imbalance is 5% or more.",
196 "At low parallelization these are the only important options",
197 "for domain decomposition.",
198 "At high parallelization the options in the next two sections",
199 "could be important for increasing the performace.",
200 "[PAR]",
201 "When PME is used with domain decomposition, separate nodes can",
202 "be assigned to do only the PME mesh calculation;",
203 "this is computationally more efficient starting at about 12 nodes.",
204 "The number of PME nodes is set with option [TT]-npme[tt],",
205 "this can not be more than half of the nodes.",
206 "By default [TT]mdrun[tt] makes a guess for the number of PME",
207 "nodes when the number of nodes is larger than 11 or performance wise",
208 "not compatible with the PME grid x dimension.",
209 "But the user should optimize npme. Performance statistics on this issue",
210 "are written at the end of the log file.",
211 "For good load balancing at high parallelization, the PME grid x and y",
212 "dimensions should be divisible by the number of PME nodes",
213 "(the simulation will run correctly also when this is not the case).",
214 "[PAR]",
215 "This section lists all options that affect the domain decomposition.",
216 "[PAR]",
217 "Option [TT]-rdd[tt] can be used to set the required maximum distance",
218 "for inter charge-group bonded interactions.",
219 "Communication for two-body bonded interactions below the non-bonded",
220 "cut-off distance always comes for free with the non-bonded communication.",
221 "Atoms beyond the non-bonded cut-off are only communicated when they have",
222 "missing bonded interactions; this means that the extra cost is minor",
223 "and nearly indepedent of the value of [TT]-rdd[tt].",
224 "With dynamic load balancing option [TT]-rdd[tt] also sets",
225 "the lower limit for the domain decomposition cell sizes.",
226 "By default [TT]-rdd[tt] is determined by [TT]mdrun[tt] based on",
227 "the initial coordinates. The chosen value will be a balance",
228 "between interaction range and communication cost.",
229 "[PAR]",
230 "When inter charge-group bonded interactions are beyond",
231 "the bonded cut-off distance, [TT]mdrun[tt] terminates with an error message.",
232 "For pair interactions and tabulated bonds",
233 "that do not generate exclusions, this check can be turned off",
234 "with the option [TT]-noddcheck[tt].",
235 "[PAR]",
236 "When constraints are present, option [TT]-rcon[tt] influences",
237 "the cell size limit as well.",
238 "Atoms connected by NC constraints, where NC is the LINCS order plus 1,",
239 "should not be beyond the smallest cell size. A error message is",
240 "generated when this happens and the user should change the decomposition",
241 "or decrease the LINCS order and increase the number of LINCS iterations.",
242 "By default [TT]mdrun[tt] estimates the minimum cell size required for P-LINCS",
243 "in a conservative fashion. For high parallelization it can be useful",
244 "to set the distance required for P-LINCS with the option [TT]-rcon[tt].",
245 "[PAR]",
246 "The [TT]-dds[tt] option sets the minimum allowed x, y and/or z scaling",
247 "of the cells with dynamic load balancing. [TT]mdrun[tt] will ensure that",
248 "the cells can scale down by at least this factor. This option is used",
249 "for the automated spatial decomposition (when not using [TT]-dd[tt])",
250 "as well as for determining the number of grid pulses, which in turn",
251 "sets the minimum allowed cell size. Under certain circumstances",
252 "the value of [TT]-dds[tt] might need to be adjusted to account for",
253 "high or low spatial inhomogeneity of the system.",
254 "[PAR]",
255 "The option [TT]-gcom[tt] can be used to only do global communication",
256 "every n steps.",
257 "This can improve performance for highly parallel simulations",
258 "where this global communication step becomes the bottleneck.",
259 "For a global thermostat and/or barostat the temperature",
260 "and/or pressure will also only be updated every [TT]-gcom[tt] steps.",
261 "By default it is set to the minimum of nstcalcenergy and nstlist.[PAR]",
262 "With [TT]-rerun[tt] an input trajectory can be given for which ",
263 "forces and energies will be (re)calculated. Neighbor searching will be",
264 "performed for every frame, unless [TT]nstlist[tt] is zero",
265 "(see the [TT].mdp[tt] file).[PAR]",
266 "ED (essential dynamics) sampling and/or additional flooding potentials",
267 "are switched on by using the [TT]-ei[tt] flag followed by an [TT].edi[tt]",
268 "file. The [TT].edi[tt] file can be produced with the [TT]make_edi[tt] tool",
269 "or by using options in the essdyn menu of the WHAT IF program.",
270 "[TT]mdrun[tt] produces a [TT].xvg[tt] output file that",
271 "contains projections of positions, velocities and forces onto selected",
272 "eigenvectors.[PAR]",
273 "When user-defined potential functions have been selected in the",
274 "[TT].mdp[tt] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]",
275 "a formatted table with potential functions. The file is read from",
276 "either the current directory or from the [TT]GMXLIB[tt] directory.",
277 "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,",
278 "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with",
279 "normal Coulomb.",
280 "When pair interactions are present, a separate table for pair interaction",
281 "functions is read using the [TT]-tablep[tt] option.[PAR]",
282 "When tabulated bonded functions are present in the topology,",
283 "interaction functions are read using the [TT]-tableb[tt] option.",
284 "For each different tabulated interaction type the table file name is",
285 "modified in a different way: before the file extension an underscore is",
286 "appended, then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals",
287 "and finally the table number of the interaction type.[PAR]",
288 "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
289 "coordinates and forces when pulling is selected",
290 "in the [TT].mdp[tt] file.[PAR]",
291 "With [TT]-multi[tt] or [TT]-multidir[tt], multiple systems can be ",
292 "simulated in parallel.",
293 "As many input files/directories are required as the number of systems. ",
294 "The [TT]-multidir[tt] option takes a list of directories (one for each ",
295 "system) and runs in each of them, using the input/output file names, ",
296 "such as specified by e.g. the [TT]-s[tt] option, relative to these ",
297 "directories.",
298 "With [TT]-multi[tt], the system number is appended to the run input ",
299 "and each output filename, for instance [TT]topol.tpr[tt] becomes",
300 "[TT]topol0.tpr[tt], [TT]topol1.tpr[tt] etc.",
301 "The number of nodes per system is the total number of nodes",
302 "divided by the number of systems.",
303 "One use of this option is for NMR refinement: when distance",
304 "or orientation restraints are present these can be ensemble averaged",
305 "over all the systems.[PAR]",
306 "With [TT]-replex[tt] replica exchange is attempted every given number",
307 "of steps. The number of replicas is set with the [TT]-multi[tt] or ",
308 "[TT]-multidir[tt] option, described above.",
309 "All run input files should use a different coupling temperature,",
310 "the order of the files is not important. The random seed is set with",
311 "[TT]-reseed[tt]. The velocities are scaled and neighbor searching",
312 "is performed after every exchange.[PAR]",
313 "Finally some experimental algorithms can be tested when the",
314 "appropriate options have been given. Currently under",
315 "investigation are: polarizability.",
316 "[PAR]",
317 "The option [TT]-membed[tt] does what used to be g_membed, i.e. embed",
318 "a protein into a membrane. The data file should contain the options",
319 "that where passed to g_membed before. The [TT]-mn[tt] and [TT]-mp[tt]",
320 "both apply to this as well.",
321 "[PAR]",
322 "The option [TT]-pforce[tt] is useful when you suspect a simulation",
323 "crashes due to too large forces. With this option coordinates and",
324 "forces of atoms with a force larger than a certain value will",
325 "be printed to stderr.",
326 "[PAR]",
327 "Checkpoints containing the complete state of the system are written",
328 "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
329 "unless option [TT]-cpt[tt] is set to -1.",
330 "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
331 "make sure that a recent state of the system is always available,",
332 "even when the simulation is terminated while writing a checkpoint.",
333 "With [TT]-cpnum[tt] all checkpoint files are kept and appended",
334 "with the step number.",
335 "A simulation can be continued by reading the full state from file",
336 "with option [TT]-cpi[tt]. This option is intelligent in the way that",
337 "if no checkpoint file is found, Gromacs just assumes a normal run and",
338 "starts from the first step of the [TT].tpr[tt] file. By default the output",
339 "will be appending to the existing output files. The checkpoint file",
340 "contains checksums of all output files, such that you will never",
341 "loose data when some output files are modified, corrupt or removed.",
342 "There are three scenarios with [TT]-cpi[tt]:[PAR]",
343 "[TT]*[tt] no files with matching names are present: new output files are written[PAR]",
344 "[TT]*[tt] all files are present with names and checksums matching those stored",
345 "in the checkpoint file: files are appended[PAR]",
346 "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]",
347 "With [TT]-noappend[tt] new output files are opened and the simulation",
348 "part number is added to all output file names.",
349 "Note that in all cases the checkpoint file itself is not renamed",
350 "and will be overwritten, unless its name does not match",
351 "the [TT]-cpo[tt] option.",
352 "[PAR]",
353 "With checkpointing the output is appended to previously written",
354 "output files, unless [TT]-noappend[tt] is used or none of the previous",
355 "output files are present (except for the checkpoint file).",
356 "The integrity of the files to be appended is verified using checksums",
357 "which are stored in the checkpoint file. This ensures that output can",
358 "not be mixed up or corrupted due to file appending. When only some",
359 "of the previous output files are present, a fatal error is generated",
360 "and no old output files are modified and no new output files are opened.",
361 "The result with appending will be the same as from a single run.",
362 "The contents will be binary identical, unless you use a different number",
363 "of nodes or dynamic load balancing or the FFT library uses optimizations",
364 "through timing.",
365 "[PAR]",
366 "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
367 "file is written at the first neighbor search step where the run time",
368 "exceeds [TT]-maxh[tt]*0.99 hours.",
369 "[PAR]",
370 "When [TT]mdrun[tt] receives a TERM signal, it will set nsteps to the current",
371 "step plus one. When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is",
372 "pressed), it will stop after the next neighbor search step ",
373 "(with nstlist=0 at the next step).",
374 "In both cases all the usual output will be written to file.",
375 "When running with MPI, a signal to one of the [TT]mdrun[tt] processes",
376 "is sufficient, this signal should not be sent to mpirun or",
377 "the [TT]mdrun[tt] process that is the parent of the others.",
378 "[PAR]",
379 "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
381 t_commrec *cr;
382 t_filenm fnm[] = {
383 { efTPX, NULL, NULL, ffREAD },
384 { efTRN, "-o", NULL, ffWRITE },
385 { efCOMPRESSED, "-x", NULL, ffOPTWR },
386 { efCPT, "-cpi", NULL, ffOPTRD },
387 { efCPT, "-cpo", NULL, ffOPTWR },
388 { efSTO, "-c", "confout", ffWRITE },
389 { efEDR, "-e", "ener", ffWRITE },
390 { efLOG, "-g", "md", ffWRITE },
391 { efXVG, "-dhdl", "dhdl", ffOPTWR },
392 { efXVG, "-field", "field", ffOPTWR },
393 { efXVG, "-table", "table", ffOPTRD },
394 { efXVG, "-tabletf", "tabletf", ffOPTRD },
395 { efXVG, "-tablep", "tablep", ffOPTRD },
396 { efXVG, "-tableb", "table", ffOPTRD },
397 { efTRX, "-rerun", "rerun", ffOPTRD },
398 { efXVG, "-tpi", "tpi", ffOPTWR },
399 { efXVG, "-tpid", "tpidist", ffOPTWR },
400 { efEDI, "-ei", "sam", ffOPTRD },
401 { efXVG, "-eo", "edsam", ffOPTWR },
402 { efXVG, "-devout", "deviatie", ffOPTWR },
403 { efXVG, "-runav", "runaver", ffOPTWR },
404 { efXVG, "-px", "pullx", ffOPTWR },
405 { efXVG, "-pf", "pullf", ffOPTWR },
406 { efXVG, "-ro", "rotation", ffOPTWR },
407 { efLOG, "-ra", "rotangles", ffOPTWR },
408 { efLOG, "-rs", "rotslabs", ffOPTWR },
409 { efLOG, "-rt", "rottorque", ffOPTWR },
410 { efMTX, "-mtx", "nm", ffOPTWR },
411 { efNDX, "-dn", "dipole", ffOPTWR },
412 { efRND, "-multidir", NULL, ffOPTRDMULT},
413 { efDAT, "-membed", "membed", ffOPTRD },
414 { efTOP, "-mp", "membed", ffOPTRD },
415 { efNDX, "-mn", "membed", ffOPTRD }
417 #define NFILE asize(fnm)
419 /* Command line options ! */
420 gmx_bool bPartDec = FALSE;
421 gmx_bool bDDBondCheck = TRUE;
422 gmx_bool bDDBondComm = TRUE;
423 gmx_bool bTunePME = TRUE;
424 gmx_bool bTestVerlet = FALSE;
425 gmx_bool bVerbose = FALSE;
426 gmx_bool bCompact = TRUE;
427 gmx_bool bSepPot = FALSE;
428 gmx_bool bRerunVSite = FALSE;
429 gmx_bool bConfout = TRUE;
430 gmx_bool bReproducible = FALSE;
432 int npme = -1;
433 int nstlist = 0;
434 int nmultisim = 0;
435 int nstglobalcomm = -1;
436 int repl_ex_nst = 0;
437 int repl_ex_seed = -1;
438 int repl_ex_nex = 0;
439 int nstepout = 100;
440 int resetstep = -1;
441 gmx_int64_t nsteps = -2; /* the value -2 means that the mdp option will be used */
443 rvec realddxyz = {0, 0, 0};
444 const char *ddno_opt[ddnoNR+1] =
445 { NULL, "interleave", "pp_pme", "cartesian", NULL };
446 const char *dddlb_opt[] =
447 { NULL, "auto", "no", "yes", NULL };
448 const char *thread_aff_opt[threadaffNR+1] =
449 { NULL, "auto", "on", "off", NULL };
450 const char *nbpu_opt[] =
451 { NULL, "auto", "cpu", "gpu", "gpu_cpu", NULL };
452 real rdd = 0.0, rconstr = 0.0, dlb_scale = 0.8, pforce = -1;
453 char *ddcsx = NULL, *ddcsy = NULL, *ddcsz = NULL;
454 real cpt_period = 15.0, max_hours = -1;
455 gmx_bool bAppendFiles = TRUE;
456 gmx_bool bKeepAndNumCPT = FALSE;
457 gmx_bool bResetCountersHalfWay = FALSE;
458 output_env_t oenv = NULL;
459 const char *deviceOptions = "";
461 /* Non transparent initialization of a complex gmx_hw_opt_t struct.
462 * But unfortunately we are not allowed to call a function here,
463 * since declarations follow below.
465 gmx_hw_opt_t hw_opt = {
466 0, 0, 0, 0, threadaffSEL, 0, 0,
467 { NULL, FALSE, 0, NULL }
470 t_pargs pa[] = {
472 { "-pd", FALSE, etBOOL, {&bPartDec},
473 "Use particle decompostion" },
474 { "-dd", FALSE, etRVEC, {&realddxyz},
475 "Domain decomposition grid, 0 is optimize" },
476 { "-ddorder", FALSE, etENUM, {ddno_opt},
477 "DD node order" },
478 { "-npme", FALSE, etINT, {&npme},
479 "Number of separate nodes to be used for PME, -1 is guess" },
480 { "-nt", FALSE, etINT, {&hw_opt.nthreads_tot},
481 "Total number of threads to start (0 is guess)" },
482 { "-ntmpi", FALSE, etINT, {&hw_opt.nthreads_tmpi},
483 "Number of thread-MPI threads to start (0 is guess)" },
484 { "-ntomp", FALSE, etINT, {&hw_opt.nthreads_omp},
485 "Number of OpenMP threads per MPI process/thread to start (0 is guess)" },
486 { "-ntomp_pme", FALSE, etINT, {&hw_opt.nthreads_omp_pme},
487 "Number of OpenMP threads per MPI process/thread to start (0 is -ntomp)" },
488 { "-pin", FALSE, etENUM, {thread_aff_opt},
489 "Fix threads (or processes) to specific cores" },
490 { "-pinoffset", FALSE, etINT, {&hw_opt.core_pinning_offset},
491 "The starting logical core number for pinning to cores; used to avoid pinning threads from different mdrun instances to the same core" },
492 { "-pinstride", FALSE, etINT, {&hw_opt.core_pinning_stride},
493 "Pinning distance in logical cores for threads, use 0 to minimize the number of threads per physical core" },
494 { "-gpu_id", FALSE, etSTR, {&hw_opt.gpu_opt.gpu_id},
495 "List of GPU device id-s to use, specifies the per-node PP rank to GPU mapping" },
496 { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck},
497 "Check for all bonded interactions with DD" },
498 { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm},
499 "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
500 { "-rdd", FALSE, etREAL, {&rdd},
501 "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
502 { "-rcon", FALSE, etREAL, {&rconstr},
503 "Maximum distance for P-LINCS (nm), 0 is estimate" },
504 { "-dlb", FALSE, etENUM, {dddlb_opt},
505 "Dynamic load balancing (with DD)" },
506 { "-dds", FALSE, etREAL, {&dlb_scale},
507 "Minimum allowed dlb scaling of the DD cell size" },
508 { "-ddcsx", FALSE, etSTR, {&ddcsx},
509 "HIDDENThe DD cell sizes in x" },
510 { "-ddcsy", FALSE, etSTR, {&ddcsy},
511 "HIDDENThe DD cell sizes in y" },
512 { "-ddcsz", FALSE, etSTR, {&ddcsz},
513 "HIDDENThe DD cell sizes in z" },
514 { "-gcom", FALSE, etINT, {&nstglobalcomm},
515 "Global communication frequency" },
516 { "-nb", FALSE, etENUM, {&nbpu_opt},
517 "Calculate non-bonded interactions on" },
518 { "-nstlist", FALSE, etINT, {&nstlist},
519 "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
520 { "-tunepme", FALSE, etBOOL, {&bTunePME},
521 "Optimize PME load between PP/PME nodes or GPU/CPU" },
522 { "-testverlet", FALSE, etBOOL, {&bTestVerlet},
523 "Test the Verlet non-bonded scheme" },
524 { "-v", FALSE, etBOOL, {&bVerbose},
525 "Be loud and noisy" },
526 { "-compact", FALSE, etBOOL, {&bCompact},
527 "Write a compact log file" },
528 { "-seppot", FALSE, etBOOL, {&bSepPot},
529 "Write separate V and dVdl terms for each interaction type and node to the log file(s)" },
530 { "-pforce", FALSE, etREAL, {&pforce},
531 "Print all forces larger than this (kJ/mol nm)" },
532 { "-reprod", FALSE, etBOOL, {&bReproducible},
533 "Try to avoid optimizations that affect binary reproducibility" },
534 { "-cpt", FALSE, etREAL, {&cpt_period},
535 "Checkpoint interval (minutes)" },
536 { "-cpnum", FALSE, etBOOL, {&bKeepAndNumCPT},
537 "Keep and number checkpoint files" },
538 { "-append", FALSE, etBOOL, {&bAppendFiles},
539 "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
540 { "-nsteps", FALSE, etINT64, {&nsteps},
541 "Run this number of steps, overrides .mdp file option" },
542 { "-maxh", FALSE, etREAL, {&max_hours},
543 "Terminate after 0.99 times this time (hours)" },
544 { "-multi", FALSE, etINT, {&nmultisim},
545 "Do multiple simulations in parallel" },
546 { "-replex", FALSE, etINT, {&repl_ex_nst},
547 "Attempt replica exchange periodically with this period (steps)" },
548 { "-nex", FALSE, etINT, {&repl_ex_nex},
549 "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion). -nex zero or not specified gives neighbor replica exchange." },
550 { "-reseed", FALSE, etINT, {&repl_ex_seed},
551 "Seed for replica exchange, -1 is generate a seed" },
552 { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
553 "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
554 { "-confout", FALSE, etBOOL, {&bConfout},
555 "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
556 { "-stepout", FALSE, etINT, {&nstepout},
557 "HIDDENFrequency of writing the remaining wall clock time for the run" },
558 { "-resetstep", FALSE, etINT, {&resetstep},
559 "HIDDENReset cycle counters after these many time steps" },
560 { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
561 "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
563 unsigned long Flags, PCA_Flags;
564 ivec ddxyz;
565 int dd_node_order;
566 gmx_bool bAddPart;
567 FILE *fplog, *fpmulti;
568 int sim_part, sim_part_fn;
569 const char *part_suffix = ".part";
570 char suffix[STRLEN];
571 int rc;
572 char **multidir = NULL;
575 cr = init_commrec();
577 PCA_Flags = (PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET));
579 /* Comment this in to do fexist calls only on master
580 * works not with rerun or tables at the moment
581 * also comment out the version of init_forcerec in md.c
582 * with NULL instead of opt2fn
585 if (!MASTER(cr))
587 PCA_Flags |= PCA_NOT_READ_NODE;
591 if (!parse_common_args(&argc, argv, PCA_Flags, NFILE, fnm, asize(pa), pa,
592 asize(desc), desc, 0, NULL, &oenv))
594 return 0;
598 /* we set these early because they might be used in init_multisystem()
599 Note that there is the potential for npme>nnodes until the number of
600 threads is set later on, if there's thread parallelization. That shouldn't
601 lead to problems. */
602 dd_node_order = nenum(ddno_opt);
603 cr->npmenodes = npme;
605 hw_opt.thread_affinity = nenum(thread_aff_opt);
607 /* now check the -multi and -multidir option */
608 if (opt2bSet("-multidir", NFILE, fnm))
610 if (nmultisim > 0)
612 gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive.");
614 nmultisim = opt2fns(&multidir, "-multidir", NFILE, fnm);
618 if (repl_ex_nst != 0 && nmultisim < 2)
620 gmx_fatal(FARGS, "Need at least two replicas for replica exchange (option -multi)");
623 if (repl_ex_nex < 0)
625 gmx_fatal(FARGS, "Replica exchange number of exchanges needs to be positive");
628 if (nmultisim > 1)
630 #ifndef GMX_THREAD_MPI
631 gmx_bool bParFn = (multidir == NULL);
632 init_multisystem(cr, nmultisim, multidir, NFILE, fnm, bParFn);
633 #else
634 gmx_fatal(FARGS, "mdrun -multi is not supported with the thread library. "
635 "Please compile GROMACS with MPI support");
636 #endif
639 bAddPart = !bAppendFiles;
641 /* Check if there is ANY checkpoint file available */
642 sim_part = 1;
643 sim_part_fn = sim_part;
644 if (opt2bSet("-cpi", NFILE, fnm))
646 if (bSepPot && bAppendFiles)
648 gmx_fatal(FARGS, "Output file appending is not supported with -seppot");
651 bAppendFiles =
652 read_checkpoint_simulation_part(opt2fn_master("-cpi", NFILE,
653 fnm, cr),
654 &sim_part_fn, NULL, cr,
655 bAppendFiles, NFILE, fnm,
656 part_suffix, &bAddPart);
657 if (sim_part_fn == 0 && MULTIMASTER(cr))
659 fprintf(stdout, "No previous checkpoint file present, assuming this is a new run.\n");
661 else
663 sim_part = sim_part_fn + 1;
666 if (MULTISIM(cr) && MASTER(cr))
668 if (MULTIMASTER(cr))
670 /* Log file is not yet available, so if there's a
671 * problem we can only write to stderr. */
672 fpmulti = stderr;
674 else
676 fpmulti = NULL;
678 check_multi_int(fpmulti, cr->ms, sim_part, "simulation part", TRUE);
681 else
683 bAppendFiles = FALSE;
686 if (!bAppendFiles)
688 sim_part_fn = sim_part;
691 if (bAddPart)
693 /* Rename all output files (except checkpoint files) */
694 /* create new part name first (zero-filled) */
695 sprintf(suffix, "%s%04d", part_suffix, sim_part_fn);
697 add_suffix_to_output_names(fnm, NFILE, suffix);
698 if (MULTIMASTER(cr))
700 fprintf(stdout, "Checkpoint file is from part %d, new output files will be suffixed '%s'.\n", sim_part-1, suffix);
704 Flags = opt2bSet("-rerun", NFILE, fnm) ? MD_RERUN : 0;
705 Flags = Flags | (bSepPot ? MD_SEPPOT : 0);
706 Flags = Flags | (bPartDec ? MD_PARTDEC : 0);
707 Flags = Flags | (bDDBondCheck ? MD_DDBONDCHECK : 0);
708 Flags = Flags | (bDDBondComm ? MD_DDBONDCOMM : 0);
709 Flags = Flags | (bTunePME ? MD_TUNEPME : 0);
710 Flags = Flags | (bTestVerlet ? MD_TESTVERLET : 0);
711 Flags = Flags | (bConfout ? MD_CONFOUT : 0);
712 Flags = Flags | (bRerunVSite ? MD_RERUN_VSITE : 0);
713 Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
714 Flags = Flags | (bAppendFiles ? MD_APPENDFILES : 0);
715 Flags = Flags | (opt2parg_bSet("-append", asize(pa), pa) ? MD_APPENDFILESSET : 0);
716 Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0);
717 Flags = Flags | (sim_part > 1 ? MD_STARTFROMCPT : 0);
718 Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
721 /* We postpone opening the log file if we are appending, so we can
722 first truncate the old log file and append to the correct position
723 there instead. */
724 if ((MASTER(cr) || bSepPot) && !bAppendFiles)
726 gmx_log_open(ftp2fn(efLOG, NFILE, fnm), cr,
727 !bSepPot, Flags & MD_APPENDFILES, &fplog);
728 please_cite(fplog, "Hess2008b");
729 please_cite(fplog, "Spoel2005a");
730 please_cite(fplog, "Lindahl2001a");
731 please_cite(fplog, "Berendsen95a");
733 else if (!MASTER(cr) && bSepPot)
735 gmx_log_open(ftp2fn(efLOG, NFILE, fnm), cr, !bSepPot, Flags, &fplog);
737 else
739 fplog = NULL;
742 ddxyz[XX] = (int)(realddxyz[XX] + 0.5);
743 ddxyz[YY] = (int)(realddxyz[YY] + 0.5);
744 ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5);
746 rc = mdrunner(&hw_opt, fplog, cr, NFILE, fnm, oenv, bVerbose, bCompact,
747 nstglobalcomm, ddxyz, dd_node_order, rdd, rconstr,
748 dddlb_opt[0], dlb_scale, ddcsx, ddcsy, ddcsz,
749 nbpu_opt[0], nstlist,
750 nsteps, nstepout, resetstep,
751 nmultisim, repl_ex_nst, repl_ex_nex, repl_ex_seed,
752 pforce, cpt_period, max_hours, deviceOptions, Flags);
754 /* Log file has to be closed in mdrunner if we are appending to it
755 (fplog not set here) */
756 if (MASTER(cr) && !bAppendFiles)
758 gmx_log_close(fplog);
761 return rc;