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,2014,2015, 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 /*! \defgroup module_mdrun Implementation of mdrun
38 * \ingroup group_mdrun
40 * \brief This module contains code that implements mdrun.
44 * \brief This file implements mdrun
46 * \author Berk Hess <hess@kth.se>
47 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
48 * \author Erik Lindahl <erik@kth.se>
49 * \author Mark Abraham <mark.j.abraham@gmail.com>
51 * \ingroup module_mdrun
60 #include "gromacs/commandline/filenm.h"
61 #include "gromacs/commandline/pargs.h"
62 #include "gromacs/gmxlib/main.h"
63 #include "gromacs/gmxlib/network.h"
64 #include "gromacs/gmxlib/readinp.h"
65 #include "gromacs/mdlib/mdrun.h"
66 #include "gromacs/mdrunutility/handlerestart.h"
67 #include "gromacs/mdtypes/commrec.h"
68 #include "gromacs/utility/arraysize.h"
69 #include "gromacs/utility/fatalerror.h"
71 #include "mdrun_main.h"
74 /*! \brief Return whether either of the command-line parameters that
75 * will trigger a multi-simulation is set */
76 static bool is_multisim_option_set(int argc
, const char *const argv
[])
78 for (int i
= 0; i
< argc
; ++i
)
80 if (strcmp(argv
[i
], "-multi") == 0 || strcmp(argv
[i
], "-multidir") == 0)
88 //! Implements C-style main function for mdrun
89 int gmx_mdrun(int argc
, char *argv
[])
91 const char *desc
[] = {
92 "[THISMODULE] is the main computational chemistry engine",
93 "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
94 "but it can also perform Stochastic Dynamics, Energy Minimization,",
95 "test particle insertion or (re)calculation of energies.",
96 "Normal mode analysis is another option. In this case [TT]mdrun[tt]",
97 "builds a Hessian matrix from single conformation.",
98 "For usual Normal Modes-like calculations, make sure that",
99 "the structure provided is properly energy-minimized.",
100 "The generated matrix can be diagonalized by [gmx-nmeig].[PAR]",
101 "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
102 "and distributes the topology over ranks if needed.",
103 "[TT]mdrun[tt] produces at least four output files.",
104 "A single log file ([TT]-g[tt]) is written.",
105 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
106 "optionally forces.",
107 "The structure file ([TT]-c[tt]) contains the coordinates and",
108 "velocities of the last step.",
109 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
110 "pressure, etc, a lot of these things are also printed in the log file.",
111 "Optionally coordinates can be written to a compressed trajectory file",
112 "([TT]-x[tt]).[PAR]",
113 "The option [TT]-dhdl[tt] is only used when free energy calculation is",
115 "Running mdrun efficiently in parallel is a complex topic topic,",
116 "many aspects of which are covered in the online User Guide. You",
117 "should look there for practical advice on using many of the options",
118 "available in mdrun.[PAR]",
119 "ED (essential dynamics) sampling and/or additional flooding potentials",
120 "are switched on by using the [TT]-ei[tt] flag followed by an [REF].edi[ref]",
121 "file. The [REF].edi[ref] file can be produced with the [TT]make_edi[tt] tool",
122 "or by using options in the essdyn menu of the WHAT IF program.",
123 "[TT]mdrun[tt] produces a [REF].xvg[ref] output file that",
124 "contains projections of positions, velocities and forces onto selected",
125 "eigenvectors.[PAR]",
126 "When user-defined potential functions have been selected in the",
127 "[REF].mdp[ref] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]",
128 "a formatted table with potential functions. The file is read from",
129 "either the current directory or from the [TT]GMXLIB[tt] directory.",
130 "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,",
131 "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with",
133 "When pair interactions are present, a separate table for pair interaction",
134 "functions is read using the [TT]-tablep[tt] option.[PAR]",
135 "When tabulated bonded functions are present in the topology,",
136 "interaction functions are read using the [TT]-tableb[tt] option.",
137 "For each different tabulated interaction type the table file name is",
138 "modified in a different way: before the file extension an underscore is",
139 "appended, then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals",
140 "and finally the table number of the interaction type.[PAR]",
141 "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
142 "coordinates and forces when pulling is selected",
143 "in the [REF].mdp[ref] file.[PAR]",
144 "Finally some experimental algorithms can be tested when the",
145 "appropriate options have been given. Currently under",
146 "investigation are: polarizability.",
148 "The option [TT]-membed[tt] does what used to be g_membed, i.e. embed",
149 "a protein into a membrane. This module requires a number of settings",
150 "that are provided in a data file that is the argument of this option.",
151 "For more details in membrane embedding, see the documentation in the",
152 "user guide. The options [TT]-mn[tt] and [TT]-mp[tt] are used to provide",
153 "the index and topology files used for the embedding.",
155 "The option [TT]-pforce[tt] is useful when you suspect a simulation",
156 "crashes due to too large forces. With this option coordinates and",
157 "forces of atoms with a force larger than a certain value will",
158 "be printed to stderr.",
160 "Checkpoints containing the complete state of the system are written",
161 "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
162 "unless option [TT]-cpt[tt] is set to -1.",
163 "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
164 "make sure that a recent state of the system is always available,",
165 "even when the simulation is terminated while writing a checkpoint.",
166 "With [TT]-cpnum[tt] all checkpoint files are kept and appended",
167 "with the step number.",
168 "A simulation can be continued by reading the full state from file",
169 "with option [TT]-cpi[tt]. This option is intelligent in the way that",
170 "if no checkpoint file is found, GROMACS just assumes a normal run and",
171 "starts from the first step of the [REF].tpr[ref] file. By default the output",
172 "will be appending to the existing output files. The checkpoint file",
173 "contains checksums of all output files, such that you will never",
174 "loose data when some output files are modified, corrupt or removed.",
175 "There are three scenarios with [TT]-cpi[tt]:[PAR]",
176 "[TT]*[tt] no files with matching names are present: new output files are written[PAR]",
177 "[TT]*[tt] all files are present with names and checksums matching those stored",
178 "in the checkpoint file: files are appended[PAR]",
179 "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]",
180 "With [TT]-noappend[tt] new output files are opened and the simulation",
181 "part number is added to all output file names.",
182 "Note that in all cases the checkpoint file itself is not renamed",
183 "and will be overwritten, unless its name does not match",
184 "the [TT]-cpo[tt] option.",
186 "With checkpointing the output is appended to previously written",
187 "output files, unless [TT]-noappend[tt] is used or none of the previous",
188 "output files are present (except for the checkpoint file).",
189 "The integrity of the files to be appended is verified using checksums",
190 "which are stored in the checkpoint file. This ensures that output can",
191 "not be mixed up or corrupted due to file appending. When only some",
192 "of the previous output files are present, a fatal error is generated",
193 "and no old output files are modified and no new output files are opened.",
194 "The result with appending will be the same as from a single run.",
195 "The contents will be binary identical, unless you use a different number",
196 "of ranks or dynamic load balancing or the FFT library uses optimizations",
199 "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
200 "file is written at the first neighbor search step where the run time",
201 "exceeds [TT]-maxh[tt]\\*0.99 hours. This option is particularly useful in",
202 "combination with setting [TT]nsteps[tt] to -1 either in the mdp or using the",
203 "similarly named command line option. This results in an infinite run,",
204 "terminated only when the time limit set by [TT]-maxh[tt] is reached (if any)"
205 "or upon receiving a signal."
207 "When [TT]mdrun[tt] receives a TERM signal, it will set nsteps to the current",
208 "step plus one. When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is",
209 "pressed), it will stop after the next neighbor search step ",
210 "(with nstlist=0 at the next step).",
211 "In both cases all the usual output will be written to file.",
212 "When running with MPI, a signal to one of the [TT]mdrun[tt] ranks",
213 "is sufficient, this signal should not be sent to mpirun or",
214 "the [TT]mdrun[tt] process that is the parent of the others.",
216 "Interactive molecular dynamics (IMD) can be activated by using at least one",
217 "of the three IMD switches: The [TT]-imdterm[tt] switch allows to terminate the",
218 "simulation from the molecular viewer (e.g. VMD). With [TT]-imdwait[tt],",
219 "[TT]mdrun[tt] pauses whenever no IMD client is connected. Pulling from the",
220 "IMD remote can be turned on by [TT]-imdpull[tt].",
221 "The port [TT]mdrun[tt] listens to can be altered by [TT]-imdport[tt].The",
222 "file pointed to by [TT]-if[tt] contains atom indices and forces if IMD",
225 "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
229 { efTPR
, NULL
, NULL
, ffREAD
},
230 { efTRN
, "-o", NULL
, ffWRITE
},
231 { efCOMPRESSED
, "-x", NULL
, ffOPTWR
},
232 { efCPT
, "-cpi", NULL
, ffOPTRD
| ffALLOW_MISSING
},
233 { efCPT
, "-cpo", NULL
, ffOPTWR
},
234 { efSTO
, "-c", "confout", ffWRITE
},
235 { efEDR
, "-e", "ener", ffWRITE
},
236 { efLOG
, "-g", "md", ffWRITE
},
237 { efXVG
, "-dhdl", "dhdl", ffOPTWR
},
238 { efXVG
, "-field", "field", ffOPTWR
},
239 { efXVG
, "-table", "table", ffOPTRD
},
240 { efXVG
, "-tablep", "tablep", ffOPTRD
},
241 { efXVG
, "-tableb", "table", ffOPTRD
},
242 { efTRX
, "-rerun", "rerun", ffOPTRD
},
243 { efXVG
, "-tpi", "tpi", ffOPTWR
},
244 { efXVG
, "-tpid", "tpidist", ffOPTWR
},
245 { efEDI
, "-ei", "sam", ffOPTRD
},
246 { efXVG
, "-eo", "edsam", ffOPTWR
},
247 { efXVG
, "-devout", "deviatie", ffOPTWR
},
248 { efXVG
, "-runav", "runaver", ffOPTWR
},
249 { efXVG
, "-px", "pullx", ffOPTWR
},
250 { efXVG
, "-pf", "pullf", ffOPTWR
},
251 { efXVG
, "-ro", "rotation", ffOPTWR
},
252 { efLOG
, "-ra", "rotangles", ffOPTWR
},
253 { efLOG
, "-rs", "rotslabs", ffOPTWR
},
254 { efLOG
, "-rt", "rottorque", ffOPTWR
},
255 { efMTX
, "-mtx", "nm", ffOPTWR
},
256 { efNDX
, "-dn", "dipole", ffOPTWR
},
257 { efRND
, "-multidir", NULL
, ffOPTRDMULT
},
258 { efDAT
, "-membed", "membed", ffOPTRD
},
259 { efTOP
, "-mp", "membed", ffOPTRD
},
260 { efNDX
, "-mn", "membed", ffOPTRD
},
261 { efXVG
, "-if", "imdforces", ffOPTWR
},
262 { efXVG
, "-swap", "swapions", ffOPTWR
}
264 const int NFILE
= asize(fnm
);
266 /* Command line options ! */
267 gmx_bool bDDBondCheck
= TRUE
;
268 gmx_bool bDDBondComm
= TRUE
;
269 gmx_bool bTunePME
= TRUE
;
270 gmx_bool bVerbose
= FALSE
;
271 gmx_bool bRerunVSite
= FALSE
;
272 gmx_bool bConfout
= TRUE
;
273 gmx_bool bReproducible
= FALSE
;
274 gmx_bool bIMDwait
= FALSE
;
275 gmx_bool bIMDterm
= FALSE
;
276 gmx_bool bIMDpull
= FALSE
;
281 int nstglobalcomm
= -1;
283 int repl_ex_seed
= -1;
287 gmx_int64_t nsteps
= -2; /* the value -2 means that the mdp option will be used */
288 int imdport
= 8888; /* can be almost anything, 8888 is easy to remember */
290 rvec realddxyz
= {0, 0, 0};
291 const char *ddno_opt
[ddnoNR
+1] =
292 { NULL
, "interleave", "pp_pme", "cartesian", NULL
};
293 const char *dddlb_opt
[] =
294 { NULL
, "auto", "no", "yes", NULL
};
295 const char *thread_aff_opt
[threadaffNR
+1] =
296 { NULL
, "auto", "on", "off", NULL
};
297 const char *nbpu_opt
[] =
298 { NULL
, "auto", "cpu", "gpu", "gpu_cpu", NULL
};
299 real rdd
= 0.0, rconstr
= 0.0, dlb_scale
= 0.8, pforce
= -1;
300 char *ddcsx
= NULL
, *ddcsy
= NULL
, *ddcsz
= NULL
;
301 real cpt_period
= 15.0, max_hours
= -1;
302 gmx_bool bTryToAppendFiles
= TRUE
;
303 gmx_bool bKeepAndNumCPT
= FALSE
;
304 gmx_bool bResetCountersHalfWay
= FALSE
;
305 gmx_output_env_t
*oenv
= NULL
;
307 /* Non transparent initialization of a complex gmx_hw_opt_t struct.
308 * But unfortunately we are not allowed to call a function here,
309 * since declarations follow below.
311 gmx_hw_opt_t hw_opt
= {
312 0, 0, 0, 0, threadaffSEL
, 0, 0,
313 { NULL
, FALSE
, 0, NULL
}
318 { "-dd", FALSE
, etRVEC
, {&realddxyz
},
319 "Domain decomposition grid, 0 is optimize" },
320 { "-ddorder", FALSE
, etENUM
, {ddno_opt
},
322 { "-npme", FALSE
, etINT
, {&npme
},
323 "Number of separate ranks to be used for PME, -1 is guess" },
324 { "-nt", FALSE
, etINT
, {&hw_opt
.nthreads_tot
},
325 "Total number of threads to start (0 is guess)" },
326 { "-ntmpi", FALSE
, etINT
, {&hw_opt
.nthreads_tmpi
},
327 "Number of thread-MPI threads to start (0 is guess)" },
328 { "-ntomp", FALSE
, etINT
, {&hw_opt
.nthreads_omp
},
329 "Number of OpenMP threads per MPI rank to start (0 is guess)" },
330 { "-ntomp_pme", FALSE
, etINT
, {&hw_opt
.nthreads_omp_pme
},
331 "Number of OpenMP threads per MPI rank to start (0 is -ntomp)" },
332 { "-pin", FALSE
, etENUM
, {thread_aff_opt
},
333 "Whether mdrun should try to set thread affinities" },
334 { "-pinoffset", FALSE
, etINT
, {&hw_opt
.core_pinning_offset
},
335 "The lowest logical core number to which mdrun should pin the first thread" },
336 { "-pinstride", FALSE
, etINT
, {&hw_opt
.core_pinning_stride
},
337 "Pinning distance in logical cores for threads, use 0 to minimize the number of threads per physical core" },
338 { "-gpu_id", FALSE
, etSTR
, {&hw_opt
.gpu_opt
.gpu_id
},
339 "List of GPU device id-s to use, specifies the per-node PP rank to GPU mapping" },
340 { "-ddcheck", FALSE
, etBOOL
, {&bDDBondCheck
},
341 "Check for all bonded interactions with DD" },
342 { "-ddbondcomm", FALSE
, etBOOL
, {&bDDBondComm
},
343 "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
344 { "-rdd", FALSE
, etREAL
, {&rdd
},
345 "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
346 { "-rcon", FALSE
, etREAL
, {&rconstr
},
347 "Maximum distance for P-LINCS (nm), 0 is estimate" },
348 { "-dlb", FALSE
, etENUM
, {dddlb_opt
},
349 "Dynamic load balancing (with DD)" },
350 { "-dds", FALSE
, etREAL
, {&dlb_scale
},
351 "Fraction in (0,1) by whose reciprocal the initial DD cell size will be increased in order to "
352 "provide a margin in which dynamic load balancing can act while preserving the minimum cell size." },
353 { "-ddcsx", FALSE
, etSTR
, {&ddcsx
},
354 "HIDDENA string containing a vector of the relative sizes in the x "
355 "direction of the corresponding DD cells. Only effective with static "
357 { "-ddcsy", FALSE
, etSTR
, {&ddcsy
},
358 "HIDDENA string containing a vector of the relative sizes in the y "
359 "direction of the corresponding DD cells. Only effective with static "
361 { "-ddcsz", FALSE
, etSTR
, {&ddcsz
},
362 "HIDDENA string containing a vector of the relative sizes in the z "
363 "direction of the corresponding DD cells. Only effective with static "
365 { "-gcom", FALSE
, etINT
, {&nstglobalcomm
},
366 "Global communication frequency" },
367 { "-nb", FALSE
, etENUM
, {&nbpu_opt
},
368 "Calculate non-bonded interactions on" },
369 { "-nstlist", FALSE
, etINT
, {&nstlist
},
370 "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
371 { "-tunepme", FALSE
, etBOOL
, {&bTunePME
},
372 "Optimize PME load between PP/PME ranks or GPU/CPU" },
373 { "-v", FALSE
, etBOOL
, {&bVerbose
},
374 "Be loud and noisy" },
375 { "-pforce", FALSE
, etREAL
, {&pforce
},
376 "Print all forces larger than this (kJ/mol nm)" },
377 { "-reprod", FALSE
, etBOOL
, {&bReproducible
},
378 "Try to avoid optimizations that affect binary reproducibility" },
379 { "-cpt", FALSE
, etREAL
, {&cpt_period
},
380 "Checkpoint interval (minutes)" },
381 { "-cpnum", FALSE
, etBOOL
, {&bKeepAndNumCPT
},
382 "Keep and number checkpoint files" },
383 { "-append", FALSE
, etBOOL
, {&bTryToAppendFiles
},
384 "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
385 { "-nsteps", FALSE
, etINT64
, {&nsteps
},
386 "Run this number of steps, overrides .mdp file option (-1 means infinite, -2 means use mdp option, smaller is invalid)" },
387 { "-maxh", FALSE
, etREAL
, {&max_hours
},
388 "Terminate after 0.99 times this time (hours)" },
389 { "-multi", FALSE
, etINT
, {&nmultisim
},
390 "Do multiple simulations in parallel" },
391 { "-replex", FALSE
, etINT
, {&repl_ex_nst
},
392 "Attempt replica exchange periodically with this period (steps)" },
393 { "-nex", FALSE
, etINT
, {&repl_ex_nex
},
394 "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion). -nex zero or not specified gives neighbor replica exchange." },
395 { "-reseed", FALSE
, etINT
, {&repl_ex_seed
},
396 "Seed for replica exchange, -1 is generate a seed" },
397 { "-imdport", FALSE
, etINT
, {&imdport
},
398 "HIDDENIMD listening port" },
399 { "-imdwait", FALSE
, etBOOL
, {&bIMDwait
},
400 "HIDDENPause the simulation while no IMD client is connected" },
401 { "-imdterm", FALSE
, etBOOL
, {&bIMDterm
},
402 "HIDDENAllow termination of the simulation from IMD client" },
403 { "-imdpull", FALSE
, etBOOL
, {&bIMDpull
},
404 "HIDDENAllow pulling in the simulation from IMD client" },
405 { "-rerunvsite", FALSE
, etBOOL
, {&bRerunVSite
},
406 "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
407 { "-confout", FALSE
, etBOOL
, {&bConfout
},
408 "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
409 { "-stepout", FALSE
, etINT
, {&nstepout
},
410 "HIDDENFrequency of writing the remaining wall clock time for the run" },
411 { "-resetstep", FALSE
, etINT
, {&resetstep
},
412 "HIDDENReset cycle counters after these many time steps" },
413 { "-resethway", FALSE
, etBOOL
, {&bResetCountersHalfWay
},
414 "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
419 gmx_bool bDoAppendFiles
, bStartFromCpt
;
422 char **multidir
= NULL
;
426 unsigned long PCA_Flags
= PCA_CAN_SET_DEFFNM
;
427 // With -multi or -multidir, the file names are going to get processed
428 // further (or the working directory changed), so we can't check for their
429 // existence during parsing. It isn't useful to do any completion based on
430 // file system contents, either.
431 if (is_multisim_option_set(argc
, argv
))
433 PCA_Flags
|= PCA_DISABLE_INPUT_FILE_CHECKING
;
436 /* Comment this in to do fexist calls only on master
437 * works not with rerun or tables at the moment
438 * also comment out the version of init_forcerec in md.c
439 * with NULL instead of opt2fn
444 PCA_Flags |= PCA_NOT_READ_NODE;
448 if (!parse_common_args(&argc
, argv
, PCA_Flags
, NFILE
, fnm
, asize(pa
), pa
,
449 asize(desc
), desc
, 0, NULL
, &oenv
))
455 /* we set these early because they might be used in init_multisystem()
456 Note that there is the potential for npme>nnodes until the number of
457 threads is set later on, if there's thread parallelization. That shouldn't
459 dd_node_order
= nenum(ddno_opt
);
460 cr
->npmenodes
= npme
;
462 hw_opt
.thread_affinity
= nenum(thread_aff_opt
);
464 /* now check the -multi and -multidir option */
465 if (opt2bSet("-multidir", NFILE
, fnm
))
469 gmx_fatal(FARGS
, "mdrun -multi and -multidir options are mutually exclusive.");
471 nmultisim
= opt2fns(&multidir
, "-multidir", NFILE
, fnm
);
475 if (repl_ex_nst
!= 0 && nmultisim
< 2)
477 gmx_fatal(FARGS
, "Need at least two replicas for replica exchange (option -multi)");
482 gmx_fatal(FARGS
, "Replica exchange number of exchanges needs to be positive");
487 #ifndef GMX_THREAD_MPI
488 gmx_bool bParFn
= (multidir
== NULL
);
489 init_multisystem(cr
, nmultisim
, multidir
, NFILE
, fnm
, bParFn
);
491 gmx_fatal(FARGS
, "mdrun -multi or -multidir are not supported with the thread-MPI library. "
492 "Please compile GROMACS with a proper external MPI library.");
496 handleRestart(cr
, bTryToAppendFiles
, NFILE
, fnm
,
497 &bDoAppendFiles
, &bStartFromCpt
);
499 Flags
= opt2bSet("-rerun", NFILE
, fnm
) ? MD_RERUN
: 0;
500 Flags
= Flags
| (bDDBondCheck
? MD_DDBONDCHECK
: 0);
501 Flags
= Flags
| (bDDBondComm
? MD_DDBONDCOMM
: 0);
502 Flags
= Flags
| (bTunePME
? MD_TUNEPME
: 0);
503 Flags
= Flags
| (bConfout
? MD_CONFOUT
: 0);
504 Flags
= Flags
| (bRerunVSite
? MD_RERUN_VSITE
: 0);
505 Flags
= Flags
| (bReproducible
? MD_REPRODUCIBLE
: 0);
506 Flags
= Flags
| (bDoAppendFiles
? MD_APPENDFILES
: 0);
507 Flags
= Flags
| (opt2parg_bSet("-append", asize(pa
), pa
) ? MD_APPENDFILESSET
: 0);
508 Flags
= Flags
| (bKeepAndNumCPT
? MD_KEEPANDNUMCPT
: 0);
509 Flags
= Flags
| (bStartFromCpt
? MD_STARTFROMCPT
: 0);
510 Flags
= Flags
| (bResetCountersHalfWay
? MD_RESETCOUNTERSHALFWAY
: 0);
511 Flags
= Flags
| (opt2parg_bSet("-ntomp", asize(pa
), pa
) ? MD_NTOMPSET
: 0);
512 Flags
= Flags
| (bIMDwait
? MD_IMDWAIT
: 0);
513 Flags
= Flags
| (bIMDterm
? MD_IMDTERM
: 0);
514 Flags
= Flags
| (bIMDpull
? MD_IMDPULL
: 0);
516 /* We postpone opening the log file if we are appending, so we can
517 first truncate the old log file and append to the correct position
519 if (MASTER(cr
) && !bDoAppendFiles
)
521 gmx_log_open(ftp2fn(efLOG
, NFILE
, fnm
), cr
,
522 Flags
& MD_APPENDFILES
, &fplog
);
529 ddxyz
[XX
] = (int)(realddxyz
[XX
] + 0.5);
530 ddxyz
[YY
] = (int)(realddxyz
[YY
] + 0.5);
531 ddxyz
[ZZ
] = (int)(realddxyz
[ZZ
] + 0.5);
533 rc
= gmx::mdrunner(&hw_opt
, fplog
, cr
, NFILE
, fnm
, oenv
, bVerbose
,
534 nstglobalcomm
, ddxyz
, dd_node_order
, rdd
, rconstr
,
535 dddlb_opt
[0], dlb_scale
, ddcsx
, ddcsy
, ddcsz
,
536 nbpu_opt
[0], nstlist
,
537 nsteps
, nstepout
, resetstep
,
538 nmultisim
, repl_ex_nst
, repl_ex_nex
, repl_ex_seed
,
539 pforce
, cpt_period
, max_hours
, imdport
, Flags
);
541 /* Log file has to be closed in mdrunner if we are appending to it
542 (fplog not set here) */
543 if (MASTER(cr
) && !bDoAppendFiles
)
545 gmx_log_close(fplog
);