added Verlet scheme and NxN non-bonded functionality
[gromacs.git] / src / kernel / mdrun.c
blob316b485143b3617e862f328ac00a05c7dc01c117
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
40 #include "typedefs.h"
41 #include "macros.h"
42 #include "copyrite.h"
43 #include "main.h"
44 #include "statutil.h"
45 #include "smalloc.h"
46 #include "futil.h"
47 #include "smalloc.h"
48 #include "edsam.h"
49 #include "mdrun.h"
50 #include "xmdrun.h"
51 #include "checkpoint.h"
52 #ifdef GMX_THREAD_MPI
53 #include "thread_mpi.h"
54 #endif
56 /* afm stuf */
57 #include "pull.h"
59 int main(int argc,char *argv[])
61 const char *desc[] = {
62 #ifdef GMX_OPENMM
63 "This is an experimental release of GROMACS for accelerated",
64 "Molecular Dynamics simulations on GPU processors. Support is provided",
65 "by the OpenMM library (https://simtk.org/home/openmm).[PAR]",
66 "*Warning*[BR]",
67 "This release is targeted at developers and advanced users and",
68 "care should be taken before production use. The following should be",
69 "noted before using the program:[PAR]",
70 " * The current release runs only on modern nVidia GPU hardware with CUDA support.",
71 "Make sure that the necessary CUDA drivers and libraries for your operating system",
72 "are already installed. The CUDA SDK also should be installed in order to compile",
73 "the program from source (http://www.nvidia.com/object/cuda_home.html).[PAR]",
74 " * Multiple GPU cards are not supported.[PAR]",
75 " * Only a small subset of the GROMACS features and options are supported on the GPUs.",
76 "See below for a detailed list.[PAR]",
77 " * Consumer level GPU cards are known to often have problems with faulty memory.",
78 "It is recommended that a full memory check of the cards is done at least once",
79 "(for example, using the memtest=full option).",
80 "A partial memory check (for example, memtest=15) before and",
81 "after the simulation run would help spot",
82 "problems resulting from processor overheating.[PAR]",
83 " * The maximum size of the simulated systems depends on the available",
84 "GPU memory,for example, a GTX280 with 1GB memory has been tested with systems",
85 "of up to about 100,000 atoms.[PAR]",
86 " * In order to take a full advantage of the GPU platform features, many algorithms",
87 "have been implemented in a very different way than they are on the CPUs.",
88 "Therefore numercal correspondence between properties of the state of",
89 "simulated systems should not be expected. Moreover, the values will likely vary",
90 "when simulations are done on different GPU hardware.[PAR]",
91 " * Frequent retrieval of system state information such as",
92 "trajectory coordinates and energies can greatly influence the performance",
93 "of the program due to slow CPU<->GPU memory transfer speed.[PAR]",
94 " * MD algorithms are complex, and although the Gromacs code is highly tuned for them,",
95 "they often do not translate very well onto the streaming architetures.",
96 "Realistic expectations about the achievable speed-up from test with GTX280:",
97 "For small protein systems in implicit solvent using all-vs-all kernels the acceleration",
98 "can be as high as 20 times, but in most other setups involving cutoffs and PME the",
99 "acceleration is usually only ~4 times relative to a 3GHz CPU.[PAR]",
100 "Supported features:[PAR]",
101 " * Integrators: md/md-vv/md-vv-avek, sd/sd1 and bd.\n",
102 " * Long-range interactions (option coulombtype): Reaction-Field, Ewald, PME, and cut-off (for Implicit Solvent only)\n",
103 " * Temperature control: Supported only with the md/md-vv/md-vv-avek, sd/sd1 and bd integrators.\n",
104 " * Pressure control: Supported.\n",
105 " * Implicit solvent: Supported.\n",
106 "A detailed description can be found on the GROMACS website:\n",
107 "http://www.gromacs.org/gpu[PAR]",
108 /* From the original mdrun documentaion */
109 "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
110 "and distributes the topology over nodes if needed.",
111 "[TT]mdrun[tt] produces at least four output files.",
112 "A single log file ([TT]-g[tt]) is written, unless the option",
113 "[TT]-seppot[tt] is used, in which case each node writes a log file.",
114 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
115 "optionally forces.",
116 "The structure file ([TT]-c[tt]) contains the coordinates and",
117 "velocities of the last step.",
118 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
119 "pressure, etc, a lot of these things are also printed in the log file.",
120 "Optionally coordinates can be written to a compressed trajectory file",
121 "([TT]-x[tt]).[PAR]",
122 /* openmm specific information */
123 "Usage with OpenMM:[BR]",
124 "[TT]mdrun -device \"OpenMM:platform=Cuda,memtest=15,deviceid=0,force-device=no\"[tt][PAR]",
125 "Options:[PAR]",
126 " [TT]platform[tt] = Cuda\t\t:\tThe only available value. OpenCL support will be available in future.\n",
127 " [TT]memtest[tt] = 15\t\t:\tRun a partial, random GPU memory test for the given amount of seconds. A full test",
128 "(recommended!) can be run with \"memtest=full\". Memory testing can be disabled with \"memtest=off\".\n",
129 " [TT]deviceid[tt] = 0\t\t:\tSpecify the target device when multiple cards are present.",
130 "Only one card can be used at any given time though.\n",
131 " [TT]force-device[tt] = no\t\t:\tIf set to \"yes\" [TT]mdrun[tt] will be forced to execute on",
132 "hardware that is not officially supported. GPU acceleration can also be achieved on older",
133 "but Cuda capable cards, although the simulation might be too slow, and the memory limits too strict.",
134 #else
135 "The [TT]mdrun[tt] program is the main computational chemistry engine",
136 "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
137 "but it can also perform Stochastic Dynamics, Energy Minimization,",
138 "test particle insertion or (re)calculation of energies.",
139 "Normal mode analysis is another option. In this case [TT]mdrun[tt]",
140 "builds a Hessian matrix from single conformation.",
141 "For usual Normal Modes-like calculations, make sure that",
142 "the structure provided is properly energy-minimized.",
143 "The generated matrix can be diagonalized by [TT]g_nmeig[tt].[PAR]",
144 "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
145 "and distributes the topology over nodes if needed.",
146 "[TT]mdrun[tt] produces at least four output files.",
147 "A single log file ([TT]-g[tt]) is written, unless the option",
148 "[TT]-seppot[tt] is used, in which case each node writes a log file.",
149 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
150 "optionally forces.",
151 "The structure file ([TT]-c[tt]) contains the coordinates and",
152 "velocities of the last step.",
153 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
154 "pressure, etc, a lot of these things are also printed in the log file.",
155 "Optionally coordinates can be written to a compressed trajectory file",
156 "([TT]-x[tt]).[PAR]",
157 "The option [TT]-dhdl[tt] is only used when free energy calculation is",
158 "turned on.[PAR]",
159 "A simulation can be run in parallel using two different parallelization",
160 "schemes: MPI parallelization and/or OpenMP thread parallelization.",
161 "The MPI parallelization uses multiple processes when [TT]mdrun[tt] is",
162 "compiled with a normal MPI library or threads when [TT]mdrun[tt] is",
163 "compiled with the GROMACS built-in thread-MPI library. OpenMP threads",
164 "are supported when mdrun is compiled with OpenMP. Full OpenMP support",
165 "is only available with the Verlet cut-off scheme, with the (older)",
166 "group scheme only PME-only processes can use OpenMP parallelization.",
167 "In all cases [TT]mdrun[tt] will by default try to use all the available",
168 "hardware resources. With a normal MPI library only the options",
169 "[TT]-ntomp[tt] (with the Verlet cut-off scheme) and [TT]-ntomp_pme[tt],",
170 "for PME-only processes, can be used to control the number of threads.",
171 "With thread-MPI there are additional options [TT]-nt[tt], which sets",
172 "the total number of threads, and [TT]-ntmpi[tt], which sets the number",
173 "of thread-MPI threads.",
174 "Note that using combined MPI+OpenMP parallelization is almost always",
175 "slower than single parallelization, except at the scaling limit, where",
176 "especially OpenMP parallelization of PME reduces the communication cost.",
177 "[PAR]",
178 "To quickly test the performance of the new Verlet cut-off scheme",
179 "with old [TT].tpr[tt] files, either on CPUs or CPUs+GPUs, you can use",
180 "the [TT]-testverlet[tt] option. This should not be used for production,",
181 "since it can slightly modify potentials and it will remove charge groups",
182 "making analysis difficult, as the [TT].tpr[tt] file will still contain",
183 "charge groups. For production simulations it is highly recommended",
184 "to specify [TT]cutoff-scheme = Verlet[tt] in the [TT].mdp[tt] file.",
185 "[PAR]",
186 "With GPUs (only supported with the Verlet cut-off scheme), the number",
187 "of GPUs should match the number of MPI processes or MPI threads,",
188 "excluding PME-only processes/threads. With thread-MPI the number",
189 "of MPI threads will automatically be set to the number of GPUs detected.",
190 "When you want to use a subset of the available GPUs, you can use",
191 "the [TT]-gpu_id[tt] option, where GPU id's are passed as a string,",
192 "e.g. 02 for using GPUs 0 and 2. When you want different GPU id's",
193 "on different nodes of a compute cluster, use the GMX_GPU_ID environment",
194 "variable instead. The format for GMX_GPU_ID is identical to ",
195 "[TT]-gpu_id[tt], but an environment variable can have different values",
196 "on different nodes of a cluster.",
197 "[PAR]",
198 "When using PME with separate PME nodes or with a GPU, the two major",
199 "compute tasks, the non-bonded force calculation and the PME calculation",
200 "run on different compute resources. If this load is not balanced,",
201 "some of the resources will be idle part of time. With the Verlet",
202 "cut-off scheme this load is automatically balanced when the PME load",
203 "is too high (but not when it is too low). This is done by scaling",
204 "the Coulomb cut-off and PME grid spacing by the same amount. In the first",
205 "few hundred steps different settings are tried and the fastest is chosen",
206 "for the rest of the simulation. This does not affect the accuracy of",
207 "the results, but it does affect the decomposition of the Coulomb energy",
208 "into particle and mesh contributions. The auto-tuning can be turned off",
209 "with the option [TT]-notunepme[tt].",
210 "[PAR]",
211 "When compiled with OpenMP on Linux, [TT]mdrun[tt] pins threads to cores,",
212 "as this usually results in significantly better performance.",
213 "If you don't want this, use [TT]-nopin[tt].",
214 "With Intel CPUs with hyper-threading enabled, you should pin",
215 "consecutive threads to the same physical core for optimal",
216 "performance when you use virtual cores. This is done automatically",
217 "when you use more than half of the virtual cores. It can also be set",
218 "manually with [TT]-pinht[tt], e.g. for running multiple simulations",
219 "on one compute node.",
220 "When running multiple mdrun (or other) simulations on the same physical",
221 "node, some simulations need to start pinning from a non-zero core",
222 "to avoid overloading cores; with [TT]-pinoffset[tt] you can specify",
223 "the offset in (physical) cores for pinning.",
224 "[PAR]",
225 "When [TT]mdrun[tt] is started using MPI with more than 1 process",
226 "or with thread-MPI with more than 1 thread, MPI parallelization is used.",
227 "By default domain decomposition is used, unless the [TT]-pd[tt]",
228 "option is set, which selects particle decomposition.",
229 "[PAR]",
230 "With domain decomposition, the spatial decomposition can be set",
231 "with option [TT]-dd[tt]. By default [TT]mdrun[tt] selects a good decomposition.",
232 "The user only needs to change this when the system is very inhomogeneous.",
233 "Dynamic load balancing is set with the option [TT]-dlb[tt],",
234 "which can give a significant performance improvement,",
235 "especially for inhomogeneous systems. The only disadvantage of",
236 "dynamic load balancing is that runs are no longer binary reproducible,",
237 "but in most cases this is not important.",
238 "By default the dynamic load balancing is automatically turned on",
239 "when the measured performance loss due to load imbalance is 5% or more.",
240 "At low parallelization these are the only important options",
241 "for domain decomposition.",
242 "At high parallelization the options in the next two sections",
243 "could be important for increasing the performace.",
244 "[PAR]",
245 "When PME is used with domain decomposition, separate nodes can",
246 "be assigned to do only the PME mesh calculation;",
247 "this is computationally more efficient starting at about 12 nodes.",
248 "The number of PME nodes is set with option [TT]-npme[tt],",
249 "this can not be more than half of the nodes.",
250 "By default [TT]mdrun[tt] makes a guess for the number of PME",
251 "nodes when the number of nodes is larger than 11 or performance wise",
252 "not compatible with the PME grid x dimension.",
253 "But the user should optimize npme. Performance statistics on this issue",
254 "are written at the end of the log file.",
255 "For good load balancing at high parallelization, the PME grid x and y",
256 "dimensions should be divisible by the number of PME nodes",
257 "(the simulation will run correctly also when this is not the case).",
258 "[PAR]",
259 "This section lists all options that affect the domain decomposition.",
260 "[PAR]",
261 "Option [TT]-rdd[tt] can be used to set the required maximum distance",
262 "for inter charge-group bonded interactions.",
263 "Communication for two-body bonded interactions below the non-bonded",
264 "cut-off distance always comes for free with the non-bonded communication.",
265 "Atoms beyond the non-bonded cut-off are only communicated when they have",
266 "missing bonded interactions; this means that the extra cost is minor",
267 "and nearly indepedent of the value of [TT]-rdd[tt].",
268 "With dynamic load balancing option [TT]-rdd[tt] also sets",
269 "the lower limit for the domain decomposition cell sizes.",
270 "By default [TT]-rdd[tt] is determined by [TT]mdrun[tt] based on",
271 "the initial coordinates. The chosen value will be a balance",
272 "between interaction range and communication cost.",
273 "[PAR]",
274 "When inter charge-group bonded interactions are beyond",
275 "the bonded cut-off distance, [TT]mdrun[tt] terminates with an error message.",
276 "For pair interactions and tabulated bonds",
277 "that do not generate exclusions, this check can be turned off",
278 "with the option [TT]-noddcheck[tt].",
279 "[PAR]",
280 "When constraints are present, option [TT]-rcon[tt] influences",
281 "the cell size limit as well.",
282 "Atoms connected by NC constraints, where NC is the LINCS order plus 1,",
283 "should not be beyond the smallest cell size. A error message is",
284 "generated when this happens and the user should change the decomposition",
285 "or decrease the LINCS order and increase the number of LINCS iterations.",
286 "By default [TT]mdrun[tt] estimates the minimum cell size required for P-LINCS",
287 "in a conservative fashion. For high parallelization it can be useful",
288 "to set the distance required for P-LINCS with the option [TT]-rcon[tt].",
289 "[PAR]",
290 "The [TT]-dds[tt] option sets the minimum allowed x, y and/or z scaling",
291 "of the cells with dynamic load balancing. [TT]mdrun[tt] will ensure that",
292 "the cells can scale down by at least this factor. This option is used",
293 "for the automated spatial decomposition (when not using [TT]-dd[tt])",
294 "as well as for determining the number of grid pulses, which in turn",
295 "sets the minimum allowed cell size. Under certain circumstances",
296 "the value of [TT]-dds[tt] might need to be adjusted to account for",
297 "high or low spatial inhomogeneity of the system.",
298 "[PAR]",
299 "The option [TT]-gcom[tt] can be used to only do global communication",
300 "every n steps.",
301 "This can improve performance for highly parallel simulations",
302 "where this global communication step becomes the bottleneck.",
303 "For a global thermostat and/or barostat the temperature",
304 "and/or pressure will also only be updated every [TT]-gcom[tt] steps.",
305 "By default it is set to the minimum of nstcalcenergy and nstlist.[PAR]",
306 "With [TT]-rerun[tt] an input trajectory can be given for which ",
307 "forces and energies will be (re)calculated. Neighbor searching will be",
308 "performed for every frame, unless [TT]nstlist[tt] is zero",
309 "(see the [TT].mdp[tt] file).[PAR]",
310 "ED (essential dynamics) sampling is switched on by using the [TT]-ei[tt]",
311 "flag followed by an [TT].edi[tt] file.",
312 "The [TT].edi[tt] file can be produced using options in the essdyn",
313 "menu of the WHAT IF program. [TT]mdrun[tt] produces a [TT].edo[tt] file that",
314 "contains projections of positions, velocities and forces onto selected",
315 "eigenvectors.[PAR]",
316 "When user-defined potential functions have been selected in the",
317 "[TT].mdp[tt] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]",
318 "a formatted table with potential functions. The file is read from",
319 "either the current directory or from the [TT]GMXLIB[tt] directory.",
320 "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,",
321 "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with",
322 "normal Coulomb.",
323 "When pair interactions are present, a separate table for pair interaction",
324 "functions is read using the [TT]-tablep[tt] option.[PAR]",
325 "When tabulated bonded functions are present in the topology,",
326 "interaction functions are read using the [TT]-tableb[tt] option.",
327 "For each different tabulated interaction type the table file name is",
328 "modified in a different way: before the file extension an underscore is",
329 "appended, then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals",
330 "and finally the table number of the interaction type.[PAR]",
331 "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
332 "coordinates and forces when pulling is selected",
333 "in the [TT].mdp[tt] file.[PAR]",
334 "With [TT]-multi[tt] or [TT]-multidir[tt], multiple systems can be ",
335 "simulated in parallel.",
336 "As many input files/directories are required as the number of systems. ",
337 "The [TT]-multidir[tt] option takes a list of directories (one for each ",
338 "system) and runs in each of them, using the input/output file names, ",
339 "such as specified by e.g. the [TT]-s[tt] option, relative to these ",
340 "directories.",
341 "With [TT]-multi[tt], the system number is appended to the run input ",
342 "and each output filename, for instance [TT]topol.tpr[tt] becomes",
343 "[TT]topol0.tpr[tt], [TT]topol1.tpr[tt] etc.",
344 "The number of nodes per system is the total number of nodes",
345 "divided by the number of systems.",
346 "One use of this option is for NMR refinement: when distance",
347 "or orientation restraints are present these can be ensemble averaged",
348 "over all the systems.[PAR]",
349 "With [TT]-replex[tt] replica exchange is attempted every given number",
350 "of steps. The number of replicas is set with the [TT]-multi[tt] or ",
351 "[TT]-multidir[tt] option, described above.",
352 "All run input files should use a different coupling temperature,",
353 "the order of the files is not important. The random seed is set with",
354 "[TT]-reseed[tt]. The velocities are scaled and neighbor searching",
355 "is performed after every exchange.[PAR]",
356 "Finally some experimental algorithms can be tested when the",
357 "appropriate options have been given. Currently under",
358 "investigation are: polarizability and X-ray bombardments.",
359 "[PAR]",
360 "The option [TT]-membed[tt] does what used to be g_membed, i.e. embed",
361 "a protein into a membrane. The data file should contain the options",
362 "that where passed to g_membed before. The [TT]-mn[tt] and [TT]-mp[tt]",
363 "both apply to this as well.",
364 "[PAR]",
365 "The option [TT]-pforce[tt] is useful when you suspect a simulation",
366 "crashes due to too large forces. With this option coordinates and",
367 "forces of atoms with a force larger than a certain value will",
368 "be printed to stderr.",
369 "[PAR]",
370 "Checkpoints containing the complete state of the system are written",
371 "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
372 "unless option [TT]-cpt[tt] is set to -1.",
373 "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
374 "make sure that a recent state of the system is always available,",
375 "even when the simulation is terminated while writing a checkpoint.",
376 "With [TT]-cpnum[tt] all checkpoint files are kept and appended",
377 "with the step number.",
378 "A simulation can be continued by reading the full state from file",
379 "with option [TT]-cpi[tt]. This option is intelligent in the way that",
380 "if no checkpoint file is found, Gromacs just assumes a normal run and",
381 "starts from the first step of the [TT].tpr[tt] file. By default the output",
382 "will be appending to the existing output files. The checkpoint file",
383 "contains checksums of all output files, such that you will never",
384 "loose data when some output files are modified, corrupt or removed.",
385 "There are three scenarios with [TT]-cpi[tt]:[PAR]",
386 "[TT]*[tt] no files with matching names are present: new output files are written[PAR]",
387 "[TT]*[tt] all files are present with names and checksums matching those stored",
388 "in the checkpoint file: files are appended[PAR]",
389 "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]",
390 "With [TT]-noappend[tt] new output files are opened and the simulation",
391 "part number is added to all output file names.",
392 "Note that in all cases the checkpoint file itself is not renamed",
393 "and will be overwritten, unless its name does not match",
394 "the [TT]-cpo[tt] option.",
395 "[PAR]",
396 "With checkpointing the output is appended to previously written",
397 "output files, unless [TT]-noappend[tt] is used or none of the previous",
398 "output files are present (except for the checkpoint file).",
399 "The integrity of the files to be appended is verified using checksums",
400 "which are stored in the checkpoint file. This ensures that output can",
401 "not be mixed up or corrupted due to file appending. When only some",
402 "of the previous output files are present, a fatal error is generated",
403 "and no old output files are modified and no new output files are opened.",
404 "The result with appending will be the same as from a single run.",
405 "The contents will be binary identical, unless you use a different number",
406 "of nodes or dynamic load balancing or the FFT library uses optimizations",
407 "through timing.",
408 "[PAR]",
409 "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
410 "file is written at the first neighbor search step where the run time",
411 "exceeds [TT]-maxh[tt]*0.99 hours.",
412 "[PAR]",
413 "When [TT]mdrun[tt] receives a TERM signal, it will set nsteps to the current",
414 "step plus one. When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is",
415 "pressed), it will stop after the next neighbor search step ",
416 "(with nstlist=0 at the next step).",
417 "In both cases all the usual output will be written to file.",
418 "When running with MPI, a signal to one of the [TT]mdrun[tt] processes",
419 "is sufficient, this signal should not be sent to mpirun or",
420 "the [TT]mdrun[tt] process that is the parent of the others.",
421 "[PAR]",
422 "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
423 #endif
425 t_commrec *cr;
426 t_filenm fnm[] = {
427 { efTPX, NULL, NULL, ffREAD },
428 { efTRN, "-o", NULL, ffWRITE },
429 { efXTC, "-x", NULL, ffOPTWR },
430 { efCPT, "-cpi", NULL, ffOPTRD },
431 { efCPT, "-cpo", NULL, ffOPTWR },
432 { efSTO, "-c", "confout", ffWRITE },
433 { efEDR, "-e", "ener", ffWRITE },
434 { efLOG, "-g", "md", ffWRITE },
435 { efXVG, "-dhdl", "dhdl", ffOPTWR },
436 { efXVG, "-field", "field", ffOPTWR },
437 { efXVG, "-table", "table", ffOPTRD },
438 { efXVG, "-tabletf", "tabletf", ffOPTRD },
439 { efXVG, "-tablep", "tablep", ffOPTRD },
440 { efXVG, "-tableb", "table", ffOPTRD },
441 { efTRX, "-rerun", "rerun", ffOPTRD },
442 { efXVG, "-tpi", "tpi", ffOPTWR },
443 { efXVG, "-tpid", "tpidist", ffOPTWR },
444 { efEDI, "-ei", "sam", ffOPTRD },
445 { efEDO, "-eo", "sam", ffOPTWR },
446 { efGCT, "-j", "wham", ffOPTRD },
447 { efGCT, "-jo", "bam", ffOPTWR },
448 { efXVG, "-ffout", "gct", ffOPTWR },
449 { efXVG, "-devout", "deviatie", ffOPTWR },
450 { efXVG, "-runav", "runaver", ffOPTWR },
451 { efXVG, "-px", "pullx", ffOPTWR },
452 { efXVG, "-pf", "pullf", ffOPTWR },
453 { efXVG, "-ro", "rotation", ffOPTWR },
454 { efLOG, "-ra", "rotangles",ffOPTWR },
455 { efLOG, "-rs", "rotslabs", ffOPTWR },
456 { efLOG, "-rt", "rottorque",ffOPTWR },
457 { efMTX, "-mtx", "nm", ffOPTWR },
458 { efNDX, "-dn", "dipole", ffOPTWR },
459 { efRND, "-multidir",NULL, ffOPTRDMULT},
460 { efDAT, "-membed", "membed", ffOPTRD },
461 { efTOP, "-mp", "membed", ffOPTRD },
462 { efNDX, "-mn", "membed", ffOPTRD }
464 #define NFILE asize(fnm)
466 /* Command line options ! */
467 gmx_bool bCart = FALSE;
468 gmx_bool bPPPME = FALSE;
469 gmx_bool bPartDec = FALSE;
470 gmx_bool bDDBondCheck = TRUE;
471 gmx_bool bDDBondComm = TRUE;
472 gmx_bool bTunePME = TRUE;
473 gmx_bool bTestVerlet = FALSE;
474 gmx_bool bVerbose = FALSE;
475 gmx_bool bCompact = TRUE;
476 gmx_bool bSepPot = FALSE;
477 gmx_bool bRerunVSite = FALSE;
478 gmx_bool bIonize = FALSE;
479 gmx_bool bConfout = TRUE;
480 gmx_bool bReproducible = FALSE;
482 int npme=-1;
483 int nmultisim=0;
484 int nstglobalcomm=-1;
485 int repl_ex_nst=0;
486 int repl_ex_seed=-1;
487 int repl_ex_nex=0;
488 int nstepout=100;
489 int resetstep=-1;
490 int nsteps=-2; /* the value -2 means that the mdp option will be used */
492 rvec realddxyz={0,0,0};
493 const char *ddno_opt[ddnoNR+1] =
494 { NULL, "interleave", "pp_pme", "cartesian", NULL };
495 const char *dddlb_opt[] =
496 { NULL, "auto", "no", "yes", NULL };
497 const char *nbpu_opt[] =
498 { NULL, "auto", "cpu", "gpu", "gpu_cpu", NULL };
499 real rdd=0.0,rconstr=0.0,dlb_scale=0.8,pforce=-1;
500 char *ddcsx=NULL,*ddcsy=NULL,*ddcsz=NULL;
501 real cpt_period=15.0,max_hours=-1;
502 gmx_bool bAppendFiles=TRUE;
503 gmx_bool bKeepAndNumCPT=FALSE;
504 gmx_bool bResetCountersHalfWay=FALSE;
505 output_env_t oenv=NULL;
506 const char *deviceOptions = "";
508 gmx_hw_opt_t hw_opt={0,0,0,0,TRUE,FALSE,0,NULL};
510 t_pargs pa[] = {
512 { "-pd", FALSE, etBOOL,{&bPartDec},
513 "Use particle decompostion" },
514 { "-dd", FALSE, etRVEC,{&realddxyz},
515 "Domain decomposition grid, 0 is optimize" },
516 { "-ddorder", FALSE, etENUM, {ddno_opt},
517 "DD node order" },
518 { "-npme", FALSE, etINT, {&npme},
519 "Number of separate nodes to be used for PME, -1 is guess" },
520 { "-nt", FALSE, etINT, {&hw_opt.nthreads_tot},
521 "Total number of threads to start (0 is guess)" },
522 { "-ntmpi", FALSE, etINT, {&hw_opt.nthreads_tmpi},
523 "Number of thread-MPI threads to start (0 is guess)" },
524 { "-ntomp", FALSE, etINT, {&hw_opt.nthreads_omp},
525 "Number of OpenMP threads to start (0 is guess)" },
526 { "-ntomp_pme", FALSE, etINT, {&hw_opt.nthreads_omp_pme},
527 "Number of OpenMP threads to start (0 is -ntomp)" },
528 { "-pin", FALSE, etBOOL, {&hw_opt.bThreadPinning},
529 "Pin OpenMP threads to cores" },
530 { "-pinht", FALSE, etBOOL, {&hw_opt.bPinHyperthreading},
531 "Always pin threads to Hyper-Threading cores" },
532 { "-pinoffset", FALSE, etINT, {&hw_opt.core_pinning_offset},
533 "Core offset for pinning (for running multiple mdrun processes on a single physical node)" },
534 { "-gpu_id", FALSE, etSTR, {&hw_opt.gpu_id},
535 "List of GPU id's to use" },
536 { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck},
537 "Check for all bonded interactions with DD" },
538 { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm},
539 "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
540 { "-rdd", FALSE, etREAL, {&rdd},
541 "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
542 { "-rcon", FALSE, etREAL, {&rconstr},
543 "Maximum distance for P-LINCS (nm), 0 is estimate" },
544 { "-dlb", FALSE, etENUM, {dddlb_opt},
545 "Dynamic load balancing (with DD)" },
546 { "-dds", FALSE, etREAL, {&dlb_scale},
547 "Minimum allowed dlb scaling of the DD cell size" },
548 { "-ddcsx", FALSE, etSTR, {&ddcsx},
549 "HIDDENThe DD cell sizes in x" },
550 { "-ddcsy", FALSE, etSTR, {&ddcsy},
551 "HIDDENThe DD cell sizes in y" },
552 { "-ddcsz", FALSE, etSTR, {&ddcsz},
553 "HIDDENThe DD cell sizes in z" },
554 { "-gcom", FALSE, etINT,{&nstglobalcomm},
555 "Global communication frequency" },
556 { "-nb", FALSE, etENUM, {&nbpu_opt},
557 "Calculate non-bonded interactions on" },
558 { "-tunepme", FALSE, etBOOL, {&bTunePME},
559 "Optimize PME load between PP/PME nodes or GPU/CPU" },
560 { "-testverlet", FALSE, etBOOL, {&bTestVerlet},
561 "Test the Verlet non-bonded scheme" },
562 { "-v", FALSE, etBOOL,{&bVerbose},
563 "Be loud and noisy" },
564 { "-compact", FALSE, etBOOL,{&bCompact},
565 "Write a compact log file" },
566 { "-seppot", FALSE, etBOOL, {&bSepPot},
567 "Write separate V and dVdl terms for each interaction type and node to the log file(s)" },
568 { "-pforce", FALSE, etREAL, {&pforce},
569 "Print all forces larger than this (kJ/mol nm)" },
570 { "-reprod", FALSE, etBOOL,{&bReproducible},
571 "Try to avoid optimizations that affect binary reproducibility" },
572 { "-cpt", FALSE, etREAL, {&cpt_period},
573 "Checkpoint interval (minutes)" },
574 { "-cpnum", FALSE, etBOOL, {&bKeepAndNumCPT},
575 "Keep and number checkpoint files" },
576 { "-append", FALSE, etBOOL, {&bAppendFiles},
577 "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
578 { "-nsteps", FALSE, etINT, {&nsteps},
579 "Run this number of steps, overrides .mdp file option" },
580 { "-maxh", FALSE, etREAL, {&max_hours},
581 "Terminate after 0.99 times this time (hours)" },
582 { "-multi", FALSE, etINT,{&nmultisim},
583 "Do multiple simulations in parallel" },
584 { "-replex", FALSE, etINT, {&repl_ex_nst},
585 "Attempt replica exchange periodically with this period (steps)" },
586 { "-nex", FALSE, etINT, {&repl_ex_nex},
587 "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion). -nex zero or not specified gives neighbor replica exchange." },
588 { "-reseed", FALSE, etINT, {&repl_ex_seed},
589 "Seed for replica exchange, -1 is generate a seed" },
590 { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
591 "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
592 { "-ionize", FALSE, etBOOL,{&bIonize},
593 "Do a simulation including the effect of an X-Ray bombardment on your system" },
594 { "-confout", FALSE, etBOOL, {&bConfout},
595 "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
596 { "-stepout", FALSE, etINT, {&nstepout},
597 "HIDDENFrequency of writing the remaining runtime" },
598 { "-resetstep", FALSE, etINT, {&resetstep},
599 "HIDDENReset cycle counters after these many time steps" },
600 { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
601 "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
602 #ifdef GMX_OPENMM
604 { "-device", FALSE, etSTR, {&deviceOptions},
605 "Device option string" }
606 #endif
608 gmx_edsam_t ed;
609 unsigned long Flags, PCA_Flags;
610 ivec ddxyz;
611 int dd_node_order;
612 gmx_bool bAddPart;
613 FILE *fplog,*fptest;
614 int sim_part,sim_part_fn;
615 const char *part_suffix=".part";
616 char suffix[STRLEN];
617 int rc;
618 char **multidir=NULL;
621 cr = init_par(&argc,&argv);
623 if (MASTER(cr))
624 CopyRight(stderr, argv[0]);
626 PCA_Flags = (PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET));
628 /* Comment this in to do fexist calls only on master
629 * works not with rerun or tables at the moment
630 * also comment out the version of init_forcerec in md.c
631 * with NULL instead of opt2fn
634 if (!MASTER(cr))
636 PCA_Flags |= PCA_NOT_READ_NODE;
640 parse_common_args(&argc,argv,PCA_Flags, NFILE,fnm,asize(pa),pa,
641 asize(desc),desc,0,NULL, &oenv);
645 /* we set these early because they might be used in init_multisystem()
646 Note that there is the potential for npme>nnodes until the number of
647 threads is set later on, if there's thread parallelization. That shouldn't
648 lead to problems. */
649 dd_node_order = nenum(ddno_opt);
650 cr->npmenodes = npme;
652 /* now check the -multi and -multidir option */
653 if (opt2bSet("-multidir", NFILE, fnm))
655 int i;
656 if (nmultisim > 0)
658 gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive.");
660 nmultisim = opt2fns(&multidir, "-multidir", NFILE, fnm);
664 if (repl_ex_nst != 0 && nmultisim < 2)
665 gmx_fatal(FARGS,"Need at least two replicas for replica exchange (option -multi)");
667 if (repl_ex_nex < 0)
668 gmx_fatal(FARGS,"Replica exchange number of exchanges needs to be positive");
670 if (nmultisim > 1) {
671 #ifndef GMX_THREAD_MPI
672 gmx_bool bParFn = (multidir == NULL);
673 init_multisystem(cr, nmultisim, multidir, NFILE, fnm, bParFn);
674 #else
675 gmx_fatal(FARGS,"mdrun -multi is not supported with the thread library.Please compile GROMACS with MPI support");
676 #endif
679 bAddPart = !bAppendFiles;
681 /* Check if there is ANY checkpoint file available */
682 sim_part = 1;
683 sim_part_fn = sim_part;
684 if (opt2bSet("-cpi",NFILE,fnm))
686 if (bSepPot && bAppendFiles)
688 gmx_fatal(FARGS,"Output file appending is not supported with -seppot");
691 bAppendFiles =
692 read_checkpoint_simulation_part(opt2fn_master("-cpi", NFILE,
693 fnm,cr),
694 &sim_part_fn,NULL,cr,
695 bAppendFiles,NFILE,fnm,
696 part_suffix,&bAddPart);
697 if (sim_part_fn==0 && MASTER(cr))
699 fprintf(stdout,"No previous checkpoint file present, assuming this is a new run.\n");
701 else
703 sim_part = sim_part_fn + 1;
706 if (MULTISIM(cr) && MASTER(cr))
708 check_multi_int(stdout,cr->ms,sim_part,"simulation part");
711 else
713 bAppendFiles = FALSE;
716 if (!bAppendFiles)
718 sim_part_fn = sim_part;
721 if (bAddPart)
723 /* Rename all output files (except checkpoint files) */
724 /* create new part name first (zero-filled) */
725 sprintf(suffix,"%s%04d",part_suffix,sim_part_fn);
727 add_suffix_to_output_names(fnm,NFILE,suffix);
728 if (MASTER(cr))
730 fprintf(stdout,"Checkpoint file is from part %d, new output files will be suffixed '%s'.\n",sim_part-1,suffix);
734 Flags = opt2bSet("-rerun",NFILE,fnm) ? MD_RERUN : 0;
735 Flags = Flags | (bSepPot ? MD_SEPPOT : 0);
736 Flags = Flags | (bIonize ? MD_IONIZE : 0);
737 Flags = Flags | (bPartDec ? MD_PARTDEC : 0);
738 Flags = Flags | (bDDBondCheck ? MD_DDBONDCHECK : 0);
739 Flags = Flags | (bDDBondComm ? MD_DDBONDCOMM : 0);
740 Flags = Flags | (bTunePME ? MD_TUNEPME : 0);
741 Flags = Flags | (bTestVerlet ? MD_TESTVERLET : 0);
742 Flags = Flags | (bConfout ? MD_CONFOUT : 0);
743 Flags = Flags | (bRerunVSite ? MD_RERUN_VSITE : 0);
744 Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
745 Flags = Flags | (bAppendFiles ? MD_APPENDFILES : 0);
746 Flags = Flags | (opt2parg_bSet("-append", asize(pa),pa) ? MD_APPENDFILESSET : 0);
747 Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0);
748 Flags = Flags | (sim_part>1 ? MD_STARTFROMCPT : 0);
749 Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
752 /* We postpone opening the log file if we are appending, so we can
753 first truncate the old log file and append to the correct position
754 there instead. */
755 if ((MASTER(cr) || bSepPot) && !bAppendFiles)
757 gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,
758 !bSepPot,Flags & MD_APPENDFILES,&fplog);
759 CopyRight(fplog,argv[0]);
760 please_cite(fplog,"Hess2008b");
761 please_cite(fplog,"Spoel2005a");
762 please_cite(fplog,"Lindahl2001a");
763 please_cite(fplog,"Berendsen95a");
765 else if (!MASTER(cr) && bSepPot)
767 gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,!bSepPot,Flags,&fplog);
769 else
771 fplog = NULL;
774 ddxyz[XX] = (int)(realddxyz[XX] + 0.5);
775 ddxyz[YY] = (int)(realddxyz[YY] + 0.5);
776 ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5);
778 rc = mdrunner(&hw_opt, fplog,cr,NFILE,fnm,oenv,bVerbose,bCompact,
779 nstglobalcomm, ddxyz,dd_node_order,rdd,rconstr,
780 dddlb_opt[0],dlb_scale,ddcsx,ddcsy,ddcsz,
781 nbpu_opt[0],
782 nsteps,nstepout,resetstep,
783 nmultisim,repl_ex_nst,repl_ex_nex,repl_ex_seed,
784 pforce, cpt_period,max_hours,deviceOptions,Flags);
786 gmx_finalize_par();
788 if (MULTIMASTER(cr)) {
789 thanx(stderr);
792 /* Log file has to be closed in mdrunner if we are appending to it
793 (fplog not set here) */
794 if (MASTER(cr) && !bAppendFiles)
796 gmx_log_close(fplog);
799 return rc;