Activate PME on GPUs
[gromacs.git] / src / programs / mdrun / mdrun.cpp
blob0c131c9a16a078d9b92cf70b3d4bfddbfc6ca5cd
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2011,2012,2013,2014,2015,2016,2017, 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.
42 /*! \internal \file
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
53 #include "gmxpre.h"
55 #include "config.h"
57 #include <cstdio>
58 #include <cstdlib>
59 #include <cstring>
61 #include "gromacs/commandline/filenm.h"
62 #include "gromacs/commandline/pargs.h"
63 #include "gromacs/domdec/domdec.h"
64 #include "gromacs/gmxlib/network.h"
65 #include "gromacs/mdlib/main.h"
66 #include "gromacs/mdlib/mdrun.h"
67 #include "gromacs/mdrunutility/handlerestart.h"
68 #include "gromacs/mdtypes/commrec.h"
69 #include "gromacs/utility/arraysize.h"
70 #include "gromacs/utility/fatalerror.h"
71 #include "gromacs/utility/smalloc.h"
73 #include "mdrun_main.h"
74 #include "repl_ex.h"
75 #include "runner.h"
77 /*! \brief Return whether either of the command-line parameters that
78 * will trigger a multi-simulation is set */
79 static bool is_multisim_option_set(int argc, const char *const argv[])
81 for (int i = 0; i < argc; ++i)
83 if (strcmp(argv[i], "-multi") == 0 || strcmp(argv[i], "-multidir") == 0)
85 return true;
88 return false;
91 //! Implements C-style main function for mdrun
92 int gmx_mdrun(int argc, char *argv[])
94 gmx::Mdrunner runner;
95 return runner.mainFunction(argc, argv);
98 namespace gmx
101 int Mdrunner::mainFunction(int argc, char *argv[])
103 const char *desc[] = {
104 "[THISMODULE] is the main computational chemistry engine",
105 "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
106 "but it can also perform Stochastic Dynamics, Energy Minimization,",
107 "test particle insertion or (re)calculation of energies.",
108 "Normal mode analysis is another option. In this case [TT]mdrun[tt]",
109 "builds a Hessian matrix from single conformation.",
110 "For usual Normal Modes-like calculations, make sure that",
111 "the structure provided is properly energy-minimized.",
112 "The generated matrix can be diagonalized by [gmx-nmeig].[PAR]",
113 "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
114 "and distributes the topology over ranks if needed.",
115 "[TT]mdrun[tt] produces at least four output files.",
116 "A single log file ([TT]-g[tt]) is written.",
117 "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
118 "optionally forces.",
119 "The structure file ([TT]-c[tt]) contains the coordinates and",
120 "velocities of the last step.",
121 "The energy file ([TT]-e[tt]) contains energies, the temperature,",
122 "pressure, etc, a lot of these things are also printed in the log file.",
123 "Optionally coordinates can be written to a compressed trajectory file",
124 "([TT]-x[tt]).[PAR]",
125 "The option [TT]-dhdl[tt] is only used when free energy calculation is",
126 "turned on.[PAR]",
127 "Running mdrun efficiently in parallel is a complex topic topic,",
128 "many aspects of which are covered in the online User Guide. You",
129 "should look there for practical advice on using many of the options",
130 "available in mdrun.[PAR]",
131 "ED (essential dynamics) sampling and/or additional flooding potentials",
132 "are switched on by using the [TT]-ei[tt] flag followed by an [REF].edi[ref]",
133 "file. The [REF].edi[ref] file can be produced with the [TT]make_edi[tt] tool",
134 "or by using options in the essdyn menu of the WHAT IF program.",
135 "[TT]mdrun[tt] produces a [REF].xvg[ref] output file that",
136 "contains projections of positions, velocities and forces onto selected",
137 "eigenvectors.[PAR]",
138 "When user-defined potential functions have been selected in the",
139 "[REF].mdp[ref] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]",
140 "a formatted table with potential functions. The file is read from",
141 "either the current directory or from the [TT]GMXLIB[tt] directory.",
142 "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,",
143 "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with",
144 "normal Coulomb.",
145 "When pair interactions are present, a separate table for pair interaction",
146 "functions is read using the [TT]-tablep[tt] option.[PAR]",
147 "When tabulated bonded functions are present in the topology,",
148 "interaction functions are read using the [TT]-tableb[tt] option.",
149 "For each different tabulated interaction type used, a table file name must",
150 "be given. For the topology to work, a file name given here must match a",
151 "character sequence before the file extension. That sequence is: an underscore,",
152 "then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals,",
153 "and finally the matching table number index used in the topology.[PAR]",
154 "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
155 "coordinates and forces when pulling is selected",
156 "in the [REF].mdp[ref] file.[PAR]",
157 "Finally some experimental algorithms can be tested when the",
158 "appropriate options have been given. Currently under",
159 "investigation are: polarizability.",
160 "[PAR]",
161 "The option [TT]-membed[tt] does what used to be g_membed, i.e. embed",
162 "a protein into a membrane. This module requires a number of settings",
163 "that are provided in a data file that is the argument of this option.",
164 "For more details in membrane embedding, see the documentation in the",
165 "user guide. The options [TT]-mn[tt] and [TT]-mp[tt] are used to provide",
166 "the index and topology files used for the embedding.",
167 "[PAR]",
168 "The option [TT]-pforce[tt] is useful when you suspect a simulation",
169 "crashes due to too large forces. With this option coordinates and",
170 "forces of atoms with a force larger than a certain value will",
171 "be printed to stderr. It will also terminate the run when non-finite",
172 "forces are present.",
173 "[PAR]",
174 "Checkpoints containing the complete state of the system are written",
175 "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
176 "unless option [TT]-cpt[tt] is set to -1.",
177 "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
178 "make sure that a recent state of the system is always available,",
179 "even when the simulation is terminated while writing a checkpoint.",
180 "With [TT]-cpnum[tt] all checkpoint files are kept and appended",
181 "with the step number.",
182 "A simulation can be continued by reading the full state from file",
183 "with option [TT]-cpi[tt]. This option is intelligent in the way that",
184 "if no checkpoint file is found, GROMACS just assumes a normal run and",
185 "starts from the first step of the [REF].tpr[ref] file. By default the output",
186 "will be appending to the existing output files. The checkpoint file",
187 "contains checksums of all output files, such that you will never",
188 "loose data when some output files are modified, corrupt or removed.",
189 "There are three scenarios with [TT]-cpi[tt]:[PAR]",
190 "[TT]*[tt] no files with matching names are present: new output files are written[PAR]",
191 "[TT]*[tt] all files are present with names and checksums matching those stored",
192 "in the checkpoint file: files are appended[PAR]",
193 "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]",
194 "With [TT]-noappend[tt] new output files are opened and the simulation",
195 "part number is added to all output file names.",
196 "Note that in all cases the checkpoint file itself is not renamed",
197 "and will be overwritten, unless its name does not match",
198 "the [TT]-cpo[tt] option.",
199 "[PAR]",
200 "With checkpointing the output is appended to previously written",
201 "output files, unless [TT]-noappend[tt] is used or none of the previous",
202 "output files are present (except for the checkpoint file).",
203 "The integrity of the files to be appended is verified using checksums",
204 "which are stored in the checkpoint file. This ensures that output can",
205 "not be mixed up or corrupted due to file appending. When only some",
206 "of the previous output files are present, a fatal error is generated",
207 "and no old output files are modified and no new output files are opened.",
208 "The result with appending will be the same as from a single run.",
209 "The contents will be binary identical, unless you use a different number",
210 "of ranks or dynamic load balancing or the FFT library uses optimizations",
211 "through timing.",
212 "[PAR]",
213 "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
214 "file is written at the first neighbor search step where the run time",
215 "exceeds [TT]-maxh[tt]\\*0.99 hours. This option is particularly useful in",
216 "combination with setting [TT]nsteps[tt] to -1 either in the mdp or using the",
217 "similarly named command line option. This results in an infinite run,",
218 "terminated only when the time limit set by [TT]-maxh[tt] is reached (if any)"
219 "or upon receiving a signal."
220 "[PAR]",
221 "When [TT]mdrun[tt] receives a TERM signal, it will stop as soon as",
222 "checkpoint file can be written, i.e. after the next global communication step.",
223 "When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is",
224 "pressed), it will stop at the next neighbor search step or at the",
225 "second global communication step, whichever happens later.",
226 "In both cases all the usual output will be written to file.",
227 "When running with MPI, a signal to one of the [TT]mdrun[tt] ranks",
228 "is sufficient, this signal should not be sent to mpirun or",
229 "the [TT]mdrun[tt] process that is the parent of the others.",
230 "[PAR]",
231 "Interactive molecular dynamics (IMD) can be activated by using at least one",
232 "of the three IMD switches: The [TT]-imdterm[tt] switch allows one to terminate",
233 "the simulation from the molecular viewer (e.g. VMD). With [TT]-imdwait[tt],",
234 "[TT]mdrun[tt] pauses whenever no IMD client is connected. Pulling from the",
235 "IMD remote can be turned on by [TT]-imdpull[tt].",
236 "The port [TT]mdrun[tt] listens to can be altered by [TT]-imdport[tt].The",
237 "file pointed to by [TT]-if[tt] contains atom indices and forces if IMD",
238 "pulling is used."
239 "[PAR]",
240 "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
243 /* Command line options */
244 rvec realddxyz = {0, 0, 0};
245 const char *ddrank_opt_choices[static_cast<int>(DdRankOrder::nr)+1] =
246 { nullptr, "interleave", "pp_pme", "cartesian", nullptr };
247 const char *dddlb_opt_choices[static_cast<int>(DlbOption::nr)+1] =
248 { nullptr, "auto", "no", "yes", nullptr };
249 const char *thread_aff_opt_choices[threadaffNR+1] =
250 { nullptr, "auto", "on", "off", nullptr };
251 const char *nbpu_opt_choices[] =
252 { nullptr, "auto", "cpu", "gpu", nullptr };
253 const char *pme_opt_choices[] =
254 { nullptr, "auto", "cpu", "gpu", nullptr };
255 const char *pme_fft_opt_choices[] =
256 { nullptr, "auto", "cpu", "gpu", nullptr };
257 gmx_bool bTryToAppendFiles = TRUE;
258 const char *gpuIdsAvailable = "";
259 const char *userGpuTaskAssignment = "";
261 ImdOptions &imdOptions = mdrunOptions.imdOptions;
263 t_pargs pa[] = {
265 { "-dd", FALSE, etRVEC, {&realddxyz},
266 "Domain decomposition grid, 0 is optimize" },
267 { "-ddorder", FALSE, etENUM, {ddrank_opt_choices},
268 "DD rank order" },
269 { "-npme", FALSE, etINT, {&domdecOptions.numPmeRanks},
270 "Number of separate ranks to be used for PME, -1 is guess" },
271 { "-nt", FALSE, etINT, {&hw_opt.nthreads_tot},
272 "Total number of threads to start (0 is guess)" },
273 { "-ntmpi", FALSE, etINT, {&hw_opt.nthreads_tmpi},
274 "Number of thread-MPI threads to start (0 is guess)" },
275 { "-ntomp", FALSE, etINT, {&hw_opt.nthreads_omp},
276 "Number of OpenMP threads per MPI rank to start (0 is guess)" },
277 { "-ntomp_pme", FALSE, etINT, {&hw_opt.nthreads_omp_pme},
278 "Number of OpenMP threads per MPI rank to start (0 is -ntomp)" },
279 { "-pin", FALSE, etENUM, {thread_aff_opt_choices},
280 "Whether mdrun should try to set thread affinities" },
281 { "-pinoffset", FALSE, etINT, {&hw_opt.core_pinning_offset},
282 "The lowest logical core number to which mdrun should pin the first thread" },
283 { "-pinstride", FALSE, etINT, {&hw_opt.core_pinning_stride},
284 "Pinning distance in logical cores for threads, use 0 to minimize the number of threads per physical core" },
285 { "-gpu_id", FALSE, etSTR, {&gpuIdsAvailable},
286 "List of unique GPU device IDs available to use" },
287 { "-gputasks", FALSE, etSTR, {&userGpuTaskAssignment},
288 "List of GPU device IDs, mapping each PP task on each node to a device" },
289 { "-ddcheck", FALSE, etBOOL, {&domdecOptions.checkBondedInteractions},
290 "Check for all bonded interactions with DD" },
291 { "-ddbondcomm", FALSE, etBOOL, {&domdecOptions.useBondedCommunication},
292 "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
293 { "-rdd", FALSE, etREAL, {&domdecOptions.minimumCommunicationRange},
294 "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
295 { "-rcon", FALSE, etREAL, {&domdecOptions.constraintCommunicationRange},
296 "Maximum distance for P-LINCS (nm), 0 is estimate" },
297 { "-dlb", FALSE, etENUM, {dddlb_opt_choices},
298 "Dynamic load balancing (with DD)" },
299 { "-dds", FALSE, etREAL, {&domdecOptions.dlbScaling},
300 "Fraction in (0,1) by whose reciprocal the initial DD cell size will be increased in order to "
301 "provide a margin in which dynamic load balancing can act while preserving the minimum cell size." },
302 { "-ddcsx", FALSE, etSTR, {&domdecOptions.cellSizeX},
303 "HIDDENA string containing a vector of the relative sizes in the x "
304 "direction of the corresponding DD cells. Only effective with static "
305 "load balancing." },
306 { "-ddcsy", FALSE, etSTR, {&domdecOptions.cellSizeY},
307 "HIDDENA string containing a vector of the relative sizes in the y "
308 "direction of the corresponding DD cells. Only effective with static "
309 "load balancing." },
310 { "-ddcsz", FALSE, etSTR, {&domdecOptions.cellSizeZ},
311 "HIDDENA string containing a vector of the relative sizes in the z "
312 "direction of the corresponding DD cells. Only effective with static "
313 "load balancing." },
314 { "-gcom", FALSE, etINT, {&mdrunOptions.globalCommunicationInterval},
315 "Global communication frequency" },
316 { "-nb", FALSE, etENUM, {nbpu_opt_choices},
317 "Calculate non-bonded interactions on" },
318 { "-nstlist", FALSE, etINT, {&nstlist_cmdline},
319 "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
320 { "-tunepme", FALSE, etBOOL, {&mdrunOptions.tunePme},
321 "Optimize PME load between PP/PME ranks or GPU/CPU (only with the Verlet cut-off scheme)" },
322 { "-pme", FALSE, etENUM, {pme_opt_choices},
323 "Perform PME calculations on" },
324 { "-pmefft", FALSE, etENUM, {pme_fft_opt_choices},
325 "Perform PME FFT calculations on" },
326 { "-v", FALSE, etBOOL, {&mdrunOptions.verbose},
327 "Be loud and noisy" },
328 { "-pforce", FALSE, etREAL, {&pforce},
329 "Print all forces larger than this (kJ/mol nm)" },
330 { "-reprod", FALSE, etBOOL, {&mdrunOptions.reproducible},
331 "Try to avoid optimizations that affect binary reproducibility" },
332 { "-cpt", FALSE, etREAL, {&mdrunOptions.checkpointOptions.period},
333 "Checkpoint interval (minutes)" },
334 { "-cpnum", FALSE, etBOOL, {&mdrunOptions.checkpointOptions.keepAndNumberCheckpointFiles},
335 "Keep and number checkpoint files" },
336 { "-append", FALSE, etBOOL, {&bTryToAppendFiles},
337 "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
338 { "-nsteps", FALSE, etINT64, {&mdrunOptions.numStepsCommandline},
339 "Run this number of steps, overrides .mdp file option (-1 means infinite, -2 means use mdp option, smaller is invalid)" },
340 { "-maxh", FALSE, etREAL, {&mdrunOptions.maximumHoursToRun},
341 "Terminate after 0.99 times this time (hours)" },
342 { "-multi", FALSE, etINT, {&nmultisim},
343 "Do multiple simulations in parallel" },
344 { "-replex", FALSE, etINT, {&replExParams.exchangeInterval},
345 "Attempt replica exchange periodically with this period (steps)" },
346 { "-nex", FALSE, etINT, {&replExParams.numExchanges},
347 "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion). -nex zero or not specified gives neighbor replica exchange." },
348 { "-reseed", FALSE, etINT, {&replExParams.randomSeed},
349 "Seed for replica exchange, -1 is generate a seed" },
350 { "-imdport", FALSE, etINT, {&imdOptions.port},
351 "HIDDENIMD listening port" },
352 { "-imdwait", FALSE, etBOOL, {&imdOptions.wait},
353 "HIDDENPause the simulation while no IMD client is connected" },
354 { "-imdterm", FALSE, etBOOL, {&imdOptions.terminatable},
355 "HIDDENAllow termination of the simulation from IMD client" },
356 { "-imdpull", FALSE, etBOOL, {&imdOptions.pull},
357 "HIDDENAllow pulling in the simulation from IMD client" },
358 { "-rerunvsite", FALSE, etBOOL, {&mdrunOptions.rerunConstructVsites},
359 "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
360 { "-confout", FALSE, etBOOL, {&mdrunOptions.writeConfout},
361 "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
362 { "-stepout", FALSE, etINT, {&mdrunOptions.verboseStepPrintInterval},
363 "HIDDENFrequency of writing the remaining wall clock time for the run" },
364 { "-resetstep", FALSE, etINT, {&mdrunOptions.timingOptions.resetStep},
365 "HIDDENReset cycle counters after these many time steps" },
366 { "-resethway", FALSE, etBOOL, {&mdrunOptions.timingOptions.resetHalfway},
367 "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
369 int rc;
370 char **multidir = nullptr;
372 cr = init_commrec();
374 unsigned long PCA_Flags = PCA_CAN_SET_DEFFNM;
375 // With -multi or -multidir, the file names are going to get processed
376 // further (or the working directory changed), so we can't check for their
377 // existence during parsing. It isn't useful to do any completion based on
378 // file system contents, either.
379 if (is_multisim_option_set(argc, argv))
381 PCA_Flags |= PCA_DISABLE_INPUT_FILE_CHECKING;
384 /* Comment this in to do fexist calls only on master
385 * works not with rerun or tables at the moment
386 * also comment out the version of init_forcerec in md.c
387 * with NULL instead of opt2fn
390 if (!MASTER(cr))
392 PCA_Flags |= PCA_NOT_READ_NODE;
396 if (!parse_common_args(&argc, argv, PCA_Flags, nfile, fnm, asize(pa), pa,
397 asize(desc), desc, 0, nullptr, &oenv))
399 sfree(cr);
400 return 0;
403 // Handle the options that permits the user to either declare
404 // which compatible GPUs are availble for use, or to select a GPU
405 // task assignment. Either could be in an environment variable (so
406 // that there is a way to customize it, when using MPI in
407 // heterogeneous contexts).
409 // TODO Argument parsing can't handle std::string. We should
410 // fix that by changing the parsing, once more of the roles of
411 // handling, validating and implementing defaults for user
412 // command-line options have been seperated.
413 hw_opt.gpuIdsAvailable = gpuIdsAvailable;
414 hw_opt.userGpuTaskAssignment = userGpuTaskAssignment;
416 const char *env = getenv("GMX_GPU_ID");
417 if (env != nullptr)
419 if (!hw_opt.gpuIdsAvailable.empty())
421 gmx_fatal(FARGS, "GMX_GPU_ID and -gpu_id can not be used at the same time");
423 hw_opt.gpuIdsAvailable = env;
426 env = getenv("GMX_GPUTASKS");
427 if (env != nullptr)
429 if (!hw_opt.userGpuTaskAssignment.empty())
431 gmx_fatal(FARGS, "GMX_GPUTASKS and -gputasks can not be used at the same time");
433 hw_opt.userGpuTaskAssignment = env;
436 if (!hw_opt.gpuIdsAvailable.empty() && !hw_opt.userGpuTaskAssignment.empty())
438 gmx_fatal(FARGS, "-gpu_id and -gputasks cannot be used at the same time");
442 hw_opt.thread_affinity = nenum(thread_aff_opt_choices);
444 /* now check the -multi and -multidir option */
445 if (opt2bSet("-multidir", nfile, fnm))
447 if (nmultisim > 0)
449 gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive.");
451 nmultisim = opt2fns(&multidir, "-multidir", nfile, fnm);
455 if (replExParams.exchangeInterval != 0 && nmultisim < 2)
457 gmx_fatal(FARGS, "Need at least two replicas for replica exchange (option -multi)");
460 if (replExParams.numExchanges < 0)
462 gmx_fatal(FARGS, "Replica exchange number of exchanges needs to be positive");
465 if (nmultisim >= 1)
467 #if !GMX_THREAD_MPI
468 init_multisystem(cr, nmultisim, multidir, nfile, fnm);
469 #else
470 gmx_fatal(FARGS, "mdrun -multi or -multidir are not supported with the thread-MPI library. "
471 "Please compile GROMACS with a proper external MPI library.");
472 #endif
475 if (!opt2bSet("-cpi", nfile, fnm))
477 // If we are not starting from a checkpoint we never allow files to be appended
478 // to, since that has caused a ton of strange behaviour and bugs in the past.
479 if (opt2parg_bSet("-append", asize(pa), pa))
481 // If the user explicitly used the -append option, explain that it is not possible.
482 gmx_fatal(FARGS, "GROMACS can only append to files when restarting from a checkpoint.");
484 else
486 // If the user did not say anything explicit, just disable appending.
487 bTryToAppendFiles = FALSE;
491 ContinuationOptions &continuationOptions = mdrunOptions.continuationOptions;
493 continuationOptions.appendFilesOptionSet = opt2parg_bSet("-append", asize(pa), pa);
495 handleRestart(cr, bTryToAppendFiles, nfile, fnm, &continuationOptions.appendFiles, &continuationOptions.startedFromCheckpoint);
497 mdrunOptions.rerun = opt2bSet("-rerun", nfile, fnm);
498 mdrunOptions.ntompOptionIsSet = opt2parg_bSet("-ntomp", asize(pa), pa);
500 /* We postpone opening the log file if we are appending, so we can
501 first truncate the old log file and append to the correct position
502 there instead. */
503 if (MASTER(cr) && !continuationOptions.appendFiles)
505 gmx_log_open(ftp2fn(efLOG, nfile, fnm), cr,
506 continuationOptions.appendFiles, &fplog);
508 else
510 fplog = nullptr;
513 domdecOptions.rankOrder = static_cast<DdRankOrder>(nenum(ddrank_opt_choices));
514 domdecOptions.dlbOption = static_cast<DlbOption>(nenum(dddlb_opt_choices));
515 domdecOptions.numCells[XX] = (int)(realddxyz[XX] + 0.5);
516 domdecOptions.numCells[YY] = (int)(realddxyz[YY] + 0.5);
517 domdecOptions.numCells[ZZ] = (int)(realddxyz[ZZ] + 0.5);
519 nbpu_opt = nbpu_opt_choices[0];
520 pme_opt = pme_opt_choices[0];
521 pme_fft_opt = pme_fft_opt_choices[0];
524 rc = mdrunner();
526 /* Log file has to be closed in mdrunner if we are appending to it
527 (fplog not set here) */
528 if (MASTER(cr) && !continuationOptions.appendFiles)
530 gmx_log_close(fplog);
533 return rc;
536 } // namespace