Put mdrun options in structs
authorBerk Hess <hess@kth.se>
Wed, 30 Aug 2017 21:14:01 +0000 (23:14 +0200)
committerKasson <kasson@gmail.com>
Sun, 3 Sep 2017 04:56:41 +0000 (06:56 +0200)
Collects all mdrun options contained in flags, plus a few more,
into a new struct MdrunOptions with sub-structs.
All boolean options still use gmx_bool, and not bool, because
the command line parsing does not support bool yet.
Moved function declarations for expanded.cpp to expanded.h.
More options can be collected, but that would increase the size
of this change even more.

Change-Id: I21ea07b443e89cbfa21986bb8bd58a5657cbfbfa

28 files changed:
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec.h
src/gromacs/gmxpreprocess/readpull.cpp
src/gromacs/imd/imd.cpp
src/gromacs/imd/imd.h
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/expanded.cpp
src/gromacs/mdlib/expanded.h [new file with mode: 0644]
src/gromacs/mdlib/integrator.h
src/gromacs/mdlib/mdoutf.cpp
src/gromacs/mdlib/mdoutf.h
src/gromacs/mdlib/mdrun.h
src/gromacs/mdlib/minimize.cpp
src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdlib/sim_util.h
src/gromacs/mdlib/tpi.cpp
src/gromacs/mdrunutility/handlerestart.cpp
src/gromacs/mdrunutility/handlerestart.h
src/gromacs/pulling/pull.cpp
src/gromacs/pulling/pull.h
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/pulling/pull_rotation.h
src/gromacs/swap/swapcoords.cpp
src/gromacs/swap/swapcoords.h
src/programs/mdrun/md.cpp
src/programs/mdrun/mdrun.cpp
src/programs/mdrun/runner.cpp
src/programs/mdrun/runner.h

