fixed mdrun verbosity with OpenMM build
[gromacs/rigid-bodies.git] / src / kernel / mdrun.c
blob7d1759c5af4df6e29618ce641ddc03870abdb36a
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"
53 /* afm stuf */
54 #include "pull.h"
56 int main(int argc,char *argv[])
58 const char *desc[] = {
59 #ifdef GMX_OPENMM
60 "This is an experimental release of GROMACS for accelerated",
61 "Molecular Dynamics simulations on GPU processors. Support is provided",
62 "by the OpenMM library (https://simtk.org/home/openmm).[PAR]",
63 "*Warning*[BR]",
64 "This release is targeted at developers and advanced users and",
65 "should not be considered ready for production. The following should be",
66 "noted before using the program:[PAR]",
67 "Usage:[BR]",
68 "$ mdrun -device \"OpenMM:platform=Cuda,memtest=15,deviceid=0,force-device=no\"[PAR]",
69 "OpenMM options:[PAR]",
70 " [TT]platform[tt] = Cuda\nThe only available value. OpenCL support will be available soon[PAR]",
71 " [TT]memtest[tt] = 15\nRun a partial, random GPU memory test for the given amount of seconds. A full test",
72 "(recommended!) can be run with \"full\". Memory testing can be disabled with \"off\".[PAR]",
73 " [TT]deviceid[tt] = 0\nSpecify the target device when multiple cards are present.",
74 "Only one card can be used at any given time though.[PAR]",
75 " [TT]force-device[tt] = no\nIf set to \"yes\" mdrun will be forced to execute on",
76 "hardware that is not officially supported. GPU acceleration can also be achieved on older,",
77 "but Cuda capable, cards although the simulation might be too slow, and the memory limits too strict.[PAR]",
78 " * The current release runs only on modern nVidia GPU hardware with CUDA support.",
79 "Make sure that the necessary CUDA drivers and libraries for your operating system",
80 "are already installed. The CUDA SDK also should be installed in order to compile",
81 "the program from source (http://www.nvidia.com/object/cuda_home.html).[PAR]"
82 " * Multiple GPU cards are not supported.[PAR]"
83 " * Only a small subset of the GROMACS features and options are supported on the GPUs.",
84 "See below for a detailed list.[PAR]",
85 " * Consumer level GPU cards are known to often have problems with faulty memory.",
86 "It is recommended that a full memory check of the cards is done at least once",
87 "(for example, using the memtest=full option).",
88 "A partial memory check (for example, memtest=15) before and",
89 "after the simulation run would help spot",
90 "problems resulting from processor overheating.[PAR]"
91 " * The maximum size of the simulated systems depends on the available",
92 "GPU memory,for example, a GTX280 with 1GB memory has been tested with systems",
93 "of up to about 100,000 atoms.[PAR]",
94 " * In order to take a full advantage of the GPU platform features, many algorithms",
95 "have been implemented in a very different way than they are on the CPUs.",
96 "Therefore numercal correspondence between properties of the state of",
97 "simulated systems should not be expected. Moreover, the values will likely vary",
98 "when simulations are done on different GPU hardware.[PAR]"
99 " * Frequent retrieval of system state information such as",
100 "trajectory coordinates and energies can greatly influence the performance",
101 "of the program due to slow CPU<->GPU memory transfer speed.[PAR]",
102 " * MD algorithms are complex, and although the Gromacs code is highly tuned for them,",
103 "they often do not translate very well onto the streaming architetures.",
104 "Realistic expectations about the achievable speed-up from test with GTX280:",
105 "For small protein systems in implicit solvent using all-vs-all kernels the acceleration",
106 "can be as high as 20 times, but in most other setups involving cutoffs and PME the",
107 "acceleration is usually only 4~6 times relative to a 3GHz CPU.[PAR]",
108 "Supported features:[PAR]",
109 " * Integrators: md, md-vv, md-vv2, sd and bd.\n",
110 " * Long-range interactions (option coulombtype): Reaction-Field, Ewald, PME.\n",
111 " * Temperature control: Supported only with the sd, bd, md-vv and md-vv2 integrators.\n",
112 " * Pressure control: Not supported.\n",
113 " * Implicit solvent: Supported.\n",
114 "A detailed description can be found on the website:\n",
115 "http://www.gromacs.org/index.php?title=Download_%26_Installation/Related_Software/OpenMM[PAR]",
116 // From the original mdrun documentaion
117 "The mdrun program reads the run input file ([TT]-s[tt])",
118 "and distributes the topology over nodes if needed.",
119 "mdrun produces at least four output files.",
120 "A single log file ([TT]-g[tt]) is written, unless the option",
121 "[TT]-seppot[tt] is used, in which case each node writes a log file.",
122 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
123 "optionally forces.",
124 "The structure file ([TT]-c[tt]) contains the coordinates and",
125 "velocities of the last step.",
126 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
127 "pressure, etc, a lot of these things are also printed in the log file.",
128 "Optionally coordinates can be written to a compressed trajectory file",
129 "([TT]-x[tt]).",
130 #else
131 "The mdrun program is the main computational chemistry engine",
132 "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
133 "but it can also perform Stochastic Dynamics, Energy Minimization,",
134 "test particle insertion or (re)calculation of energies.",
135 "Normal mode analysis is another option. In this case mdrun",
136 "builds a Hessian matrix from single conformation.",
137 "For usual Normal Modes-like calculations, make sure that",
138 "the structure provided is properly energy-minimized.",
139 "The generated matrix can be diagonalized by g_nmeig.[PAR]",
140 "The mdrun program reads the run input file ([TT]-s[tt])",
141 "and distributes the topology over nodes if needed.",
142 "mdrun produces at least four output files.",
143 "A single log file ([TT]-g[tt]) is written, unless the option",
144 "[TT]-seppot[tt] is used, in which case each node writes a log file.",
145 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
146 "optionally forces.",
147 "The structure file ([TT]-c[tt]) contains the coordinates and",
148 "velocities of the last step.",
149 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
150 "pressure, etc, a lot of these things are also printed in the log file.",
151 "Optionally coordinates can be written to a compressed trajectory file",
152 "([TT]-x[tt]).[PAR]",
153 "The option [TT]-dhdl[tt] is only used when free energy calculation is",
154 "turned on.[PAR]",
155 "When mdrun is started using MPI with more than 1 node, parallelization",
156 "is used. By default domain decomposition is used, unless the [TT]-pd[tt]",
157 "option is set, which selects particle decomposition.[PAR]",
158 "With domain decomposition, the spatial decomposition can be set",
159 "with option [TT]-dd[tt]. By default mdrun selects a good decomposition.",
160 "The user only needs to change this when the system is very inhomogeneous.",
161 "Dynamic load balancing is set with the option [TT]-dlb[tt],",
162 "which can give a significant performance improvement,",
163 "especially for inhomogeneous systems. The only disadvantage of",
164 "dynamic load balancing is that runs are no longer binary reproducible,",
165 "but in most cases this is not important.",
166 "By default the dynamic load balancing is automatically turned on",
167 "when the measured performance loss due to load imbalance is 5% or more.",
168 "At low parallelization these are the only important options",
169 "for domain decomposition.",
170 "At high parallelization the options in the next two sections",
171 "could be important for increasing the performace.",
172 "[PAR]",
173 "When PME is used with domain decomposition, separate nodes can",
174 "be assigned to do only the PME mesh calculation;",
175 "this is computationally more efficient starting at about 12 nodes.",
176 "The number of PME nodes is set with option [TT]-npme[tt],",
177 "this can not be more than half of the nodes.",
178 "By default mdrun makes a guess for the number of PME",
179 "nodes when the number of nodes is larger than 11 or performance wise",
180 "not compatible with the PME grid x dimension.",
181 "But the user should optimize npme. Performance statistics on this issue",
182 "are written at the end of the log file.",
183 "For good load balancing at high parallelization, the PME grid x and y",
184 "dimensions should be divisible by the number of PME nodes",
185 "(the simulation will run correctly also when this is not the case).",
186 "[PAR]",
187 "This section lists all options that affect the domain decomposition.",
188 "[BR]",
189 "Option [TT]-rdd[tt] can be used to set the required maximum distance",
190 "for inter charge-group bonded interactions.",
191 "Communication for two-body bonded interactions below the non-bonded",
192 "cut-off distance always comes for free with the non-bonded communication.",
193 "Atoms beyond the non-bonded cut-off are only communicated when they have",
194 "missing bonded interactions; this means that the extra cost is minor",
195 "and nearly indepedent of the value of [TT]-rdd[tt].",
196 "With dynamic load balancing option [TT]-rdd[tt] also sets",
197 "the lower limit for the domain decomposition cell sizes.",
198 "By default [TT]-rdd[tt] is determined by mdrun based on",
199 "the initial coordinates. The chosen value will be a balance",
200 "between interaction range and communication cost.",
201 "[BR]",
202 "When inter charge-group bonded interactions are beyond",
203 "the bonded cut-off distance, mdrun terminates with an error message.",
204 "For pair interactions and tabulated bonds",
205 "that do not generate exclusions, this check can be turned off",
206 "with the option [TT]-noddcheck[tt].",
207 "[BR]",
208 "When constraints are present, option [TT]-rcon[tt] influences",
209 "the cell size limit as well.",
210 "Atoms connected by NC constraints, where NC is the LINCS order plus 1,",
211 "should not be beyond the smallest cell size. A error message is",
212 "generated when this happens and the user should change the decomposition",
213 "or decrease the LINCS order and increase the number of LINCS iterations.",
214 "By default mdrun estimates the minimum cell size required for P-LINCS",
215 "in a conservative fashion. For high parallelization it can be useful",
216 "to set the distance required for P-LINCS with the option [TT]-rcon[tt].",
217 "[BR]",
218 "The [TT]-dds[tt] option sets the minimum allowed x, y and/or z scaling",
219 "of the cells with dynamic load balancing. mdrun will ensure that",
220 "the cells can scale down by at least this factor. This option is used",
221 "for the automated spatial decomposition (when not using [TT]-dd[tt])",
222 "as well as for determining the number of grid pulses, which in turn",
223 "sets the minimum allowed cell size. Under certain circumstances",
224 "the value of [TT]-dds[tt] might need to be adjusted to account for",
225 "high or low spatial inhomogeneity of the system.",
226 "[PAR]",
227 "The option [TT]-gcom[tt] can be used to only do global communication",
228 "every n steps."
229 "This can improve performance for highly parallel simulations",
230 "where this global communication step becomes the bottleneck.",
231 "For a global thermostat and/or barostat the temperature",
232 "and/or pressure will also only be updated every -gcom steps.",
233 "By default it is set to the minimum of nstcalcenergy and nstlist.[PAR]",
234 "With [TT]-rerun[tt] an input trajectory can be given for which ",
235 "forces and energies will be (re)calculated. Neighbor searching will be",
236 "performed for every frame, unless [TT]nstlist[tt] is zero",
237 "(see the [TT].mdp[tt] file).[PAR]",
238 "ED (essential dynamics) sampling is switched on by using the [TT]-ei[tt]",
239 "flag followed by an [TT].edi[tt] file.",
240 "The [TT].edi[tt] file can be produced using options in the essdyn",
241 "menu of the WHAT IF program. mdrun produces a [TT].edo[tt] file that",
242 "contains projections of positions, velocities and forces onto selected",
243 "eigenvectors.[PAR]",
244 "When user-defined potential functions have been selected in the",
245 "[TT].mdp[tt] file the [TT]-table[tt] option is used to pass mdrun",
246 "a formatted table with potential functions. The file is read from",
247 "either the current directory or from the GMXLIB directory.",
248 "A number of pre-formatted tables are presented in the GMXLIB dir,",
249 "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard Jones potentials with",
250 "normal Coulomb.",
251 "When pair interactions are present a separate table for pair interaction",
252 "functions is read using the [TT]-tablep[tt] option.[PAR]",
253 "When tabulated bonded functions are present in the topology,",
254 "interaction functions are read using the [TT]-tableb[tt] option.",
255 "For each different tabulated interaction type the table file name is",
256 "modified in a different way: before the file extension an underscore is",
257 "appended, then a b for bonds, an a for angles or a d for dihedrals",
258 "and finally the table number of the interaction type.[PAR]",
259 "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
260 "coordinates and forces when pulling is selected",
261 "in the [TT].mdp[tt] file.[PAR]",
262 "With [TT]-multi[tt] multiple systems are simulated in parallel.",
263 "As many input files are required as the number of systems.",
264 "The system number is appended to the run input and each output filename,",
265 "for instance topol.tpr becomes topol0.tpr, topol1.tpr etc.",
266 "The number of nodes per system is the total number of nodes",
267 "divided by the number of systems.",
268 "One use of this option is for NMR refinement: when distance",
269 "or orientation restraints are present these can be ensemble averaged",
270 "over all the systems.[PAR]",
271 "With [TT]-replex[tt] replica exchange is attempted every given number",
272 "of steps. The number of replicas is set with the [TT]-multi[tt] option,",
273 "see above.",
274 "All run input files should use a different coupling temperature,",
275 "the order of the files is not important. The random seed is set with",
276 "[TT]-reseed[tt]. The velocities are scaled and neighbor searching",
277 "is performed after every exchange.[PAR]",
278 "Finally some experimental algorithms can be tested when the",
279 "appropriate options have been given. Currently under",
280 "investigation are: polarizability, and X-Ray bombardments.",
281 "[PAR]",
282 "The option [TT]-pforce[tt] is useful when you suspect a simulation",
283 "crashes due to too large forces. With this option coordinates and",
284 "forces of atoms with a force larger than a certain value will",
285 "be printed to stderr.",
286 "[PAR]",
287 "Checkpoints containing the complete state of the system are written",
288 "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
289 "unless option [TT]-cpt[tt] is set to -1.",
290 "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
291 "make sure that a recent state of the system is always available,",
292 "even when the simulation is terminated while writing a checkpoint.",
293 "A simulation can be continued by reading the full state from file",
294 "with option [TT]-cpi[tt]. This option is intelligent in the way that",
295 "if no checkpoint file is found, Gromacs just assumes a normal run and",
296 "starts from the first step of the tpr file.",
297 "The simulation part number is added to all output files,",
298 "unless [TT]-append[tt] or [TT]-noaddpart[tt] are set.",
299 "[PAR]",
300 "With checkpointing the output is appended to previously written",
301 "output files, unless [TT]-noappend[tt] is used or none of the previous",
302 "output files are present (except for the checkpoint file).",
303 "The integrity of the files to be appended is verified using checksums",
304 "which are stored in the checkpoint file. This ensures that output can",
305 "not be mixed up or corrupted due to file appending. When only some",
306 "of the previous output files are present, a fatal error is generated",
307 "and no old output files are modified and no new output files are opened.",
308 "The result with appending will be the same as from a single run.",
309 "The contents will be binary identical, unless you use a different number",
310 "of nodes or dynamic load balancing or the FFT library uses optimizations",
311 "through timing."
312 "[PAR]",
313 "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
314 "file is written at the first neighbor search step where the run time",
315 "exceeds [TT]-maxh[tt]*0.99 hours.",
316 "[PAR]",
317 "When mdrun receives a TERM signal, it will set nsteps to the current",
318 "step plus one. When mdrun receives an INT signal (e.g. when ctrl+C is",
319 "pressed), it will stop after the next neighbor search step ",
320 "(with nstlist=0 at the next step).",
321 "In both cases all the usual output will be written to file.",
322 "When running with MPI, a signal to one of the mdrun processes",
323 "is sufficient, this signal should not be sent to mpirun or",
324 "the mdrun process that is the parent of the others.",
325 "[PAR]",
326 "When mdrun is started with MPI, it does not run niced by default."
327 #endif
329 t_commrec *cr;
330 t_filenm fnm[] = {
331 { efTPX, NULL, NULL, ffREAD },
332 { efTRN, "-o", NULL, ffWRITE },
333 { efXTC, "-x", NULL, ffOPTWR },
334 { efCPT, "-cpi", NULL, ffOPTRD },
335 { efCPT, "-cpo", NULL, ffOPTWR },
336 { efSTO, "-c", "confout", ffWRITE },
337 { efEDR, "-e", "ener", ffWRITE },
338 { efLOG, "-g", "md", ffWRITE },
339 #ifndef GMX_OPENMM
340 { efXVG, "-dhdl", "dhdl", ffOPTWR },
341 { efXVG, "-field", "field", ffOPTWR },
342 { efXVG, "-table", "table", ffOPTRD },
343 { efXVG, "-tablep", "tablep", ffOPTRD },
344 { efXVG, "-tableb", "table", ffOPTRD },
345 { efTRX, "-rerun", "rerun", ffOPTRD },
346 { efXVG, "-tpi", "tpi", ffOPTWR },
347 { efXVG, "-tpid", "tpidist", ffOPTWR },
348 { efEDI, "-ei", "sam", ffOPTRD },
349 { efEDO, "-eo", "sam", ffOPTWR },
350 { efGCT, "-j", "wham", ffOPTRD },
351 { efGCT, "-jo", "bam", ffOPTWR },
352 { efXVG, "-ffout", "gct", ffOPTWR },
353 { efXVG, "-devout", "deviatie", ffOPTWR },
354 { efXVG, "-runav", "runaver", ffOPTWR },
355 { efXVG, "-px", "pullx", ffOPTWR },
356 { efXVG, "-pf", "pullf", ffOPTWR },
357 { efMTX, "-mtx", "nm", ffOPTWR },
358 { efNDX, "-dn", "dipole", ffOPTWR }
359 #endif
361 #define NFILE asize(fnm)
363 /* Command line options ! */
364 bool bCart = FALSE;
365 bool bPPPME = FALSE;
366 bool bPartDec = FALSE;
367 bool bDDBondCheck = TRUE;
368 bool bDDBondComm = TRUE;
369 bool bVerbose = FALSE;
370 bool bCompact = TRUE;
371 bool bSepPot = FALSE;
372 bool bRerunVSite = FALSE;
373 bool bIonize = FALSE;
374 bool bConfout = TRUE;
375 bool bReproducible = FALSE;
377 int npme=-1;
378 int nmultisim=0;
379 int nstglobalcomm=-1;
380 int repl_ex_nst=0;
381 int repl_ex_seed=-1;
382 int nstepout=100;
383 int nthreads=1;
384 int resetstep=-1;
386 rvec realddxyz={0,0,0};
387 const char *ddno_opt[ddnoNR+1] =
388 { NULL, "interleave", "pp_pme", "cartesian", NULL };
389 const char *dddlb_opt[] =
390 { NULL, "auto", "no", "yes", NULL };
391 real rdd=0.0,rconstr=0.0,dlb_scale=0.8,pforce=-1;
392 char *ddcsx=NULL,*ddcsy=NULL,*ddcsz=NULL;
393 real cpt_period=15.0,max_hours=-1;
394 bool bAppendFiles=TRUE,bAddPart=TRUE;
395 bool bResetCountersHalfWay=FALSE;
396 output_env_t oenv=NULL;
397 const char *deviceOptions = "";
399 t_pargs pa[] = {
401 // arguments relevant to OPENMM only
402 #ifdef GMX_OPENMM
403 { "-device", FALSE, etSTR, {&deviceOptions},
404 "Device option string" },
405 // args for non-OpenMM binaries
406 #else
407 { "-pd", FALSE, etBOOL,{&bPartDec},
408 "Use particle decompostion" },
409 { "-dd", FALSE, etRVEC,{&realddxyz},
410 "Domain decomposition grid, 0 is optimize" },
411 { "-nt", FALSE, etINT, {&nthreads},
412 "Number of threads to start on each node" },
413 { "-npme", FALSE, etINT, {&npme},
414 "Number of separate nodes to be used for PME, -1 is guess" },
415 { "-ddorder", FALSE, etENUM, {ddno_opt},
416 "DD node order" },
417 { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck},
418 "Check for all bonded interactions with DD" },
419 { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm},
420 "HIDDENUse special bonded atom communication when -rdd > cut-off" },
421 { "-rdd", FALSE, etREAL, {&rdd},
422 "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
423 { "-rcon", FALSE, etREAL, {&rconstr},
424 "Maximum distance for P-LINCS (nm), 0 is estimate" },
425 { "-dlb", FALSE, etENUM, {dddlb_opt},
426 "Dynamic load balancing (with DD)" },
427 { "-dds", FALSE, etREAL, {&dlb_scale},
428 "Minimum allowed dlb scaling of the DD cell size" },
429 { "-ddcsx", FALSE, etSTR, {&ddcsx},
430 "HIDDENThe DD cell sizes in x" },
431 { "-ddcsy", FALSE, etSTR, {&ddcsy},
432 "HIDDENThe DD cell sizes in y" },
433 { "-ddcsz", FALSE, etSTR, {&ddcsz},
434 "HIDDENThe DD cell sizes in z" },
435 { "-gcom", FALSE, etINT,{&nstglobalcomm},
436 "Global communication frequency" },
437 { "-compact", FALSE, etBOOL,{&bCompact},
438 "Write a compact log file" },
439 { "-seppot", FALSE, etBOOL, {&bSepPot},
440 "Write separate V and dVdl terms for each interaction type and node to the log file(s)" },
441 { "-pforce", FALSE, etREAL, {&pforce},
442 "Print all forces larger than this (kJ/mol nm)" },
443 { "-reprod", FALSE, etBOOL,{&bReproducible},
444 "Try to avoid optimizations that affect binary reproducibility" },
445 { "-cpt", FALSE, etREAL, {&cpt_period},
446 "Checkpoint interval (minutes)" },
447 { "-append", FALSE, etBOOL, {&bAppendFiles},
448 "Append to previous output files when continuing from checkpoint" },
449 { "-addpart", FALSE, etBOOL, {&bAddPart},
450 "Add the simulation part number to all output files when continuing from checkpoint" },
451 { "-multi", FALSE, etINT,{&nmultisim},
452 "Do multiple simulations in parallel" },
453 { "-replex", FALSE, etINT, {&repl_ex_nst},
454 "Attempt replica exchange every # steps" },
455 { "-reseed", FALSE, etINT, {&repl_ex_seed},
456 "Seed for replica exchange, -1 is generate a seed" },
457 { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
458 "HIDDENRecalculate virtual site coordinates with -rerun" },
459 { "-ionize", FALSE, etBOOL,{&bIonize},
460 "Do a simulation including the effect of an X-Ray bombardment on your system" },
461 { "-confout", FALSE, etBOOL, {&bConfout},
462 "HIDDENWrite the last configuration with -c and force checkpointing at the last step" },
463 { "-stepout", FALSE, etINT, {&nstepout},
464 "HIDDENFrequency of writing the remaining runtime" },
465 { "-resetstep", FALSE, etINT, {&resetstep},
466 "HIDDENReset cycle counters after these many time steps" },
467 { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
468 "HIDDENReset the cycle counters after half the number of steps or halfway -maxh" },
469 #endif
470 // args for both
471 { "-v", FALSE, etBOOL,{&bVerbose},
472 "Be loud and noisy" },
473 { "-maxh", FALSE, etREAL, {&max_hours},
474 "Terminate after 0.99 times this time (hours)" },
476 gmx_edsam_t ed;
477 unsigned long Flags, PCA_Flags;
478 ivec ddxyz;
479 int dd_node_order;
480 bool HaveCheckpoint;
481 FILE *fplog,*fptest;
482 int sim_part,sim_part_fn;
483 const char *part_suffix=".part";
484 char suffix[STRLEN];
485 int rc;
487 cr = init_par(&argc,&argv);
488 cr->nthreads = nthreads;
490 PCA_Flags = (PCA_KEEP_ARGS | PCA_NOEXIT_ON_ARGS | PCA_CAN_SET_DEFFNM
491 | (MASTER(cr) ? 0 : PCA_QUIET));
494 /* Comment this in to do fexist calls only on master
495 * works not with rerun or tables at the moment
496 * also comment out the version of init_forcerec in md.c
497 * with NULL instead of opt2fn
500 if (!MASTER(cr))
502 PCA_Flags |= PCA_NOT_READ_NODE;
506 parse_common_args(&argc,argv,PCA_Flags, NFILE,fnm,asize(pa),pa,
507 asize(desc),desc,0,NULL, &oenv);
510 dd_node_order = nenum(ddno_opt);
511 cr->npmenodes = npme;
513 if (repl_ex_nst != 0 && nmultisim < 2)
514 gmx_fatal(FARGS,"Need at least two replicas for replica exchange (option -multi)");
516 if (nmultisim > 1) {
517 #ifndef GMX_THREADS
518 init_multisystem(cr,nmultisim,NFILE,fnm,TRUE);
519 #else
520 gmx_fatal(FARGS,"mdrun -multi is not supported with the thread library.Please compile GROMACS with MPI support");
521 #endif
524 /* Check if there is ANY checkpoint file available */
525 sim_part = 1;
526 sim_part_fn = sim_part;
527 if (opt2bSet("-cpi",NFILE,fnm))
529 bAppendFiles =
530 read_checkpoint_simulation_part(opt2fn_master("-cpi",NFILE,fnm,cr),
531 &sim_part_fn,NULL,cr,
532 bAppendFiles,
533 part_suffix,&bAddPart);
534 if (sim_part_fn==0 && MASTER(cr))
536 fprintf(stdout,"No previous checkpoint file present, assuming this is a new run.\n");
538 else
540 sim_part = sim_part_fn + 1;
543 else
545 bAppendFiles = FALSE;
548 if (!bAppendFiles)
550 sim_part_fn = sim_part;
553 if (bAddPart && sim_part_fn > 1)
555 /* This is a continuation run, rename trajectory output files
556 (except checkpoint files) */
557 /* create new part name first (zero-filled) */
558 sprintf(suffix,"%s%04d",part_suffix,sim_part_fn);
560 add_suffix_to_output_names(fnm,NFILE,suffix);
561 fprintf(stdout,"Checkpoint file is from part %d, new output files will be suffixed '%s'.\n",sim_part-1,suffix);
564 Flags = opt2bSet("-rerun",NFILE,fnm) ? MD_RERUN : 0;
565 Flags = Flags | (bSepPot ? MD_SEPPOT : 0);
566 Flags = Flags | (bIonize ? MD_IONIZE : 0);
567 Flags = Flags | (bPartDec ? MD_PARTDEC : 0);
568 Flags = Flags | (bDDBondCheck ? MD_DDBONDCHECK : 0);
569 Flags = Flags | (bDDBondComm ? MD_DDBONDCOMM : 0);
570 Flags = Flags | (bConfout ? MD_CONFOUT : 0);
571 Flags = Flags | (bRerunVSite ? MD_RERUN_VSITE : 0);
572 Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
573 Flags = Flags | (bAppendFiles ? MD_APPENDFILES : 0);
574 Flags = Flags | (sim_part>1 ? MD_STARTFROMCPT : 0);
575 Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
578 /* We postpone opening the log file if we are appending, so we can
579 first truncate the old log file and append to the correct position
580 there instead. */
581 if ((MASTER(cr) || bSepPot) && !bAppendFiles)
583 gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,!bSepPot,Flags,&fplog);
584 CopyRight(fplog,argv[0]);
585 please_cite(fplog,"Hess2008b");
586 please_cite(fplog,"Spoel2005a");
587 please_cite(fplog,"Lindahl2001a");
588 please_cite(fplog,"Berendsen95a");
590 else
592 fplog = NULL;
595 #if 0
596 /* this is now done in mdrunner: */
597 /* Essential dynamics */
598 if (opt2bSet("-ei",NFILE,fnm)) {
599 /* Open input and output files, allocate space for ED data structure */
600 ed = ed_open(NFILE,fnm,cr);
601 } else
602 ed=NULL;
603 #endif
605 ddxyz[XX] = (int)(realddxyz[XX] + 0.5);
606 ddxyz[YY] = (int)(realddxyz[YY] + 0.5);
607 ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5);
609 /* even if nthreads = 1, we still call this one */
610 rc = mdrunner_threads(nthreads,
611 fplog,cr,NFILE,fnm,oenv,bVerbose,bCompact,nstglobalcomm,
612 ddxyz,dd_node_order,rdd,rconstr,
613 dddlb_opt[0],dlb_scale,ddcsx,ddcsy,ddcsz,
614 nstepout,resetstep,nmultisim,repl_ex_nst,repl_ex_seed,pforce,
615 cpt_period,max_hours,deviceOptions,Flags);
617 if (gmx_parallel_env_initialized())
618 gmx_finalize();
620 if (MULTIMASTER(cr)) {
621 thanx(stderr);
624 /* Log file has to be closed in mdrunner if we are appending to it
625 (fplog not set here) */
626 if (MASTER(cr) && !bAppendFiles)
628 gmx_log_close(fplog);
631 return rc;