index 298d5f57725a998969afe3e169a40d74bbeaa803..40ed1e789d3c4c3a3aa0ddf325d8ad5511518b6c 100644 (file)
@@ -6192,13 +6192,14 @@ static int forceDlbOffOrBail(int                cmdlineDlbState,
  * \param [in] cr          Pointer to MPI communication object.
  * \param [in] dlbOption   Enum value for the DLB option.
  * \param [in] bRecordLoad True if the load balancer is recording load information.
- * \param [in] Flags       Simulation flags passed from main.
+ * \param [in] mdrunOptions  Options for mdrun.
  * \param [in] ir          Pointer mdrun to input parameters.
  * \returns                DLB initial/startup state.
  */
 static int determineInitialDlbState(FILE *fplog, t_commrec *cr,
                                     DlbOption dlbOption, gmx_bool bRecordLoad,
-                                    unsigned long Flags, const t_inputrec *ir)
+                                    const MdrunOptions &mdrunOptions,
+                                    const t_inputrec *ir)
 {
     int dlbState = edlbsOffCanTurnOn;
 
@@ -6211,7 +6212,7 @@ static int determineInitialDlbState(FILE *fplog, t_commrec *cr,
     }
 
     /* Reruns don't support DLB: bail or override auto mode */
-    if (Flags & MD_RERUN)
+    if (mdrunOptions.rerun)
     {
         std::string reasonStr = "it is not supported in reruns.";
         return forceDlbOffOrBail(dlbState, reasonStr, cr, fplog);
@@ -6231,7 +6232,7 @@ static int determineInitialDlbState(FILE *fplog, t_commrec *cr,
         return forceDlbOffOrBail(dlbState, reasonStr, cr, fplog);
     }
 
-    if (Flags & MD_REPRODUCIBLE)
+    if (mdrunOptions.reproducible)
     {
         std::string reasonStr = "you started a reproducible run.";
         switch (dlbState)
@@ -6336,7 +6337,7 @@ static gmx_domdec_comm_t *init_dd_comm()
 /*! \brief Set the cell size and interaction limits, as well as the DD grid */
 static void set_dd_limits_and_grid(FILE *fplog, t_commrec *cr, gmx_domdec_t *dd,
                                    const DomdecOptions &options,
-                                   unsigned long Flags,
+                                   const MdrunOptions &mdrunOptions,
                                    const gmx_mtop_t *mtop,
                                    const t_inputrec *ir,
                                    matrix box, const rvec *x,
@@ -6360,7 +6361,7 @@ static void set_dd_limits_and_grid(FILE *fplog, t_commrec *cr, gmx_domdec_t *dd,
     /* Initialize to GPU share count to 0, might change later */
     comm->nrank_gpu_shared = 0;
 
-    comm->dlbState         = determineInitialDlbState(fplog, cr, options.dlbOption, comm->bRecordLoad, Flags, ir);
+    comm->dlbState         = determineInitialDlbState(fplog, cr, options.dlbOption, comm->bRecordLoad, mdrunOptions, ir);
     dd_dlb_set_should_check_whether_to_turn_dlb_on(dd, TRUE);
     /* To consider turning DLB on after 2*nstlist steps we need to check
      * at partitioning count 3. Thus we need to increase the first count by 2.
@@ -7232,7 +7233,7 @@ DomdecOptions::DomdecOptions() :
 
 gmx_domdec_t *init_domain_decomposition(FILE *fplog, t_commrec *cr,
                                         const DomdecOptions &options,
-                                        unsigned long Flags,
+                                        const MdrunOptions &mdrunOptions,
                                         const gmx_mtop_t *mtop,
                                         const t_inputrec *ir,
                                         matrix box, rvec *x,
@@ -7253,7 +7254,7 @@ gmx_domdec_t *init_domain_decomposition(FILE *fplog, t_commrec *cr,
 
     set_dd_envvar_options(fplog, dd, cr->nodeid);
 
-    set_dd_limits_and_grid(fplog, cr, dd, options, Flags,
+    set_dd_limits_and_grid(fplog, cr, dd, options, mdrunOptions,
                            mtop, ir,
                            box, x,
                            ddbox,
index ecafb4c3c30a9ebc55fcbb4d08e89c764cfb5603..a64cbbef420814affacc896e1b8280dc0f2cf23c 100644 (file)
@@ -75,6 +75,7 @@
 struct gmx_domdec_t;
 struct gmx_ddbox_t;
 struct gmx_domdec_zones_t;
+struct MdrunOptions;
 struct t_commrec;
 struct t_inputrec;
 class t_state;
@@ -186,7 +187,7 @@ struct DomdecOptions
 gmx_domdec_t *init_domain_decomposition(FILE                *fplog,
                                         t_commrec           *cr,
                                         const DomdecOptions &options,
-                                        unsigned long        Flags,
+                                        const MdrunOptions  &mdrunOptions,
                                         const gmx_mtop_t    *mtop,
                                         const t_inputrec    *ir,
                                         matrix               box,
index 161674e1be460d65a2d481db5603d5387219ecfa..96bcf9fb5c6b84c19243734eda70d4a4cae5a5b4 100644 (file)
@@ -45,6 +45,7 @@
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/mdatoms.h"
+#include "gromacs/mdlib/mdrun.h"
 #include "gromacs/mdtypes/inputrec.h"
 #include "gromacs/mdtypes/md_enums.h"
 #include "gromacs/mdtypes/pull-params.h"
@@ -513,7 +514,7 @@ pull_t *set_pull_init(t_inputrec *ir, const gmx_mtop_t *mtop,
     double         t_start;
 
     pull      = ir->pull;
-    pull_work = init_pull(nullptr, pull, ir, 0, nullptr, mtop, nullptr, oenv, lambda, FALSE, 0);
+    pull_work = init_pull(nullptr, pull, ir, 0, nullptr, mtop, nullptr, oenv, lambda, FALSE, ContinuationOptions());
     md        = init_mdatoms(nullptr, mtop, ir->efep);
     atoms2md(mtop, ir, -1, nullptr, mtop->natoms, md);
     if (ir->efep)
index 9bd65ae71cfc4ea0a1cca047e62a5d32fe8e9cfc..1d2d157bedc9b753c845f9a80353249ee75297ca 100644 (file)
@@ -978,11 +978,11 @@ static void imd_readcommand(t_gmx_IMD_setup *IMDsetup)
  *
  * Call on master only.
  */
-static FILE *open_imd_out(const char             *fn,
-                          t_gmx_IMD_setup        *IMDsetup,
-                          int                     nat_total,
-                          const gmx_output_env_t *oenv,
-                          unsigned long           Flags)
+static FILE *open_imd_out(const char                *fn,
+                          t_gmx_IMD_setup           *IMDsetup,
+                          int                        nat_total,
+                          const gmx_output_env_t    *oenv,
+                          const ContinuationOptions &continuationOptions)
 {
     FILE       *fp;
 
@@ -991,7 +991,7 @@ static FILE *open_imd_out(const char             *fn,
     if (fn && oenv)
     {
         /* If we append to an existing file, all the header information is already there */
-        if (Flags & MD_APPENDFILES)
+        if (continuationOptions.appendFiles)
         {
             fp = gmx_fio_fopen(fn, "a+");
         }
@@ -1294,8 +1294,7 @@ void init_IMD(t_inputrec             *ir,
               int                     nfile,
               const t_filenm          fnm[],
               const gmx_output_env_t *oenv,
-              int                     imdport,
-              unsigned long           Flags)
+              const MdrunOptions     &mdrunOptions)
 {
     int              i;
     int              nat_total;
@@ -1310,12 +1309,14 @@ void init_IMD(t_inputrec             *ir,
         return;
     }
 
+    const ImdOptions &options = mdrunOptions.imdOptions;
+
     /* It seems we have a .tpr file that defines an IMD group and thus allows IMD sessions.
      * Check whether we can actually provide the IMD functionality for this setting: */
     if (MASTER(cr))
     {
         /* Check whether IMD was enabled by one of the command line switches: */
-        if ((Flags & MD_IMDWAIT) || (Flags & MD_IMDTERM) || (Flags & MD_IMDPULL))
+        if (options.wait || options.terminatable || options.pull)
         {
             /* Multiple simulations or replica exchange */
             if (MULTISIM(cr))
@@ -1373,13 +1374,13 @@ void init_IMD(t_inputrec             *ir,
     /* Initialize IMD setup structure. If we read in a pre-IMD .tpr file, imd->nat
      * will be zero. For those cases we transfer _all_ atomic positions */
     ir->imd->setup = imd_create(ir->imd->nat > 0 ? ir->imd->nat : nat_total,
-                                defnstimd, imdport);
+                                defnstimd, options.port);
     IMDsetup       = ir->imd->setup;
 
     /* We might need to open an output file for IMD forces data */
     if (MASTER(cr))
     {
-        IMDsetup->outf = open_imd_out(opt2fn("-if", nfile, fnm), ir->imd->setup, nat_total, oenv, Flags);
+        IMDsetup->outf = open_imd_out(opt2fn("-if", nfile, fnm), ir->imd->setup, nat_total, oenv, mdrunOptions.continuationOptions);
     }
 
     /* Make sure that we operate with a valid atom index array for the IMD atoms */
@@ -1406,21 +1407,21 @@ void init_IMD(t_inputrec             *ir,
         snew(IMDsetup->energysendbuf, recsize);
 
         /* Shall we wait for a connection? */
-        if (Flags & MD_IMDWAIT)
+        if (options.wait)
         {
             IMDsetup->bWConnect = TRUE;
             fprintf(stderr, "%s Pausing simulation while no IMD connection present (-imdwait).\n", IMDstr);
         }
 
         /* Will the IMD clients be able to terminate the simulation? */
-        if (Flags & MD_IMDTERM)
+        if (options.terminatable)
         {
             IMDsetup->bTerminatable = TRUE;
             fprintf(stderr, "%s Allow termination of the simulation from IMD client (-imdterm).\n", IMDstr);
         }
 
         /* Is pulling from IMD client allowed? */
-        if (Flags & MD_IMDPULL)
+        if (options.pull)
         {
             IMDsetup->bForceActivated = TRUE;
             fprintf(stderr, "%s Pulling from IMD remote is enabled (-imdpull).\n", IMDstr);
index ce977acb2ba1840f85a509b5be27ce75df4040ad..089174a68a5b5d7293b50756bf09726bcf4b0f16 100644 (file)
@@ -78,6 +78,7 @@ struct gmx_enerdata_t;
 struct gmx_mtop_t;
 struct gmx_output_env_t;
 struct gmx_wallcycle;
+struct MdrunOptions;
 struct t_commrec;
 struct t_filenm;
 struct t_gmx_IMD;
@@ -135,14 +136,12 @@ void dd_make_local_IMD_atoms(gmx_bool bIMD, gmx_domdec_t *dd, t_IMD *imd);
  * \param nfile        Number of files.
  * \param fnm          Struct containing file names etc.
  * \param oenv         Output options.
- * \param imdport      Port to use for IMD connections.
- * \param Flags        Flags passed over from main, used to determine
- *                     whether or not we are appending.
+ * \param mdrunOptions Options for mdrun.
  */
 void init_IMD(t_inputrec *ir, t_commrec *cr, gmx_mtop_t *top_global,
               FILE *fplog, int defnstimd, rvec x[],
               int nfile, const t_filenm fnm[], const gmx_output_env_t *oenv,
-              int imdport, unsigned long  Flags);
+              const MdrunOptions &mdrunOptions);
 
 
 /*! \brief IMD required in this time step?
index d070a1a4746fc757a342089873886165549b27cb..d44687058e5d16a48e79e3bb0961bb5626ec77ea 100644 (file)
@@ -47,8 +47,8 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/vecdump.h"
+#include "gromacs/mdlib/expanded.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
-#include "gromacs/mdlib/mdrun.h"
 #include "gromacs/mdlib/sim_util.h"
 #include "gromacs/mdlib/update.h"
 #include "gromacs/mdtypes/commrec.h"
index 7493e6ef3786d37a858c04c16a2fd2e5c6ae2501..cd1b2981de77bce2f68d876c924630fc9443ae80 100644 (file)
@@ -34,6 +34,8 @@
  */
 #include "gmxpre.h"
 
+#include "expanded.h"
+
 #include <stdio.h>
 
 #include <cmath>
@@ -55,7 +57,6 @@
 #include "gromacs/mdlib/calcmu.h"
 #include "gromacs/mdlib/constr.h"
 #include "gromacs/mdlib/force.h"
-#include "gromacs/mdlib/mdrun.h"
 #include "gromacs/mdlib/update.h"
 #include "gromacs/mdtypes/inputrec.h"
 #include "gromacs/mdtypes/md_enums.h"
@@ -80,7 +81,7 @@ static void init_df_history_weights(df_history_t *dfhist, t_expanded *expand, in
 
 /* Eventually should contain all the functions needed to initialize expanded ensemble
    before the md loop starts */
-extern void init_expanded_ensemble(gmx_bool bStateFromCP, t_inputrec *ir, df_history_t *dfhist)
+void init_expanded_ensemble(gmx_bool bStateFromCP, t_inputrec *ir, df_history_t *dfhist)
 {
     if (!bStateFromCP)
     {
@@ -987,8 +988,8 @@ static int ChooseNewLambda(int nlim, t_expanded *expand, df_history_t *dfhist, i
 }
 
 /* print out the weights to the log, along with current state */
-extern void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *expand, t_simtemp *simtemp, df_history_t *dfhist,
-                                      int fep_state, int frequency, gmx_int64_t step)
+void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *expand, t_simtemp *simtemp, df_history_t *dfhist,
+                               int fep_state, int frequency, gmx_int64_t step)
 {
     int         nlim, i, ifep, jfep;
     real        dw, dg, dv, Tprint;
@@ -1154,10 +1155,10 @@ extern void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *
     }
 }
 
-extern int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd,
-                                    t_state *state, t_extmass *MassQ, int fep_state, df_history_t *dfhist,
-                                    gmx_int64_t step,
-                                    rvec *v, t_mdatoms *mdatoms)
+int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd,
+                             t_state *state, t_extmass *MassQ, int fep_state, df_history_t *dfhist,
+                             gmx_int64_t step,
+                             rvec *v, t_mdatoms *mdatoms)
 /* Note that the state variable is only needed for simulated tempering, not
    Hamiltonian expanded ensemble.  May be able to remove it after integrator refactoring. */
 {
diff --git a/src/gromacs/mdlib/expanded.h b/src/gromacs/mdlib/expanded.h
new file mode 100644 (file)
index 0000000..335c91c
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2017, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_MDLIB_EXPANDED_H
+#define GMX_MDLIB_EXPANDED_H
+
+#include <stdio.h>
+
+#include "gromacs/math/vectypes.h"
+#include "gromacs/utility/basedefinitions.h"
+
+struct df_history_t;
+struct gmx_enerdata_t;
+struct t_expanded;
+struct t_extmass;
+struct t_inputrec;
+struct t_lambda;
+struct t_mdatoms;
+struct t_simtemp;
+class t_state;
+
+void init_npt_masses(t_inputrec *ir, t_state *state, t_extmass *MassQ, gmx_bool bInit);
+
+void init_expanded_ensemble(gmx_bool bStateFromCP, t_inputrec *ir, df_history_t *dfhist);
+
+int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd,
+                             t_state *state, t_extmass *MassQ, int fep_state, df_history_t *dfhist,
+                             gmx_int64_t step,
+                             rvec *v, t_mdatoms *mdatoms);
+
+void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *expand, t_simtemp *simtemp, df_history_t *dfhist,
+                               int fep_state, int frequency, gmx_int64_t step);
+
+#endif
index e8fdaa42d40925143bf13f66cc0d7ee14ebf3452..9ac0b817305c23e527364e9d99bc391f0d40630a 100644 (file)
@@ -57,6 +57,7 @@ class energyhistory_t;
 struct gmx_mtop_t;
 struct gmx_membed_t;
 struct gmx_output_env_t;
+struct MdrunOptions;
 struct ObservablesHistory;
 struct ReplicaExchangeParameters;
 struct t_commrec;
@@ -78,11 +79,9 @@ class MDLogger;
  * \param[in] nfile               Number of files
  * \param[in] fnm                 Filename structure array
  * \param[in] oenv                Output information
- * \param[in] bVerbose            Verbose output or not
- * \param[in] nstglobalcomm       How often global communication is done
+ * \param[in] mdrunOptions        Options for mdrun
  * \param[in] vsite               Virtual site information
  * \param[in] constr              Constraint information
- * \param[in] stepout             How often we writen to the console
  * \param[in] outputProvider      Additional output provider
  * \param[in] inputrec            Input record with mdp options
  * \param[in] top_global          Molecular topology for the whole system
@@ -95,18 +94,13 @@ class MDLogger;
  * \param[in] fr                  Force record with cut-off information and more
  * \param[in] replExParams        Parameters for the replica exchange algorithm
  * \param[in] membed              Membrane embedding data structure
- * \param[in] cpt_period          How often to checkpoint the simulation
- * \param[in] max_hours           Maximume length of the simulation (wall time)
- * \param[in] imdport             Interactive MD port (socket)
- * \param[in] Flags               Flags to control mdrun
  * \param[in] walltime_accounting More timing information
  */
 typedef double integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                              int nfile, const t_filenm fnm[],
-                             const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                             int nstglobalcomm,
+                             const gmx_output_env_t *oenv,
+                             const MdrunOptions &mdrunOptions,
                              gmx_vsite_t *vsite, gmx_constr_t constr,
-                             int stepout,
                              gmx::IMDOutputProvider *outputProvider,
                              t_inputrec *inputrec,
                              gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -117,9 +111,6 @@ typedef double integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &md
                              t_forcerec *fr,
                              const ReplicaExchangeParameters &replExParams,
                              gmx_membed_t gmx_unused * membed,
-                             real cpt_period, real max_hours,
-                             int imdport,
-                             unsigned long Flags,
                              gmx_walltime_accounting_t walltime_accounting);
 
 }      // namespace gmx
index 159e06866e120137307c3590b90eaf333b1aaff9..7f93e20d5db7551859be4ca603acf15bd1e3c8f7 100644 (file)
@@ -82,7 +82,8 @@ struct gmx_mdoutf {
 
 
 gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[],
-                         int mdrun_flags, const t_commrec *cr,
+                         const MdrunOptions &mdrunOptions,
+                         const t_commrec *cr,
                          gmx::IMDOutputProvider *outputProvider,
                          const t_inputrec *ir, gmx_mtop_t *top_global,
                          const gmx_output_env_t *oenv, gmx_wallcycle_t wcycle)
@@ -112,9 +113,9 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[],
 
     if (MASTER(cr))
     {
-        bAppendFiles = (mdrun_flags & MD_APPENDFILES);
+        bAppendFiles = mdrunOptions.continuationOptions.appendFiles;
 
-        of->bKeepAndNumCPT = (mdrun_flags & MD_KEEPANDNUMCPT);
+        of->bKeepAndNumCPT = mdrunOptions.checkpointOptions.keepAndNumberCheckpointFiles;
 
         filemode = bAppendFiles ? appendMode : writeMode;
 
index 2bb5b9739112581f1ac655d53407e373200b618b..612982182fceeb91d82539e7952cd49271e0c1b5 100644 (file)
@@ -46,6 +46,7 @@
 class energyhistory_t;
 struct gmx_mtop_t;
 struct gmx_output_env_t;
+struct MdrunOptions;
 struct ObservablesHistory;
 struct t_commrec;
 struct t_filenm;
@@ -66,7 +67,7 @@ typedef struct gmx_mdoutf *gmx_mdoutf_t;
 gmx_mdoutf_t init_mdoutf(FILE                   *fplog,
                          int                     nfile,
                          const t_filenm          fnm[],
-                         int                     mdrun_flags,
+                         const MdrunOptions     &mdrunOptions,
                          const t_commrec        *cr,
                          gmx::IMDOutputProvider *outputProvider,
                          const t_inputrec       *ir,
index bf69598eb55c6e2da20dbf0c96792153ffacc6d2..ea03f188f2bb8ddfe71a53b61f4e06ddb5b60909 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+
+/*! \libinternal \file
+ *
+ * \brief This file declares types and functions for initializing an MD run
+ *
+ * \author Berk Hess <hess@kth.se>
+ * \inlibraryapi
+ */
+
 #ifndef GMX_MDLIB_MDRUN_H
 #define GMX_MDLIB_MDRUN_H
 
-#include <stdio.h>
-#include <time.h>
-
 #include "gromacs/timing/wallcycle.h"
 
-struct df_history_t;
-struct gmx_constr;
-struct gmx_edsam;
-struct gmx_enerdata_t;
 struct gmx_mtop_t;
 struct t_commrec;
-struct t_expanded;
-struct t_extmass;
 struct t_inputrec;
-struct t_lambda;
-struct t_mdatoms;
-struct t_simtemp;
 class t_state;
 
-#define MD_POLARISE       (1<<2)
-#define MD_RERUN          (1<<4)
-#define MD_RERUN_VSITE    (1<<5)
-#define MD_CONFOUT        (1<<12)
-#define MD_REPRODUCIBLE   (1<<13)
-#define MD_APPENDFILES    (1<<15)
-#define MD_APPENDFILESSET (1<<21)
-#define MD_KEEPANDNUMCPT  (1<<16)
-#define MD_READ_EKIN      (1<<17)
-#define MD_STARTFROMCPT   (1<<18)
-#define MD_RESETCOUNTERSHALFWAY (1<<19)
-#define MD_TUNEPME        (1<<20)
-#define MD_NTOMPSET       (1<<21)
-#define MD_IMDWAIT        (1<<23)
-#define MD_IMDTERM        (1<<24)
-#define MD_IMDPULL        (1<<25)
-
-void init_npt_masses(t_inputrec *ir, t_state *state, t_extmass *MassQ, gmx_bool bInit);
-
-void init_expanded_ensemble(gmx_bool bStateFromCP, t_inputrec *ir, df_history_t *dfhist);
-
-int ExpandedEnsembleDynamics(FILE *log, t_inputrec *ir, gmx_enerdata_t *enerd,
-                             t_state *state, t_extmass *MassQ, int fep_state, df_history_t *dfhist,
-                             gmx_int64_t step,
-                             rvec *v, t_mdatoms *mdatoms);
-
-void PrintFreeEnergyInfoToFile(FILE *outfile, t_lambda *fep, t_expanded *expand, t_simtemp *simtemp, df_history_t *dfhist,
-                               int fep_state, int frequency, gmx_int64_t step);
-
-/* Allocate and initialize node-local state entries. */
+//! \internal \brief Options and settings for continuing from checkpoint
+struct ContinuationOptions
+{
+    //! \brief Constructor
+    ContinuationOptions() :
+        appendFiles(false),
+        appendFilesOptionSet(false),
+        startedFromCheckpoint(false),
+        haveReadEkin(false)
+    {
+    }
+
+    //! True if we are continuing from a checkpoint and should append output files
+    bool appendFiles;
+    //! True if the -append option was explicitly set by the user (either to true of false
+    bool appendFilesOptionSet;
+    //! True if we started from a checkpoint file
+    bool startedFromCheckpoint;
+    //! True if we read the kinetic energy from checkpoint file
+    bool haveReadEkin;
+};
+
+//! \internal \brief Options for writing checkpoint files
+struct CheckpointOptions
+{
+    //! \brief Constructor
+    CheckpointOptions() :
+        keepAndNumberCheckpointFiles(FALSE),
+        period(15)
+    {
+    }
+
+    //! True means keep all checkpoint file and add the step number to the name
+    gmx_bool keepAndNumberCheckpointFiles;
+    //! The period in minutes for writing checkpoint files
+    real     period;
+};
+
+//! \internal \brief Options for timing (parts of) mdrun
+struct TimingOptions
+{
+    //! \brief Constructor
+    TimingOptions() :
+        resetStep(-1),
+        resetHalfway(FALSE)
+    {
+    }
+
+    //! Reset timers at the start of this MD step, -1 means do not reset
+    int      resetStep;
+    //! If true, reset timers half-way the run
+    gmx_bool resetHalfway;
+};
+
+//! \internal \brief Options for IMD
+struct ImdOptions
+{
+    //! Constructor
+    ImdOptions() :
+        port(8888),
+        wait(FALSE),
+        terminatable(FALSE),
+        pull(FALSE)
+    {
+    }
+
+    //! IMD listening port
+    int      port;
+    //! If true, pause the simulation while no IMD client is connected
+    gmx_bool wait;
+    //! If true, allow termination of the simulation from IMD client
+    gmx_bool terminatable;
+    //! If true, allow COM pulling in the simulation from IMD client
+    gmx_bool pull;
+};
+
+//! \internal \brief Collection of all options of mdrun that are not processed separately
+struct MdrunOptions
+{
+    //! \brief Constructor
+    MdrunOptions() :
+        rerun(FALSE),
+        rerunConstructVsites(FALSE),
+        globalCommunicationInterval(-1),
+        reproducible(FALSE),
+        writeConfout(TRUE),
+        continuationOptions(),
+        checkpointOptions(),
+        numStepsCommandline(-2),
+        maximumHoursToRun(-1),
+        timingOptions(),
+        tunePme(TRUE),
+        ntompOptionIsSet(FALSE),
+        imdOptions(),
+        verbose(FALSE),
+        verboseStepPrintInterval(100)
+    {
+    }
+
+    //! Re-compute energies, and possibly forces, for frames from an input tracjectory
+    gmx_bool            rerun;
+    //! Re-construct virual sites durin a rerun simulation
+    gmx_bool            rerunConstructVsites;
+    //! Request to do global communication at this interval in steps, -1 is determine from inputrec
+    int                 globalCommunicationInterval;
+    //! Try to make the simulation binary reproducible
+    gmx_bool            reproducible;
+    //! Write confout.gro at the end of the run
+    gmx_bool            writeConfout;
+    //! Options for continuing a simulation from a checkpoint file
+    ContinuationOptions continuationOptions;
+    //! Options for checkpointing th simulation
+    CheckpointOptions   checkpointOptions;
+    //! Number of steps to run, -2 is use inputrec, -1 is infinite
+    gmx_int64_t         numStepsCommandline;
+    //! Maximum duration of this simulation in wall-clock hours, -1 is no limit
+    real                maximumHoursToRun;
+    //! Options for timing the run
+    TimingOptions       timingOptions;
+    //! If true and supported, will tune the PP-PME load balance
+    gmx_bool            tunePme;
+    //! True if the user explicitly set the -ntomp command line option
+    gmx_bool            ntompOptionIsSet;
+    //! Options for IMD
+    ImdOptions          imdOptions;
+    //! Increase the verbosity level in the logging and/or stdout/stderr
+    gmx_bool            verbose;
+    //! If verbose=true, print remaining runtime at this step interval
+    int                 verboseStepPrintInterval;
+};
+
+//! \brief Allocate and initialize node-local state entries
 void set_state_entries(t_state *state, const t_inputrec *ir);
 
-/* Broadcast the data for a simulation, and allocate node-specific settings */
+//! \brief Broadcast inputrec and mtop and allocate node-specific settings
 void init_parallel(t_commrec *cr, t_inputrec *inputrec,
                    gmx_mtop_t *mtop);
 
+//! \brief Broadcasts state from the master to all ranks in cr->mpi_comm_mygroup
 void bcast_state(const t_commrec *cr, t_state *state);
-/* Broadcasts state from the master to all nodes in cr->mpi_comm_mygroup.
- */
 
 #endif
index 04e6b7039ef21aaab4ad4f34bc71ebbc4a010bd3..b98b8a0703feae002510f554423acf07fce3d467 100644 (file)
@@ -324,6 +324,7 @@ static void get_state_f_norm_max(t_commrec *cr,
 static void init_em(FILE *fplog, const char *title,
                     t_commrec *cr, gmx::IMDOutputProvider *outputProvider,
                     t_inputrec *ir,
+                    const MdrunOptions &mdrunOptions,
                     t_state *state_global, gmx_mtop_t *top_global,
                     em_state_t *ems, gmx_localtop_t **top,
                     t_nrnb *nrnb, rvec mu_tot,
@@ -332,7 +333,6 @@ static void init_em(FILE *fplog, const char *title,
                     gmx_vsite_t *vsite, gmx_constr_t constr, gmx_shellfc_t **shellfc,
                     int nfile, const t_filenm fnm[],
                     gmx_mdoutf_t *outf, t_mdebin **mdebin,
-                    int imdport, unsigned long gmx_unused Flags,
                     gmx_wallcycle_t wcycle)
 {
     real dvdl_constr;
@@ -351,7 +351,7 @@ static void init_em(FILE *fplog, const char *title,
 
     /* Interactive molecular dynamics */
     init_IMD(ir, cr, top_global, fplog, 1, as_rvec_array(state_global->x.data()),
-             nfile, fnm, nullptr, imdport, Flags);
+             nfile, fnm, nullptr, mdrunOptions);
 
     if (ir->eI == eiNM)
     {
@@ -454,7 +454,7 @@ static void init_em(FILE *fplog, const char *title,
         *gstat = nullptr;
     }
 
-    *outf = init_mdoutf(fplog, nfile, fnm, 0, cr, outputProvider, ir, top_global, nullptr, wcycle);
+    *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, ir, top_global, nullptr, wcycle);
 
     snew(*enerd, 1);
     init_enerdata(top_global->groups.grps[egcENER].nr, ir->fepvals->n_lambda,
@@ -972,10 +972,9 @@ namespace gmx
 /*! \brief Do conjugate gradients minimization
     \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                            int nfile, const t_filenm fnm[],
-                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                           int nstglobalcomm,
+                           const gmx_output_env_t *oenv,
+                           const MdrunOptions &mdrunOptions,
                            gmx_vsite_t *vsite, gmx_constr_t constr,
-                           int stepout,
                            gmx::IMDOutputProvider *outputProvider,
                            t_inputrec *inputrec,
                            gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -986,17 +985,13 @@ namespace gmx
                            t_forcerec *fr,
                            const ReplicaExchangeParameters &replExParams,
                            gmx_membed_t gmx_unused *membed,
-                           real cpt_period, real max_hours,
-                           int imdport,
-                           unsigned long Flags,
                            gmx_walltime_accounting_t walltime_accounting)
  */
 double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
              int nfile, const t_filenm fnm[],
-             const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
-             int gmx_unused nstglobalcomm,
+             const gmx_output_env_t gmx_unused *oenv,
+             const MdrunOptions &mdrunOptions,
              gmx_vsite_t *vsite, gmx_constr_t constr,
-             int gmx_unused stepout,
              gmx::IMDOutputProvider *outputProvider,
              t_inputrec *inputrec,
              gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -1007,9 +1002,6 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
              t_forcerec *fr,
              const ReplicaExchangeParameters gmx_unused &replExParams,
              gmx_membed_t gmx_unused *membed,
-             real gmx_unused cpt_period, real gmx_unused max_hours,
-             int imdport,
-             unsigned long gmx_unused Flags,
              gmx_walltime_accounting_t walltime_accounting)
 {
     const char       *CG = "Polak-Ribiere Conjugate Gradients";
@@ -1045,11 +1037,11 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
     em_state_t *s_c   = &s3;
 
     /* Init em and store the local state in s_min */
-    init_em(fplog, CG, cr, outputProvider, inputrec,
+    init_em(fplog, CG, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, s_min, &top,
             nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
             vsite, constr, nullptr,
-            nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
+            nfile, fnm, &outf, &mdebin, wcycle);
 
     /* Print to log file */
     print_em_start(fplog, cr, walltime_accounting, wcycle, CG);
@@ -1502,7 +1494,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
         /* Print it if necessary */
         if (MASTER(cr))
         {
-            if (bVerbose)
+            if (mdrunOptions.verbose)
             {
                 double sqrtNumAtoms = sqrt(static_cast<double>(state_global->natoms));
                 fprintf(stderr, "\rStep %d, Epot=%12.6e, Fnorm=%9.3e, Fmax=%9.3e (atom %d)\n",
@@ -1624,10 +1616,9 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
 /*! \brief Do L-BFGS conjugate gradients minimization
     \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                           int nfile, const t_filenm fnm[],
-                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                          int nstglobalcomm,
+                          const gmx_output_env_t *oenv,
+                          const MdrunOptions &mdrunOptions,
                           gmx_vsite_t *vsite, gmx_constr_t constr,
-                          int stepout,
                           gmx::IMDOutputProvider *outputProvider,
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -1638,17 +1629,13 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                           t_forcerec *fr,
                           const ReplicaExchangeParameters &replExParams,
                           gmx_membed_t gmx_unused *membed,
-                          real cpt_period, real max_hours,
-                          int imdport,
-                          unsigned long Flags,
                           gmx_walltime_accounting_t walltime_accounting)
  */
 double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                 int nfile, const t_filenm fnm[],
-                const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
-                int gmx_unused nstglobalcomm,
+                const gmx_output_env_t gmx_unused *oenv,
+                const MdrunOptions &mdrunOptions,
                 gmx_vsite_t *vsite, gmx_constr_t constr,
-                int gmx_unused stepout,
                 gmx::IMDOutputProvider *outputProvider,
                 t_inputrec *inputrec,
                 gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -1659,9 +1646,6 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                 t_forcerec *fr,
                 const ReplicaExchangeParameters gmx_unused &replExParams,
                 gmx_membed_t gmx_unused *membed,
-                real gmx_unused cpt_period, real gmx_unused max_hours,
-                int imdport,
-                unsigned long gmx_unused Flags,
                 gmx_walltime_accounting_t walltime_accounting)
 {
     static const char *LBFGS = "Low-Memory BFGS Minimizer";
@@ -1721,11 +1705,11 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     neval = 0;
 
     /* Init em */
-    init_em(fplog, LBFGS, cr, outputProvider, inputrec,
+    init_em(fplog, LBFGS, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, &ems, &top,
             nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
             vsite, constr, nullptr,
-            nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
+            nfile, fnm, &outf, &mdebin, wcycle);
 
     start = 0;
     end   = mdatoms->homenr;
@@ -2286,7 +2270,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
         /* Print it if necessary */
         if (MASTER(cr))
         {
-            if (bVerbose)
+            if (mdrunOptions.verbose)
             {
                 double sqrtNumAtoms = sqrt(static_cast<double>(state_global->natoms));
                 fprintf(stderr, "\rStep %d, Epot=%12.6e, Fnorm=%9.3e, Fmax=%9.3e (atom %d)\n",
@@ -2397,10 +2381,9 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
 /*! \brief Do steepest descents minimization
     \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                           int nfile, const t_filenm fnm[],
-                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                          int nstglobalcomm,
+                          const gmx_output_env_t *oenv,
+                          const MdrunOptions &mdrunOptions,
                           gmx_vsite_t *vsite, gmx_constr_t constr,
-                          int stepout,
                           gmx::IMDOutputProvider *outputProvider,
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -2410,17 +2393,13 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                           gmx_edsam_t ed,
                           t_forcerec *fr,
                           const ReplicaExchangeParameters &replExParams,
-                          real cpt_period, real max_hours,
-                          int imdport,
-                          unsigned long Flags,
                           gmx_walltime_accounting_t walltime_accounting)
  */
 double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                 int nfile, const t_filenm fnm[],
-                const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
-                int gmx_unused nstglobalcomm,
+                const gmx_output_env_t gmx_unused *oenv,
+                const MdrunOptions &mdrunOptions,
                 gmx_vsite_t *vsite, gmx_constr_t constr,
-                int gmx_unused stepout,
                 gmx::IMDOutputProvider *outputProvider,
                 t_inputrec *inputrec,
                 gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -2431,9 +2410,6 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                 t_forcerec *fr,
                 const ReplicaExchangeParameters gmx_unused &replExParams,
                 gmx_membed_t gmx_unused *membed,
-                real gmx_unused cpt_period, real gmx_unused max_hours,
-                int imdport,
-                unsigned long gmx_unused Flags,
                 gmx_walltime_accounting_t walltime_accounting)
 {
     const char       *SD = "Steepest Descents";
@@ -2458,11 +2434,11 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     em_state_t *s_try = &s1;
 
     /* Init em and store the local state in s_try */
-    init_em(fplog, SD, cr, outputProvider, inputrec,
+    init_em(fplog, SD, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, s_try, &top,
             nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
             vsite, constr, nullptr,
-            nfile, fnm, &outf, &mdebin, imdport, Flags, wcycle);
+            nfile, fnm, &outf, &mdebin, wcycle);
 
     /* Print to log file  */
     print_em_start(fplog, cr, walltime_accounting, wcycle, SD);
@@ -2536,7 +2512,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
         /* Print it if necessary  */
         if (MASTER(cr))
         {
-            if (bVerbose)
+            if (mdrunOptions.verbose)
             {
                 fprintf(stderr, "Step=%5d, Dmax= %6.1e nm, Epot= %12.5e Fmax= %11.5e, atom= %d%c",
                         count, ustep, s_try->epot, s_try->fmax, s_try->a_fmax+1,
@@ -2667,10 +2643,9 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
 /*! \brief Do normal modes analysis
     \copydoc integrator_t(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                           int nfile, const t_filenm fnm[],
-                          const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                          int nstglobalcomm,
+                          const gmx_output_env_t *oenv,
+                          const MdrunOptions &mdrunOptions,
                           gmx_vsite_t *vsite, gmx_constr_t constr,
-                          int stepout,
                           gmx::IMDOutputProvider *outputProvider,
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -2680,17 +2655,13 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                           gmx_edsam_t ed,
                           t_forcerec *fr,
                           const ReplicaExchangeParameters &replExParams,
-                          real cpt_period, real max_hours,
-                          int imdport,
-                          unsigned long Flags,
                           gmx_walltime_accounting_t walltime_accounting)
  */
 double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
              int nfile, const t_filenm fnm[],
-             const gmx_output_env_t gmx_unused *oenv, gmx_bool bVerbose,
-             int gmx_unused nstglobalcomm,
+             const gmx_output_env_t gmx_unused *oenv,
+             const MdrunOptions &mdrunOptions,
              gmx_vsite_t *vsite, gmx_constr_t constr,
-             int gmx_unused stepout,
              gmx::IMDOutputProvider *outputProvider,
              t_inputrec *inputrec,
              gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -2701,9 +2672,6 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
              t_forcerec *fr,
              const ReplicaExchangeParameters gmx_unused &replExParams,
              gmx_membed_t gmx_unused *membed,
-             real gmx_unused cpt_period, real gmx_unused max_hours,
-             int imdport,
-             unsigned long gmx_unused Flags,
              gmx_walltime_accounting_t walltime_accounting)
 {
     const char          *NM = "Normal Mode Analysis";
@@ -2737,11 +2705,11 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     em_state_t     state_work {};
 
     /* Init em and store the local state in state_minimum */
-    init_em(fplog, NM, cr, outputProvider, inputrec,
+    init_em(fplog, NM, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, &state_work, &top,
             nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
             vsite, constr, &shellfc,
-            nfile, fnm, &outf, nullptr, imdport, Flags, wcycle);
+            nfile, fnm, &outf, nullptr, wcycle);
 
     std::vector<size_t> atom_index = get_atom_index(top_global);
     snew(fneg, atom_index.size());
@@ -2875,7 +2843,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 if (shellfc)
                 {
                     /* Now is the time to relax the shells */
-                    (void) relax_shell_flexcon(fplog, cr, bVerbose, step,
+                    (void) relax_shell_flexcon(fplog, cr, mdrunOptions.verbose, step,
                                                inputrec, bNS, force_flags,
                                                top,
                                                constr, enerd, fcd,
@@ -2967,13 +2935,13 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 }
             }
 
-            if (bVerbose && fplog)
+            if (mdrunOptions.verbose && fplog)
             {
                 fflush(fplog);
             }
         }
         /* write progress */
-        if (bIsMaster && bVerbose)
+        if (bIsMaster && mdrunOptions.verbose)
         {
             fprintf(stderr, "\rFinished step %d out of %d",
                     static_cast<int>(std::min(atom+nnodes, atom_index.size())),
index 8bd347ed45249d258034fbf9603ed8995b994924..3761078deae8e078bead1686645783ce4406d0dd 100644 (file)
@@ -2648,6 +2648,7 @@ extern void initialize_lambdas(FILE *fplog, t_inputrec *ir, int *fep_state, gmx:
 void init_md(FILE *fplog,
              t_commrec *cr, gmx::IMDOutputProvider *outputProvider,
              t_inputrec *ir, const gmx_output_env_t *oenv,
+             const MdrunOptions &mdrunOptions,
              double *t, double *t0,
              gmx::ArrayRef<real> lambda, int *fep_state, double *lam0,
              t_nrnb *nrnb, gmx_mtop_t *mtop,
@@ -2655,7 +2656,7 @@ void init_md(FILE *fplog,
              int nfile, const t_filenm fnm[],
              gmx_mdoutf_t *outf, t_mdebin **mdebin,
              tensor force_vir, tensor shake_vir, rvec mu_tot,
-             gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags,
+             gmx_bool *bSimAnn, t_vcm **vcm,
              gmx_wallcycle_t wcycle)
 {
     int  i;
@@ -2691,7 +2692,7 @@ void init_md(FILE *fplog,
         *vcm = init_vcm(fplog, &mtop->groups, ir);
     }
 
-    if (EI_DYNAMICS(ir->eI) && !(Flags & MD_APPENDFILES))
+    if (EI_DYNAMICS(ir->eI) && !mdrunOptions.continuationOptions.appendFiles)
     {
         if (ir->etc == etcBERENDSEN)
         {
@@ -2710,9 +2711,9 @@ void init_md(FILE *fplog,
 
     if (nfile != -1)
     {
-        *outf = init_mdoutf(fplog, nfile, fnm, Flags, cr, outputProvider, ir, mtop, oenv, wcycle);
+        *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, ir, mtop, oenv, wcycle);
 
-        *mdebin = init_mdebin((Flags & MD_APPENDFILES) ? nullptr : mdoutf_get_fp_ene(*outf),
+        *mdebin = init_mdebin(mdrunOptions.continuationOptions.appendFiles ? nullptr : mdoutf_get_fp_ene(*outf),
                               mtop, ir, mdoutf_get_fp_dhdl(*outf));
     }
 
index 7425b513e2a60a217296f61ffcafccbed96a3da4..c8ed785fcf10fbf1389a6a63e467eaa5105eadb2 100644 (file)
@@ -49,6 +49,7 @@ struct gmx_constr;
 struct gmx_localtop_t;
 struct gmx_output_env_t;
 struct gmx_update_t;
+struct MdrunOptions;
 struct nonbonded_verlet_t;
 struct t_mdatoms;
 struct t_nrnb;
@@ -143,6 +144,7 @@ void do_constrain_first(FILE *log, gmx_constr *constr,
 void init_md(FILE *fplog,
              t_commrec *cr, gmx::IMDOutputProvider *outputProvider,
              t_inputrec *ir, const gmx_output_env_t *oenv,
+             const MdrunOptions &mdrunOptions,
              double *t, double *t0,
              gmx::ArrayRef<real> lambda, int *fep_state, double *lam0,
              t_nrnb *nrnb, gmx_mtop_t *mtop,
@@ -151,7 +153,7 @@ void init_md(FILE *fplog,
              gmx_mdoutf_t *outf, t_mdebin **mdebin,
              tensor force_vir, tensor shake_vir,
              rvec mu_tot,
-             gmx_bool *bSimAnn, t_vcm **vcm, unsigned long Flags,
+             gmx_bool *bSimAnn, t_vcm **vcm,
              gmx_wallcycle_t wcycle);
 /* Routine in sim_util.c */
 
index 0e99f3f59e7410de6ccc8a90e149b00f66116183..332286edc06ff3d6a5b088bace03eb6b5b39624e 100644 (file)
@@ -129,10 +129,9 @@ namespace gmx
 /*! \brief Do test particle insertion.
     \copydoc integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                            int nfile, const t_filenm fnm[],
-                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                           int nstglobalcomm,
+                           const gmx_output_env_t *oenv,
+                           const MdrunOptions &mdrunOptions,
                            gmx_vsite_t *vsite, gmx_constr_t constr,
-                           int stepout,
                            gmx::IMDOutputProvider *outputProvider,
                            t_inputrec *inputrec,
                            gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -142,17 +141,14 @@ namespace gmx
                            gmx_edsam_t ed,
                            t_forcerec *fr,
                            const ReplicaExchangeParameters &replExParams,
-                           real cpt_period, real max_hours,
-                           int imdport,
-                           unsigned long Flags,
+                           gmx_membed_t gmx_unused *membed,
                            gmx_walltime_accounting_t walltime_accounting)
  */
 double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
               int nfile, const t_filenm fnm[],
-              const gmx_output_env_t *oenv, gmx_bool bVerbose,
-              int gmx_unused nstglobalcomm,
+              const gmx_output_env_t *oenv,
+              const MdrunOptions &mdrunOptions,
               gmx_vsite_t gmx_unused *vsite, gmx_constr_t gmx_unused constr,
-              int gmx_unused stepout,
               gmx::IMDOutputProvider *outputProvider,
               t_inputrec *inputrec,
               gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -163,9 +159,6 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
               t_forcerec *fr,
               const ReplicaExchangeParameters gmx_unused &replExParams,
               gmx_membed_t gmx_unused *membed,
-              real gmx_unused cpt_period, real gmx_unused max_hours,
-              int gmx_unused imdport,
-              unsigned long gmx_unused Flags,
               gmx_walltime_accounting_t walltime_accounting)
 {
     gmx_localtop_t  *top;
@@ -817,7 +810,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
 
         if (fp_tpi)
         {
-            if (bVerbose || frame%10 == 0 || frame < 10)
+            if (mdrunOptions.verbose || frame%10 == 0 || frame < 10)
             {
                 fprintf(stderr, "mu %10.3e <mu> %10.3e\n",
                         -log(sum_embU/nsteps)/beta, -log(VembU_all/V_all)/beta);
index 36545f9c1373bb932ce35d550dafbb02a052f2b1..0721298a563a9cbae3a736ad65245c97b900fd5b 100644 (file)
@@ -105,7 +105,7 @@ read_checkpoint_data(const char *filename, int *simulation_part,
                      int nfile, const t_filenm fnm[],
                      const char *part_suffix,
                      gmx_bool *bAddPart,
-                     gmx_bool *bDoAppendFiles)
+                     bool *bDoAppendFiles)
 {
     t_fileio            *fp;
     int                  nfiles;
@@ -233,8 +233,8 @@ handleRestart(t_commrec *cr,
               gmx_bool   bTryToAppendFiles,
               const int  NFILE,
               t_filenm   fnm[],
-              gmx_bool  *bDoAppendFiles,
-              gmx_bool  *bStartFromCpt)
+              bool      *bDoAppendFiles,
+              bool      *bStartFromCpt)
 {
     gmx_bool        bAddPart;
     int             sim_part, sim_part_fn;
index e66a013e9522c92598a20dd3156ce3e2f117bc59..350f78d248bb4a0042ece19434e34e220d2b9638 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -94,7 +94,7 @@ void handleRestart(t_commrec *cr,
                    gmx_bool   bTryToAppendFiles,
                    const int  NFILE,
                    t_filenm   fnm[],
-                   gmx_bool  *bDoAppendFiles,
-                   gmx_bool  *bStartFromCpt);
+                   bool      *bDoAppendFiles,
+                   bool      *bStartFromCpt);
 
 #endif
index a4463eaf78e7b1c0cb2d572040c489ab5d41c39d..47a82c8a77d56c97ca435ccf1db14bcb5a64a128 100644 (file)
@@ -287,13 +287,14 @@ static void set_legend_for_coord_components(const pull_coord_work_t *pcrd, int c
 
 static FILE *open_pull_out(const char *fn, struct pull_t *pull,
                            const gmx_output_env_t *oenv,
-                           gmx_bool bCoord, unsigned long Flags)
+                           gmx_bool bCoord,
+                           const ContinuationOptions &continuationOptions)
 {
     FILE  *fp;
     int    nsets, c, m;
     char **setname, buf[50];
 
-    if (Flags & MD_APPENDFILES)
+    if (continuationOptions.appendFiles)
     {
         fp = gmx_fio_fopen(fn, "a+");
     }
@@ -2105,7 +2106,8 @@ init_pull(FILE *fplog, const pull_params_t *pull_params, const t_inputrec *ir,
           int nfile, const t_filenm fnm[],
           const gmx_mtop_t *mtop, t_commrec *cr,
           const gmx_output_env_t *oenv, real lambda,
-          gmx_bool bOutFile, unsigned long Flags)
+          gmx_bool bOutFile,
+          const ContinuationOptions &continuationOptions)
 {
     struct pull_t *pull;
     pull_comm_t   *comm;
@@ -2522,9 +2524,9 @@ init_pull(FILE *fplog, const pull_params_t *pull_params, const t_inputrec *ir,
                 }
                 GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
                 pull->out_x   = open_pull_out(px_appended.c_str(), pull, oenv,
-                                              TRUE, Flags);
+                                              TRUE, continuationOptions);
                 pull->out_f = open_pull_out(pf_appended.c_str(), pull, oenv,
-                                            FALSE, Flags);
+                                            FALSE, continuationOptions);
                 return pull;
             }
             else
@@ -2537,12 +2539,12 @@ init_pull(FILE *fplog, const pull_params_t *pull_params, const t_inputrec *ir,
         if (pull->params.nstxout != 0)
         {
             pull->out_x = open_pull_out(opt2fn("-px", nfile, fnm), pull, oenv,
-                                        TRUE, Flags);
+                                        TRUE, continuationOptions);
         }
         if (pull->params.nstfout != 0)
         {
             pull->out_f = open_pull_out(opt2fn("-pf", nfile, fnm), pull, oenv,
-                                        FALSE, Flags);
+                                        FALSE, continuationOptions);
         }
     }
 
index 8aefaf94a2ed6d9f0f7ed6ae3af2532510f8e8d5..f5002ded235a4720c89de43e9dadc2415738ab8f 100644 (file)
@@ -62,6 +62,7 @@
 extern "C" {
 #endif
 
+struct ContinuationOptions;
 struct gmx_mtop_t;
 struct gmx_output_env_t;
 struct pull_params_t;
@@ -227,20 +228,19 @@ void dd_make_local_pull_groups(t_commrec *cr,
  * \param oenv        Output options.
  * \param lambda      FEP lambda.
  * \param bOutFile    Open output files?
- * \param Flags       Flags passed over from main, used to determine
- *                    whether or not we are appending.
+ * \param continuationOptions  Options for continuing from checkpoint file
  */
-struct pull_t *init_pull(FILE                   *fplog,
-                         const pull_params_t    *pull_params,
-                         const t_inputrec       *ir,
-                         int                     nfile,
-                         const t_filenm          fnm[],
-                         const gmx_mtop_t       *mtop,
-                         t_commrec             * cr,
-                         const gmx_output_env_t *oenv,
-                         real                    lambda,
-                         gmx_bool                bOutFile,
-                         unsigned long           Flags);
+struct pull_t *init_pull(FILE                      *fplog,
+                         const pull_params_t       *pull_params,
+                         const t_inputrec          *ir,
+                         int                        nfile,
+                         const t_filenm             fnm[],
+                         const gmx_mtop_t          *mtop,
+                         t_commrec                * cr,
+                         const gmx_output_env_t    *oenv,
+                         real                       lambda,
+                         gmx_bool                   bOutFile,
+                         const ContinuationOptions &continuationOptions);
 
 
 /*! \brief Close the pull output files.
index ff225c5d0db6ee33f31149a5d0d0439b6bb639dc..0f5b83e77ceedcae4482d3a83a2aa4b4e4d0a88f 100644 (file)
@@ -125,7 +125,7 @@ typedef struct gmx_enfrot
     real             *mpi_inbuf;   /* MPI buffer                                     */
     real             *mpi_outbuf;  /* MPI buffer                                     */
     int               mpi_bufsize; /* Allocation size of in & outbuf                 */
-    unsigned long     Flags;       /* mdrun flags                                    */
+    gmx_bool          appendFiles; /* If true, append output files                   */
     gmx_bool          bOut;        /* Used to skip first output when appending to
                                     * avoid duplicate entries in rotation outfiles   */
 } t_gmx_enfrot;
@@ -790,7 +790,7 @@ static FILE *open_slab_out(const char *fn, t_rot *rot)
     t_rotgrp  *rotg;
 
 
-    if (rot->enfrot->Flags & MD_APPENDFILES)
+    if (rot->enfrot->appendFiles)
     {
         fp = gmx_fio_fopen(fn, "a");
     }
@@ -865,7 +865,7 @@ static FILE *open_rot_out(const char *fn, t_rot *rot, const gmx_output_env_t *oe
     char           *LegendStr = nullptr;
 
 
-    if (rot->enfrot->Flags & MD_APPENDFILES)
+    if (rot->enfrot->appendFiles)
     {
         fp = gmx_fio_fopen(fn, "a");
     }
@@ -1006,7 +1006,7 @@ static FILE *open_angles_out(const char *fn, t_rot *rot)
     char            buf[100];
 
 
-    if (rot->enfrot->Flags & MD_APPENDFILES)
+    if (rot->enfrot->appendFiles)
     {
         fp = gmx_fio_fopen(fn, "a");
     }
@@ -1090,7 +1090,7 @@ static FILE *open_torque_out(const char *fn, t_rot *rot)
     t_rotgrp  *rotg;
 
 
-    if (rot->enfrot->Flags & MD_APPENDFILES)
+    if (rot->enfrot->appendFiles)
     {
         fp = gmx_fio_fopen(fn, "a");
     }
@@ -3658,7 +3658,7 @@ static int calc_mpi_bufsize(t_rot *rot)
 
 extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[],
                      t_commrec *cr, rvec *x, matrix box, gmx_mtop_t *mtop, const gmx_output_env_t *oenv,
-                     gmx_bool bVerbose, unsigned long Flags)
+                     const MdrunOptions &mdrunOptions)
 {
     t_rot          *rot;
     t_rotgrp       *rotg;
@@ -3669,18 +3669,18 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[
     rvec           *x_pbc = nullptr; /* Space for the pbc-correct atom positions */
 
 
-    if (MASTER(cr) && bVerbose)
+    if (MASTER(cr) && mdrunOptions.verbose)
     {
         fprintf(stdout, "%s Initializing ...\n", RotStr);
     }
 
     rot = ir->rot;
     snew(rot->enfrot, 1);
-    er        = rot->enfrot;
-    er->Flags = Flags;
+    er              = rot->enfrot;
+    er->appendFiles = mdrunOptions.continuationOptions.appendFiles;
 
     /* When appending, skip first output to avoid duplicate entries in the data files */
-    if (er->Flags & MD_APPENDFILES)
+    if (er->appendFiles)
     {
         er->bOut = FALSE;
     }
@@ -3695,7 +3695,7 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[
     }
 
     /* Output every step for reruns */
-    if (er->Flags & MD_RERUN)
+    if (mdrunOptions.rerun)
     {
         if (nullptr != fplog)
         {
@@ -3752,9 +3752,9 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[
                 erg->nat_loc = rotg->nat;
                 erg->ind_loc = rotg->ind;
             }
-            init_rot_group(fplog, cr, g, rotg, x_pbc, mtop, bVerbose, er->out_slabs, box, ir,
-                           !(er->Flags & MD_APPENDFILES) ); /* Do not output the reference centers
-                                                             * again if we are appending */
+            init_rot_group(fplog, cr, g, rotg, x_pbc, mtop, mdrunOptions.verbose, er->out_slabs, box, ir,
+                           !er->appendFiles); /* Do not output the reference centers
+                                               * again if we are appending */
         }
     }
 
index c80efd2a604234ac92ed8c60c69e5a47764d4f03..8a282e768895bbe027217379fb755f4446d8fcf7 100644 (file)
@@ -56,6 +56,7 @@
 struct gmx_domdec_t;
 struct gmx_mtop_t;
 struct gmx_output_env_t;
+struct MdrunOptions;
 struct t_commrec;
 struct t_filenm;
 struct t_inputrec;
@@ -82,13 +83,11 @@ extern "C" {
  * \param box      The simulation box.
  * \param mtop     Molecular topology.
  * \param oenv     Needed to open the rotation output xvgr file.
- * \param bVerbose Whether to print extra status information.
- * \param Flags    Flags passed over from main, used to determine
- *                 whether or not we are doing a rerun.
+ * \param mdrunOptions  Options for mdrun.
  */
 extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[],
                      struct t_commrec *cr, rvec *x, matrix box, gmx_mtop_t *mtop, const gmx_output_env_t *oenv,
-                     gmx_bool bVerbose, unsigned long Flags);
+                     const MdrunOptions &mdrunOptions);
 
 
 /*! \brief Make a selection of the home atoms for all enforced rotation groups.
index f330981f846c8921fb5cc483739a46af6f5625d6..1d230a6c5f6758026f6d9dd5ea6a4573fff7240f 100644 (file)
@@ -1450,7 +1450,6 @@ static gmx_bool bConvertFromOldTpr(t_swapcoords *sc)
 
 void init_swapcoords(
         FILE                   *fplog,
-        gmx_bool                bVerbose,
         t_inputrec             *ir,
         const char             *fn,
         gmx_mtop_t             *mtop,
@@ -1459,13 +1458,13 @@ void init_swapcoords(
         ObservablesHistory     *oh,
         t_commrec              *cr,
         const gmx_output_env_t *oenv,
-        unsigned long           Flags)
+        const MdrunOptions     &mdrunOptions)
 {
     t_swapcoords          *sc;
     t_swap                *s;
     t_swapgrp             *g;
     swapstateIons_t       *gs;
-    gmx_bool               bAppend, bStartFromCpt, bRerun;
+    gmx_bool               bAppend, bStartFromCpt;
     matrix                 boxCopy;
     swaphistory_t         *swapstate = nullptr;
 
@@ -1475,15 +1474,14 @@ void init_swapcoords(
         gmx_fatal(FARGS, "Position swapping is only implemented for domain decomposition!");
     }
 
-    bAppend       = Flags & MD_APPENDFILES;
-    bStartFromCpt = Flags & MD_STARTFROMCPT;
-    bRerun        = Flags & MD_RERUN;
+    bAppend       = mdrunOptions.continuationOptions.appendFiles;
+    bStartFromCpt = mdrunOptions.continuationOptions.startedFromCheckpoint;
 
     sc = ir->swap;
     snew(sc->si_priv, 1);
     s = sc->si_priv;
 
-    if (bRerun)
+    if (mdrunOptions.rerun)
     {
         if (PAR(cr))
         {
@@ -1517,6 +1515,8 @@ void init_swapcoords(
             break;
     }
 
+    const gmx_bool bVerbose = mdrunOptions.verbose;
+
     // For compatibility with old .tpr files
     if (bConvertFromOldTpr(sc) )
     {
@@ -1697,7 +1697,7 @@ void init_swapcoords(
                     sc->cyl1r, sc->cyl1u, sc->cyl1l);
 
             fprintf(s->fpout, "#\n");
-            if (!bRerun)
+            if (!mdrunOptions.rerun)
             {
                 fprintf(s->fpout, "# Coupling constant (number of swap attempt steps to average over): %d  (translates to %f ps).\n",
                         sc->nAverage, sc->nAverage*sc->nstswap*ir->delta_t);
@@ -1758,7 +1758,7 @@ void init_swapcoords(
         else
         {
             fprintf(stderr, "%s Determining initial numbers of ions per compartment.\n", SwS);
-            get_initial_ioncounts(ir, x, box, cr, bRerun);
+            get_initial_ioncounts(ir, x, box, cr, mdrunOptions.rerun);
         }
 
         /* Prepare (further) checkpoint writes ... */
index 1a15c0e626a0db51f92dae5c92075d5fd137fc76..3adaa006201c1bde0ad89776e7d117a0ffd544ba 100644 (file)
@@ -61,6 +61,7 @@ struct gmx_domdec_t;
 struct gmx_mtop_t;
 struct gmx_output_env_t;
 struct gmx_wallcycle;
+struct MdrunOptions;
 struct swaphistory_t;
 struct t_commrec;
 struct t_inputrec;
@@ -74,7 +75,6 @@ struct ObservablesHistory;
  * the output file, sets up swap data checkpoint writing, etc.
  *
  * \param[in] fplog         General output file, normally md.log.
- * \param[in] bVerbose      Should we be quiet or verbose?
  * \param[in] ir            Structure containing MD input parameters, among those
  *                          also the structure needed for position swapping.
  * \param[in] fn            Output file name for swap data.
@@ -84,12 +84,10 @@ struct ObservablesHistory;
  * \param[in] oh            Contains struct with swap data that is read from or written to checkpoint.
  * \param[in] cr            Pointer to MPI communication data.
  * \param[in] oenv          Needed to open the swap output XVGR file.
- * \param[in] Flags         Flags passed over from main, used to determine
- *                          whether we are doing a rerun, appending, etc.
+ * \param[in] mdrunOptions  Options for mdrun.
  */
 void init_swapcoords(
         FILE                   *fplog,
-        gmx_bool                bVerbose,
         t_inputrec             *ir,
         const char             *fn,
         gmx_mtop_t             *mtop,
@@ -98,7 +96,7 @@ void init_swapcoords(
         ObservablesHistory     *oh,
         t_commrec              *cr,
         const gmx_output_env_t *oenv,
-        unsigned long           Flags);
+        const MdrunOptions     &mdrunOptions);
 
 
 /*! \brief Finalizes ion / water position swapping.
index 58a53ef7a813ec4ecb921828de553261a913e4d8..e91763990552deef8081dfdf579b30c5d81bb2c7 100644 (file)
@@ -69,6 +69,7 @@
 #include "gromacs/mdlib/compute_io.h"
 #include "gromacs/mdlib/constr.h"
 #include "gromacs/mdlib/ebin.h"
+#include "gromacs/mdlib/expanded.h"
 #include "gromacs/mdlib/force.h"
 #include "gromacs/mdlib/force_flags.h"
 #include "gromacs/mdlib/forcerec.h"
@@ -195,10 +196,9 @@ static void reset_all_counters(FILE *fplog, const gmx::MDLogger &mdlog, t_commre
 /*! \libinternal
     \copydoc integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                            int nfile, const t_filenm fnm[],
-                           const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                           int nstglobalcomm,
+                           const gmx_output_env_t *oenv,
+                           const MdrunOptions &mdrunOptions,
                            gmx_vsite_t *vsite, gmx_constr_t constr,
-                           int stepout,
                            gmx::IMDOutputProvider *outputProvider,
                            t_inputrec *inputrec,
                            gmx_mtop_t *top_global, t_fcdata *fcd,
@@ -206,18 +206,16 @@ static void reset_all_counters(FILE *fplog, const gmx::MDLogger &mdlog, t_commre
                            t_mdatoms *mdatoms,
                            t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                            t_forcerec *fr,
-                           int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
-                           real cpt_period, real max_hours,
-                           int imdport,
-                           unsigned long Flags,
+                           const ReplicaExchangeParameters &replExParams,
+                           gmx_membed_t *membed,
                            gmx_walltime_accounting_t walltime_accounting)
  */
 double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                   int nfile, const t_filenm fnm[],
-                  const gmx_output_env_t *oenv, gmx_bool bVerbose,
-                  int nstglobalcomm,
+                  const gmx_output_env_t *oenv,
+                  const MdrunOptions &mdrunOptions,
                   gmx_vsite_t *vsite, gmx_constr_t constr,
-                  int stepout, gmx::IMDOutputProvider *outputProvider,
+                  gmx::IMDOutputProvider *outputProvider,
                   t_inputrec *ir,
                   gmx_mtop_t *top_global,
                   t_fcdata *fcd,
@@ -228,9 +226,6 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                   t_forcerec *fr,
                   const ReplicaExchangeParameters &replExParams,
                   gmx_membed_t *membed,
-                  real cpt_period, real max_hours,
-                  int imdport,
-                  unsigned long Flags,
                   gmx_walltime_accounting_t walltime_accounting)
 {
     gmx_mdoutf_t    outf = nullptr;
@@ -238,8 +233,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     double          elapsed_time;
     double          t, t0, lam0[efptNR];
     gmx_bool        bGStatEveryStep, bGStat, bCalcVir, bCalcEnerStep, bCalcEner;
-    gmx_bool        bNS, bNStList, bSimAnn, bStopCM, bRerunMD,
-                    bFirstStep, startingFromCheckpoint, bInitStep, bLastStep = FALSE,
+    gmx_bool        bNS, bNStList, bSimAnn, bStopCM,
+                    bFirstStep, bInitStep, bLastStep = FALSE,
                     bBornRadii, bUsingEnsembleRestraints;
     gmx_bool          bDoDHDL = FALSE, bDoFEP = FALSE, bDoExpanded = FALSE;
     gmx_bool          do_ene, do_log, do_verbose, bRerunWarnNoV = TRUE,
@@ -310,9 +305,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     // signals, and will use this object to achieve that.
     SimulationSignaller nullSignaller(nullptr, nullptr, false, false);
 
-    /* Check for special mdrun options */
-    bRerunMD = (Flags & MD_RERUN);
-    if (Flags & MD_RESETCOUNTERSHALFWAY)
+    if (mdrunOptions.timingOptions.resetHalfway)
     {
         if (ir->nsteps > 0)
         {
@@ -320,7 +313,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             wcycle_set_reset_counters(wcycle, ir->nsteps/2);
         }
         /* Signal to reset the counters halfway the simulation time. */
-        bResetCountersHalfMaxH = (max_hours > 0);
+        bResetCountersHalfMaxH = (mdrunOptions.maximumHoursToRun > 0);
     }
 
     /* md-vv uses averaged full step velocities for T-control
@@ -328,6 +321,9 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
        md uses averaged half step kinetic energies to determine temperature unless defined otherwise by GMX_EKIN_AVE_VEL; */
     bTrotter = (EI_VV(ir->eI) && (inputrecNptTrotter(ir) || inputrecNphTrotter(ir) || inputrecNvtTrotter(ir)));
 
+    const gmx_bool bRerunMD      = mdrunOptions.rerun;
+    int            nstglobalcomm = mdrunOptions.globalCommunicationInterval;
+
     if (bRerunMD)
     {
         /* Since we don't know if the frames read are related in any way,
@@ -355,22 +351,23 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                         top_global, ir, cr, constr,
                         as_rvec_array(state_global->x.data()),
                         state_global->box, observablesHistory,
-                        oenv, Flags & MD_APPENDFILES);
+                        oenv, mdrunOptions.continuationOptions.appendFiles);
     }
 
     if (ir->eSwapCoords != eswapNO)
     {
         /* Initialize ion swapping code */
-        init_swapcoords(fplog, bVerbose, ir, opt2fn_master("-swap", nfile, fnm, cr),
-                        top_global, as_rvec_array(state_global->x.data()), state_global->box, observablesHistory, cr, oenv, Flags);
+        init_swapcoords(fplog, ir, opt2fn_master("-swap", nfile, fnm, cr),
+                        top_global, as_rvec_array(state_global->x.data()), state_global->box, observablesHistory, cr, oenv, mdrunOptions);
     }
 
     /* Initial values */
-    init_md(fplog, cr, outputProvider, ir, oenv, &t, &t0, state_global->lambda,
+    init_md(fplog, cr, outputProvider, ir, oenv, mdrunOptions,
+            &t, &t0, state_global->lambda,
             &(state_global->fep_state), lam0,
             nrnb, top_global, &upd,
             nfile, fnm, &outf, &mdebin,
-            force_vir, shake_vir, mu_tot, &bSimAnn, &vcm, Flags, wcycle);
+            force_vir, shake_vir, mu_tot, &bSimAnn, &vcm, wcycle);
 
     clear_mat(total_vir);
     clear_mat(pres);
@@ -450,7 +447,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 
     /* Set up interactive MD (IMD) */
     init_IMD(ir, cr, top_global, fplog, ir->nstcalcenergy, as_rvec_array(state_global->x.data()),
-             nfile, fnm, oenv, imdport, Flags);
+             nfile, fnm, oenv, mdrunOptions);
 
     if (DOMAINDECOMP(cr))
     {
@@ -466,7 +463,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 
     update_mdatoms(mdatoms, state->lambda[efptMASS]);
 
-    startingFromCheckpoint = Flags & MD_STARTFROMCPT;
+    const ContinuationOptions &continuationOptions    = mdrunOptions.continuationOptions;
+    bool                       startingFromCheckpoint = continuationOptions.startedFromCheckpoint;
 
     if (ir->bExpanded)
     {
@@ -478,7 +476,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         if (startingFromCheckpoint)
         {
             /* Update mdebin with energy history if appending to output files */
-            if (Flags & MD_APPENDFILES)
+            if (continuationOptions.appendFiles)
             {
                 restore_energyhistory_from_state(mdebin, observablesHistory->energyHistory.get());
             }
@@ -515,8 +513,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     /* PME tuning is only supported in the Verlet scheme, with PME for
      * Coulomb. It is not supported with only LJ PME, or for
      * reruns. */
-    bPMETune = ((Flags & MD_TUNEPME) && EEL_PME(fr->eeltype) && !bRerunMD &&
-                !(Flags & MD_REPRODUCIBLE) && ir->cutoff_scheme != ecutsGROUP);
+    bPMETune = (mdrunOptions.tunePme && EEL_PME(fr->eeltype) && !bRerunMD &&
+                !mdrunOptions.reproducible && ir->cutoff_scheme != ecutsGROUP);
     if (bPMETune)
     {
         pme_loadbal_init(&pme_loadbal, cr, mdlog, ir, state->box,
@@ -585,7 +583,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
      */
     bStopCM = (ir->comm_mode != ecmNO && !ir->bContinuation);
 
-    if (Flags & MD_READ_EKIN)
+    if (continuationOptions.haveReadEkin)
     {
         restore_ekinstate_from_state(cr, ekind, &state_global->ekinstate);
     }
@@ -594,7 +592,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                   | (bStopCM ? CGLO_STOPCM : 0)
                   | (EI_VV(ir->eI) ? CGLO_PRESSURE : 0)
                   | (EI_VV(ir->eI) ? CGLO_CONSTRAINT : 0)
-                  | ((Flags & MD_READ_EKIN) ? CGLO_READEKIN : 0));
+                  | (continuationOptions.haveReadEkin ? CGLO_READEKIN : 0));
 
     bSumEkinhOld = FALSE;
     compute_globals(fplog, gstat, cr, ir, fr, ekind, state, mdatoms, nrnb, vcm,
@@ -621,7 +619,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     }
 
     /* Calculate the initial half step temperature, and save the ekinh_old */
-    if (!(Flags & MD_STARTFROMCPT))
+    if (!continuationOptions.startedFromCheckpoint)
     {
         for (i = 0; (i < ir->opts.ngtc); i++)
         {
@@ -662,7 +660,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             fprintf(stderr, "starting md rerun '%s', reading coordinates from"
                     " input trajectory '%s'\n\n",
                     *(top_global->name), opt2fn("-rerun", nfile, fnm));
-            if (bVerbose)
+            if (mdrunOptions.verbose)
             {
                 fprintf(stderr, "Calculated time to finish depends on nsteps from "
                         "run input file,\nwhich may not correspond to the time "
@@ -766,8 +764,11 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         }
     }
 
-    /* loop over MD steps or if rerunMD to end of input trajectory */
-    bFirstStep = TRUE;
+    /* Loop over MD steps or if rerunMD to end of input trajectory,
+     * or, if max_hours>0, until max_hours is reached.
+     */
+    real max_hours   = mdrunOptions.maximumHoursToRun;
+    bFirstStep       = TRUE;
     /* Skip the first Nose-Hoover integration when we get the state from tpx */
     bInitStep        = !startingFromCheckpoint || EI_VV(ir->eI);
     bSumEkinhOld     = FALSE;
@@ -826,7 +827,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         {
             /* PME grid + cut-off optimization with GPUs or PME nodes */
             pme_loadbal_do(pme_loadbal, cr,
-                           (bVerbose && MASTER(cr)) ? stderr : nullptr,
+                           (mdrunOptions.verbose && MASTER(cr)) ? stderr : nullptr,
                            fplog, mdlog,
                            ir, fr, state,
                            wcycle,
@@ -913,7 +914,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             copy_mat(rerun_fr.box, state_global->box);
             copy_mat(state_global->box, state->box);
 
-            if (vsite && (Flags & MD_RERUN_VSITE))
+            if (vsite && mdrunOptions.rerunConstructVsites)
             {
                 if (DOMAINDECOMP(cr))
                 {
@@ -972,8 +973,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
          * beyond the last step. But we don't consider that to be an issue.
          */
         do_log     = do_per_step(step, ir->nstlog) || (bFirstStep && !startingFromCheckpoint) || bLastStep || bRerunMD;
-        do_verbose = bVerbose &&
-            (step % stepout == 0 || bFirstStep || bLastStep || bRerunMD);
+        do_verbose = mdrunOptions.verbose &&
+            (step % mdrunOptions.verboseStepPrintInterval == 0 || bFirstStep || bLastStep || bRerunMD);
 
         if (bNS && !(bFirstStep && ir->bContinuation && !bRerunMD))
         {
@@ -1046,7 +1047,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
          * but never at the first step or with rerun.
          */
         bCPT = (((signals[eglsCHKPT].set && (bNS || ir->nstlist == 0)) ||
-                 (bLastStep && (Flags & MD_CONFOUT))) &&
+                 (bLastStep && mdrunOptions.writeConfout)) &&
                 step > ir->init_step && !bRerunMD);
         if (bCPT)
         {
@@ -1100,7 +1101,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         if (shellfc)
         {
             /* Now is the time to relax the shells */
-            relax_shell_flexcon(fplog, cr, bVerbose, step,
+            relax_shell_flexcon(fplog, cr, mdrunOptions.verbose, step,
                                 ir, bNS, force_flags, top,
                                 constr, enerd, fcd,
                                 state, &f, force_vir, mdatoms,
@@ -1302,7 +1303,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                                  top_global, fr,
                                  outf, mdebin, ekind, &f,
                                  &nchkpt,
-                                 bCPT, bRerunMD, bLastStep, (Flags & MD_CONFOUT),
+                                 bCPT, bRerunMD, bLastStep,
+                                 mdrunOptions.writeConfout,
                                  bSumEkinhOld);
         /* Check if IMD step and do IMD communication, if bIMD is TRUE. */
         bIMDstep = do_IMD(ir->bIMD, step, cr, bNS, state->box, as_rvec_array(state->x.data()), ir, t, wcycle);
@@ -1375,6 +1377,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
          * where we do global communication,
          *  otherwise the other nodes don't know.
          */
+        const real cpt_period = mdrunOptions.checkpointOptions.period;
         if (MASTER(cr) && ((bGStat || !PAR(cr)) &&
                            cpt_period >= 0 &&
                            (cpt_period == 0 ||
@@ -1711,7 +1714,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             bNeedRepartition = do_swapcoords(cr, step, t, ir, wcycle,
                                              bRerunMD ? rerun_fr.x   : as_rvec_array(state->x.data()),
                                              bRerunMD ? rerun_fr.box : state->box,
-                                             MASTER(cr) && bVerbose, bRerunMD);
+                                             MASTER(cr) && mdrunOptions.verbose,
+                                             bRerunMD);
 
             if (bNeedRepartition && DOMAINDECOMP(cr))
             {
@@ -1741,7 +1745,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 
         bFirstStep             = FALSE;
         bInitStep              = FALSE;
-        startingFromCheckpoint = FALSE;
+        startingFromCheckpoint = false;
 
         /* #######  SET VARIABLES FOR NEXT ITERATION IF THEY STILL NEED IT ###### */
         /* With all integrators, except VV, we need to retain the pressure
index 06053b376e9da15941d7be998ef2157b27c9c452..9fcdb4ce480531a0cec4eda9cf28e4be3130d87e 100644 (file)
@@ -240,15 +240,6 @@ int Mdrunner::mainFunction(int argc, char *argv[])
         "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
     };
 
-    /* Command line option parameters, with their default values */
-    gmx_bool          bTunePME      = TRUE;
-    gmx_bool          bRerunVSite   = FALSE;
-    gmx_bool          bConfout      = TRUE;
-    gmx_bool          bReproducible = FALSE;
-    gmx_bool          bIMDwait      = FALSE;
-    gmx_bool          bIMDterm      = FALSE;
-    gmx_bool          bIMDpull      = FALSE;
-
     /* Command line options */
     rvec              realddxyz                                               = {0, 0, 0};
     const char       *ddrank_opt_choices[static_cast<int>(DdRankOrder::nr)+1] =
@@ -260,10 +251,10 @@ int Mdrunner::mainFunction(int argc, char *argv[])
     const char       *nbpu_opt_choices[] =
     { nullptr, "auto", "cpu", "gpu", "gpu_cpu", nullptr };
     gmx_bool          bTryToAppendFiles     = TRUE;
-    gmx_bool          bKeepAndNumCPT        = FALSE;
-    gmx_bool          bResetCountersHalfWay = FALSE;
     const char       *gpuIdTaskAssignment   = "";
 
+    ImdOptions       &imdOptions = mdrunOptions.imdOptions;
+
     t_pargs           pa[] = {
 
         { "-dd",      FALSE, etRVEC, {&realddxyz},
@@ -313,29 +304,29 @@ int Mdrunner::mainFunction(int argc, char *argv[])
           "HIDDENA string containing a vector of the relative sizes in the z "
           "direction of the corresponding DD cells. Only effective with static "
           "load balancing." },
-        { "-gcom",    FALSE, etINT, {&nstglobalcomm},
+        { "-gcom",    FALSE, etINT, {&mdrunOptions.globalCommunicationInterval},
           "Global communication frequency" },
         { "-nb",      FALSE, etENUM, {nbpu_opt_choices},
           "Calculate non-bonded interactions on" },
         { "-nstlist", FALSE, etINT, {&nstlist_cmdline},
           "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
-        { "-tunepme", FALSE, etBOOL, {&bTunePME},
+        { "-tunepme", FALSE, etBOOL, {&mdrunOptions.tunePme},
           "Optimize PME load between PP/PME ranks or GPU/CPU (only with the Verlet cut-off scheme)" },
-        { "-v",       FALSE, etBOOL, {&bVerbose},
+        { "-v",       FALSE, etBOOL, {&mdrunOptions.verbose},
           "Be loud and noisy" },
         { "-pforce",  FALSE, etREAL, {&pforce},
           "Print all forces larger than this (kJ/mol nm)" },
-        { "-reprod",  FALSE, etBOOL, {&bReproducible},
+        { "-reprod",  FALSE, etBOOL, {&mdrunOptions.reproducible},
           "Try to avoid optimizations that affect binary reproducibility" },
-        { "-cpt",     FALSE, etREAL, {&cpt_period},
+        { "-cpt",     FALSE, etREAL, {&mdrunOptions.checkpointOptions.period},
           "Checkpoint interval (minutes)" },
-        { "-cpnum",   FALSE, etBOOL, {&bKeepAndNumCPT},
+        { "-cpnum",   FALSE, etBOOL, {&mdrunOptions.checkpointOptions.keepAndNumberCheckpointFiles},
           "Keep and number checkpoint files" },
         { "-append",  FALSE, etBOOL, {&bTryToAppendFiles},
           "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
-        { "-nsteps",  FALSE, etINT64, {&nsteps_cmdline},
+        { "-nsteps",  FALSE, etINT64, {&mdrunOptions.numStepsCommandline},
           "Run this number of steps, overrides .mdp file option (-1 means infinite, -2 means use mdp option, smaller is invalid)" },
-        { "-maxh",   FALSE, etREAL, {&max_hours},
+        { "-maxh",   FALSE, etREAL, {&mdrunOptions.maximumHoursToRun},
           "Terminate after 0.99 times this time (hours)" },
         { "-multi",   FALSE, etINT, {&nmultisim},
           "Do multiple simulations in parallel" },
@@ -345,26 +336,25 @@ int Mdrunner::mainFunction(int argc, char *argv[])
           "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion).  -nex zero or not specified gives neighbor replica exchange." },
         { "-reseed",  FALSE, etINT, {&replExParams.randomSeed},
           "Seed for replica exchange, -1 is generate a seed" },
-        { "-imdport",    FALSE, etINT, {&imdport},
+        { "-imdport",    FALSE, etINT, {&imdOptions.port},
           "HIDDENIMD listening port" },
-        { "-imdwait",  FALSE, etBOOL, {&bIMDwait},
+        { "-imdwait",  FALSE, etBOOL, {&imdOptions.wait},
           "HIDDENPause the simulation while no IMD client is connected" },
-        { "-imdterm",  FALSE, etBOOL, {&bIMDterm},
+        { "-imdterm",  FALSE, etBOOL, {&imdOptions.terminatable},
           "HIDDENAllow termination of the simulation from IMD client" },
-        { "-imdpull",  FALSE, etBOOL, {&bIMDpull},
+        { "-imdpull",  FALSE, etBOOL, {&imdOptions.pull},
           "HIDDENAllow pulling in the simulation from IMD client" },
-        { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
+        { "-rerunvsite", FALSE, etBOOL, {&mdrunOptions.rerunConstructVsites},
           "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
-        { "-confout", FALSE, etBOOL, {&bConfout},
+        { "-confout", FALSE, etBOOL, {&mdrunOptions.writeConfout},
           "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
-        { "-stepout", FALSE, etINT, {&nstepout},
+        { "-stepout", FALSE, etINT, {&mdrunOptions.verboseStepPrintInterval},
           "HIDDENFrequency of writing the remaining wall clock time for the run" },
-        { "-resetstep", FALSE, etINT, {&resetstep},
+        { "-resetstep", FALSE, etINT, {&mdrunOptions.timingOptions.resetStep},
           "HIDDENReset cycle counters after these many time steps" },
-        { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
+        { "-resethway", FALSE, etBOOL, {&mdrunOptions.timingOptions.resetHalfway},
           "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
     };
-    gmx_bool          bDoAppendFiles, bStartFromCpt;
     int               rc;
     char            **multidir = nullptr;
 
@@ -469,30 +459,22 @@ int Mdrunner::mainFunction(int argc, char *argv[])
         }
     }
 
-    handleRestart(cr, bTryToAppendFiles, nfile, fnm, &bDoAppendFiles, &bStartFromCpt);
-
-    Flags = opt2bSet("-rerun", nfile, fnm) ? MD_RERUN : 0;
-    Flags = Flags | (bTunePME      ? MD_TUNEPME      : 0);
-    Flags = Flags | (bConfout      ? MD_CONFOUT      : 0);
-    Flags = Flags | (bRerunVSite   ? MD_RERUN_VSITE  : 0);
-    Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
-    Flags = Flags | (bDoAppendFiles  ? MD_APPENDFILES  : 0);
-    Flags = Flags | (opt2parg_bSet("-append", asize(pa), pa) ? MD_APPENDFILESSET : 0);
-    Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0);
-    Flags = Flags | (bStartFromCpt ? MD_STARTFROMCPT : 0);
-    Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
-    Flags = Flags | (opt2parg_bSet("-ntomp", asize(pa), pa) ? MD_NTOMPSET : 0);
-    Flags = Flags | (bIMDwait      ? MD_IMDWAIT      : 0);
-    Flags = Flags | (bIMDterm      ? MD_IMDTERM      : 0);
-    Flags = Flags | (bIMDpull      ? MD_IMDPULL      : 0);
+    ContinuationOptions &continuationOptions = mdrunOptions.continuationOptions;
+
+    continuationOptions.appendFilesOptionSet = opt2parg_bSet("-append", asize(pa), pa);
+
+    handleRestart(cr, bTryToAppendFiles, nfile, fnm, &continuationOptions.appendFiles, &continuationOptions.startedFromCheckpoint);
+
+    mdrunOptions.rerun            = opt2bSet("-rerun", nfile, fnm);
+    mdrunOptions.ntompOptionIsSet = opt2parg_bSet("-ntomp", asize(pa), pa);
 
     /* We postpone opening the log file if we are appending, so we can
        first truncate the old log file and append to the correct position
        there instead.  */
-    if (MASTER(cr) && !bDoAppendFiles)
+    if (MASTER(cr) && !continuationOptions.appendFiles)
     {
         gmx_log_open(ftp2fn(efLOG, nfile, fnm), cr,
-                     Flags & MD_APPENDFILES, &fplog);
+                     continuationOptions.appendFiles, &fplog);
     }
     else
     {
@@ -510,7 +492,7 @@ int Mdrunner::mainFunction(int argc, char *argv[])
 
     /* Log file has to be closed in mdrunner if we are appending to it
        (fplog not set here) */
-    if (MASTER(cr) && !bDoAppendFiles)
+    if (MASTER(cr) && !continuationOptions.appendFiles)
     {
         gmx_log_close(fplog);
     }
index b6263940e2585ea84eb212125ca7be6c6a2887b9..7fa27c998fb750953fb1168bf71355a483db846a 100644 (file)
@@ -462,13 +462,13 @@ int Mdrunner::mdrunner()
     t_inputrec    *inputrec = &inputrecInstance;
     snew(mtop, 1);
 
-    if (Flags & MD_APPENDFILES)
+    if (mdrunOptions.continuationOptions.appendFiles)
     {
         fplog = nullptr;
     }
 
     bool doMembed = opt2bSet("-membed", nfile, fnm);
-    bool doRerun  = (Flags & MD_RERUN);
+    bool doRerun  = mdrunOptions.rerun;
 
     /* Handle GPU-related user options. Later, we check consistency
      * with things like whether support is compiled, or tMPI thread
@@ -731,9 +731,11 @@ int Mdrunner::mdrunner()
         tMPI_Thread_mutex_unlock(&deform_init_box_mutex);
     }
 
-    ObservablesHistory observablesHistory = {};
+    ObservablesHistory   observablesHistory = {};
 
-    if (Flags & MD_STARTFROMCPT)
+    ContinuationOptions &continuationOptions = mdrunOptions.continuationOptions;
+
+    if (continuationOptions.startedFromCheckpoint)
     {
         /* Check if checkpoint file exists before doing continuation.
          * This way we can use identical input options for the first and subsequent runs...
@@ -743,26 +745,26 @@ int Mdrunner::mdrunner()
         load_checkpoint(opt2fn_master("-cpi", nfile, fnm, cr), &fplog,
                         cr, domdecOptions.numCells,
                         inputrec, state, &bReadEkin, &observablesHistory,
-                        (Flags & MD_APPENDFILES),
-                        (Flags & MD_APPENDFILESSET),
-                        (Flags & MD_REPRODUCIBLE));
+                        continuationOptions.appendFiles,
+                        continuationOptions.appendFilesOptionSet,
+                        mdrunOptions.reproducible);
 
         if (bReadEkin)
         {
-            Flags |= MD_READ_EKIN;
+            continuationOptions.haveReadEkin = true;
         }
     }
 
-    if (SIMMASTER(cr) && (Flags & MD_APPENDFILES))
+    if (SIMMASTER(cr) && continuationOptions.appendFiles)
     {
         gmx_log_open(ftp2fn(efLOG, nfile, fnm), cr,
-                     Flags, &fplog);
+                     continuationOptions.appendFiles, &fplog);
         logOwner = buildLogger(fplog, nullptr);
         mdlog    = logOwner.logger();
     }
 
-    /* override nsteps with value from cmdline */
-    override_nsteps_cmdline(mdlog, nsteps_cmdline, inputrec);
+    /* override nsteps with value set on the commamdline */
+    override_nsteps_cmdline(mdlog, mdrunOptions.numStepsCommandline, inputrec);
 
     if (SIMMASTER(cr))
     {
@@ -777,7 +779,7 @@ int Mdrunner::mdrunner()
     if (PAR(cr) && !(EI_TPI(inputrec->eI) ||
                      inputrec->eI == eiNM))
     {
-        cr->dd = init_domain_decomposition(fplog, cr, domdecOptions, Flags,
+        cr->dd = init_domain_decomposition(fplog, cr, domdecOptions, mdrunOptions,
                                            mtop, inputrec,
                                            box, as_rvec_array(state->x.data()),
                                            &ddbox, &npme_major, &npme_minor);
@@ -890,7 +892,7 @@ int Mdrunner::mdrunner()
 #endif
 
     /* Now that we know the setup is consistent, check for efficiency */
-    check_resource_division_efficiency(hwinfo, hw_opt.nthreads_tot, !gpuTaskAssignment.empty(), Flags & MD_NTOMPSET,
+    check_resource_division_efficiency(hwinfo, hw_opt.nthreads_tot, !gpuTaskAssignment.empty(), mdrunOptions.ntompOptionIsSet,
                                        cr, mdlog);
 
     gmx_device_info_t *shortRangedDeviceInfo = nullptr;
@@ -916,7 +918,7 @@ int Mdrunner::mdrunner()
      */
     nthreads_pme = gmx_omp_nthreads_get(emntPME);
 
-    wcycle = wallcycle_init(fplog, resetstep, cr);
+    wcycle = wallcycle_init(fplog, mdrunOptions.timingOptions.resetStep, cr);
 
     if (PAR(cr))
     {
@@ -937,7 +939,7 @@ int Mdrunner::mdrunner()
         /* Note that membed cannot work in parallel because mtop is
          * changed here. Fix this if we ever want to make it run with
          * multiple ranks. */
-        membed = init_membed(fplog, nfile, fnm, mtop, inputrec, state, cr, &cpt_period);
+        membed = init_membed(fplog, nfile, fnm, mtop, inputrec, state, cr, &mdrunOptions.checkpointOptions.period);
     }
 
     snew(nrnb, 1);
@@ -1070,7 +1072,7 @@ int Mdrunner::mdrunner()
             {
                 status = gmx_pme_init(pmedata, cr, npme_major, npme_minor, inputrec,
                                       mtop ? mtop->natoms : 0, nChargePerturbed, nTypePerturbed,
-                                      (Flags & MD_REPRODUCIBLE),
+                                      mdrunOptions.reproducible,
                                       ewaldcoeff_q, ewaldcoeff_lj,
                                       nthreads_pme);
             }
@@ -1104,14 +1106,15 @@ int Mdrunner::mdrunner()
             inputrec->pull_work =
                 init_pull(fplog, inputrec->pull, inputrec, nfile, fnm,
                           mtop, cr, oenv, inputrec->fepvals->init_lambda,
-                          EI_DYNAMICS(inputrec->eI) && MASTER(cr), Flags);
+                          EI_DYNAMICS(inputrec->eI) && MASTER(cr),
+                          continuationOptions);
         }
 
         if (inputrec->bRot)
         {
             /* Initialize enforced rotation code */
             init_rot(fplog, inputrec, nfile, fnm, cr, as_rvec_array(state->x.data()), state->box, mtop, oenv,
-                     bVerbose, Flags);
+                     mdrunOptions);
         }
 
         /* Let init_constraints know whether we have essential dynamics constraints.
@@ -1134,18 +1137,15 @@ int Mdrunner::mdrunner()
 
         /* Now do whatever the user wants us to do (how flexible...) */
         my_integrator(inputrec->eI) (fplog, cr, mdlog, nfile, fnm,
-                                     oenv, bVerbose,
-                                     nstglobalcomm,
+                                     oenv,
+                                     mdrunOptions,
                                      vsite, constr,
-                                     nstepout, mdModules.outputProvider(),
+                                     mdModules.outputProvider(),
                                      inputrec, mtop,
                                      fcd, state, &observablesHistory,
                                      mdatoms, nrnb, wcycle, fr,
                                      replExParams,
                                      membed,
-                                     cpt_period, max_hours,
-                                     imdport,
-                                     Flags,
                                      walltime_accounting);
 
         if (inputrec->bRot)
@@ -1199,7 +1199,7 @@ int Mdrunner::mdrunner()
     walltime_accounting_destroy(walltime_accounting);
 
     /* Close logfile already here if we were appending to it */
-    if (MASTER(cr) && (Flags & MD_APPENDFILES))
+    if (MASTER(cr) && continuationOptions.appendFiles)
     {
         gmx_log_close(fplog);
     }
index 0f5225277f3a60a9fa948ae30a93c6a84ed9feb2..90fe1d98b8e9415a8e54b136cb418e0b28808b89 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/hardware/hw_info.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/mdlib/mdrun.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
@@ -132,36 +133,20 @@ class Mdrunner
         int nfile = filenames.size();
         //! Output context for writing text files
         gmx_output_env_t                *oenv = nullptr;
-        //! TRUE if mdrun should be verbose.
-        gmx_bool                         bVerbose = FALSE;
-        //! Number of steps between global communication.
-        int                              nstglobalcomm = -1;
+        //! Ongoing collection of mdrun options
+        MdrunOptions                     mdrunOptions;
         //! Options for the domain decomposition.
         DomdecOptions                    domdecOptions;
         //! Target short-range interations for "cpu", "gpu", "gpu_cpu", or "auto". Default is "auto".
         const char                      *nbpu_opt = nullptr;
         //! Command-line override for the duration of a neighbor list with the Verlet scheme.
         int                              nstlist_cmdline = 0;
-        //! Command-line override for the number of MD steps (-2 means that the mdp option will be used).
-        gmx_int64_t                      nsteps_cmdline = -2;
-        //! Number of steps between output to the console of time remaining.
-        int                              nstepout = 100;
-        //! Number of steps that elapse before cycle counters are reset.
-        int                              resetstep = -1;
         //! Number of simulations in multi-simulation set.
         int                              nmultisim = 0;
         //! Parameters for replica-exchange simulations.
         ReplicaExchangeParameters        replExParams;
         //! Print a warning if any force is larger than this (in kJ/mol nm).
         real                             pforce = -1;
-        //! Period (in wall-clock minutes) between writing checkpoint files.
-        real                             cpt_period = 15.0;
-        //! Maximum duration of this simulation (in wall-clock hours).
-        real                             max_hours = -1;
-        //! Socket number used for IMD inter-process communication.
-        int                              imdport = 8888;
-        //! Bitfield of boolean flags configuring mdrun behavior.
-        unsigned long                    Flags = 0;
         //! Handle to file used for logging.
         FILE                            *fplog;
         //! Handle to communication data structure.