struct gmx_membed_t;
struct gmx_output_env_t;
struct ObservablesHistory;
+struct ReplicaExchangeParameters;
struct t_commrec;
struct t_filenm;
struct t_inputrec;
* \param[in] nrnb Accounting for floating point operations
* \param[in] wcycle Wall cycle timing information
* \param[in] fr Force record with cut-off information and more
- * \param[in] repl_ex_nst How often we do replica exchange (in steps)
- * \param[in] repl_ex_nex How many replicas we have
- * \param[in] repl_ex_seed The seed for Monte Carlo swaps
+ * \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)
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,
+ const ReplicaExchangeParameters &replExParams,
gmx_membed_t gmx_unused * membed,
real cpt_period, real max_hours,
int imdport,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
gmx_edsam_t ed,
t_forcerec *fr,
- int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ const ReplicaExchangeParameters &replExParams,
gmx_membed_t gmx_unused *membed,
real cpt_period, real max_hours,
int imdport,
t_mdatoms *mdatoms,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
t_forcerec *fr,
- int gmx_unused repl_ex_nst, int gmx_unused repl_ex_nex, int gmx_unused repl_ex_seed,
+ const ReplicaExchangeParameters gmx_unused &replExParams,
gmx_membed_t gmx_unused *membed,
real gmx_unused cpt_period, real gmx_unused max_hours,
int imdport,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
gmx_edsam_t ed,
t_forcerec *fr,
- int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ const ReplicaExchangeParameters &replExParams,
gmx_membed_t gmx_unused *membed,
real cpt_period, real max_hours,
int imdport,
t_mdatoms *mdatoms,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
t_forcerec *fr,
- int gmx_unused repl_ex_nst, int gmx_unused repl_ex_nex, int gmx_unused repl_ex_seed,
+ const ReplicaExchangeParameters gmx_unused &replExParams,
gmx_membed_t gmx_unused *membed,
real gmx_unused cpt_period, real gmx_unused max_hours,
int imdport,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
gmx_edsam_t ed,
t_forcerec *fr,
- int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ const ReplicaExchangeParameters &replExParams,
real cpt_period, real max_hours,
int imdport,
unsigned long Flags,
t_mdatoms *mdatoms,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
t_forcerec *fr,
- int gmx_unused repl_ex_nst, int gmx_unused repl_ex_nex, int gmx_unused repl_ex_seed,
+ const ReplicaExchangeParameters gmx_unused &replExParams,
gmx_membed_t gmx_unused *membed,
real gmx_unused cpt_period, real gmx_unused max_hours,
int imdport,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
gmx_edsam_t ed,
t_forcerec *fr,
- int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ const ReplicaExchangeParameters &replExParams,
real cpt_period, real max_hours,
int imdport,
unsigned long Flags,
t_mdatoms *mdatoms,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
t_forcerec *fr,
- int gmx_unused repl_ex_nst, int gmx_unused repl_ex_nex, int gmx_unused repl_ex_seed,
+ const ReplicaExchangeParameters gmx_unused &replExParams,
gmx_membed_t gmx_unused *membed,
real gmx_unused cpt_period, real gmx_unused max_hours,
int imdport,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
gmx_edsam_t ed,
t_forcerec *fr,
- int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ const ReplicaExchangeParameters &replExParams,
real cpt_period, real max_hours,
int imdport,
unsigned long Flags,
t_mdatoms *mdatoms,
t_nrnb *nrnb, gmx_wallcycle_t wcycle,
t_forcerec *fr,
- int gmx_unused repl_ex_nst, int gmx_unused repl_ex_nex, int gmx_unused repl_ex_seed,
+ 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,
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,
+ const ReplicaExchangeParameters &replExParams,
gmx_membed_t *membed,
real cpt_period, real max_hours,
int imdport,
set_constraints(constr, top, ir, mdatoms, cr);
}
- if (repl_ex_nst > 0 && MASTER(cr))
+ const bool useReplicaExchange = (replExParams.exchangeInterval > 0);
+ if (useReplicaExchange && MASTER(cr))
{
repl_ex = init_replica_exchange(fplog, cr->ms, state_global, ir,
- repl_ex_nst, repl_ex_nex, repl_ex_seed);
+ replExParams);
}
/* PME tuning is only supported with PME for Coulomb. Is is not supported
{
nstfep = gmx_greatest_common_divisor(ir->expandedvals->nstexpanded, nstfep);
}
- if (repl_ex_nst > 0)
+ if (useReplicaExchange)
{
- nstfep = gmx_greatest_common_divisor(repl_ex_nst, nstfep);
+ nstfep = gmx_greatest_common_divisor(replExParams.exchangeInterval, nstfep);
}
}
// checkpoints and stop conditions to act on the same step, so
// the propagation of such signals must take place between
// simulations, not just within simulations.
- bool checkpointIsLocal = (repl_ex_nst <= 0) && !bUsingEnsembleRestraints;
- bool stopConditionIsLocal = (repl_ex_nst <= 0) && !bUsingEnsembleRestraints;
+ bool checkpointIsLocal = !useReplicaExchange && !bUsingEnsembleRestraints;
+ bool stopConditionIsLocal = !useReplicaExchange && !bUsingEnsembleRestraints;
bool resetCountersIsLocal = true;
signals[eglsCHKPT] = SimulationSignal(checkpointIsLocal);
signals[eglsSTOPCOND] = SimulationSignal(stopConditionIsLocal);
step_rel = 0;
// TODO extract this to new multi-simulation module
- if (MASTER(cr) && MULTISIM(cr) && (repl_ex_nst <= 0 ))
+ if (MASTER(cr) && MULTISIM(cr) && !useReplicaExchange)
{
if (!multisim_int_all_are_equal(cr->ms, ir->nsteps))
{
&& (ir->bExpanded) && (step > 0) && (!startingFromCheckpoint));
}
- bDoReplEx = ((repl_ex_nst > 0) && (step > 0) && !bLastStep &&
- do_per_step(step, repl_ex_nst));
+ bDoReplEx = (useReplicaExchange && (step > 0) && !bLastStep &&
+ do_per_step(step, replExParams.exchangeInterval));
if (bSimAnn)
{
done_shellfc(fplog, shellfc, step_rel);
- if (repl_ex_nst > 0 && MASTER(cr))
+ if (useReplicaExchange && MASTER(cr))
{
print_replica_exchange_statistics(fplog, repl_ex);
}
#include "gromacs/utility/smalloc.h"
#include "mdrun_main.h"
+#include "repl_ex.h"
#include "runner.h"
/*! \brief Return whether either of the command-line parameters that
};
const int NFILE = asize(fnm);
- /* Command line options ! */
+ /* Command line option parameters, with their default values */
gmx_bool bDDBondCheck = TRUE;
gmx_bool bDDBondComm = TRUE;
gmx_bool bTunePME = TRUE;
int nstlist = 0;
int nmultisim = 0;
int nstglobalcomm = -1;
- int repl_ex_nst = 0;
- int repl_ex_seed = -1;
- int repl_ex_nex = 0;
int nstepout = 100;
int resetstep = -1;
gmx_int64_t nsteps = -2; /* the value -2 means that the mdp option will be used */
- int imdport = 8888; /* can be almost anything, 8888 is easy to remember */
+ /* Special algorithms section */
+ ReplicaExchangeParameters replExParams;
+ int imdport = 8888; /* can be almost anything, 8888 is easy to remember */
+
+ /* Command line options */
rvec realddxyz = {0, 0, 0};
const char *ddrank_opt[ddrankorderNR+1] =
{ nullptr, "interleave", "pp_pme", "cartesian", nullptr };
"Terminate after 0.99 times this time (hours)" },
{ "-multi", FALSE, etINT, {&nmultisim},
"Do multiple simulations in parallel" },
- { "-replex", FALSE, etINT, {&repl_ex_nst},
+ { "-replex", FALSE, etINT, {&replExParams.exchangeInterval},
"Attempt replica exchange periodically with this period (steps)" },
- { "-nex", FALSE, etINT, {&repl_ex_nex},
+ { "-nex", FALSE, etINT, {&replExParams.numExchanges},
"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, {&repl_ex_seed},
+ { "-reseed", FALSE, etINT, {&replExParams.randomSeed},
"Seed for replica exchange, -1 is generate a seed" },
{ "-imdport", FALSE, etINT, {&imdport},
"HIDDENIMD listening port" },
}
- if (repl_ex_nst != 0 && nmultisim < 2)
+ if (replExParams.exchangeInterval != 0 && nmultisim < 2)
{
gmx_fatal(FARGS, "Need at least two replicas for replica exchange (option -multi)");
}
- if (repl_ex_nex < 0)
+ if (replExParams.numExchanges < 0)
{
gmx_fatal(FARGS, "Replica exchange number of exchanges needs to be positive");
}
dddlb_opt[0], dlb_scale, ddcsx, ddcsy, ddcsz,
nbpu_opt[0], nstlist,
nsteps, nstepout, resetstep,
- nmultisim, repl_ex_nst, repl_ex_nex, repl_ex_seed,
+ nmultisim, replExParams,
pforce, cpt_period, max_hours, imdport, Flags);
/* Log file has to be closed in mdrunner if we are appending to it
return bDiff;
}
-gmx_repl_ex_t init_replica_exchange(FILE *fplog,
- const gmx_multisim_t *ms,
- const t_state *state,
- const t_inputrec *ir,
- int nst, int nex, int init_seed)
+gmx_repl_ex_t
+init_replica_exchange(FILE *fplog,
+ const gmx_multisim_t *ms,
+ const t_state *state,
+ const t_inputrec *ir,
+ const ReplicaExchangeParameters &replExParams)
{
real pres;
int i, j, k;
check_multi_int(fplog, ms, state->natoms, "the number of atoms", FALSE);
check_multi_int(fplog, ms, ir->eI, "the integrator", FALSE);
check_multi_int64(fplog, ms, ir->init_step+ir->nsteps, "init_step+nsteps", FALSE);
+ const int nst = replExParams.exchangeInterval;
check_multi_int64(fplog, ms, (ir->init_step+nst-1)/nst,
"first exchange step: init_step/-replex", FALSE);
check_multi_int(fplog, ms, ir->etc, "the temperature coupling", FALSE);
}
}
re->nst = nst;
- if (init_seed == -1)
+ if (replExParams.randomSeed == -1)
{
if (MASTERSIM(ms))
{
}
else
{
- re->seed = init_seed;
+ re->seed = replExParams.randomSeed;
}
fprintf(fplog, "\nReplica exchange interval: %d\n", re->nst);
fprintf(fplog, "\nReplica random seed: %d\n", re->seed);
{
snew(re->de[i], re->nrepl);
}
- re->nex = nex;
+ re->nex = replExParams.numExchanges;
return re;
}
struct t_inputrec;
class t_state;
+/* The parameters for the replica exchange algorithm */
+struct ReplicaExchangeParameters
+{
+ ReplicaExchangeParameters() :
+ exchangeInterval(0),
+ numExchanges(0),
+ randomSeed(-1)
+ {
+ };
+
+ int exchangeInterval; /* Interval in steps at which to attempt exchanges, 0 means no replica exchange */
+ int numExchanges; /* The number of exchanges to attempt at an exchange step */
+ int randomSeed; /* The random seed, -1 means generate a seed */
+};
+
/* Abstract type for replica exchange */
typedef struct gmx_repl_ex *gmx_repl_ex_t;
-gmx_repl_ex_t init_replica_exchange(FILE *fplog,
- const gmx_multisim_t *ms,
- const t_state *state,
- const t_inputrec *ir,
- int nst, int nmultiex, int init_seed);
-/* Should only be called on the master nodes */
+gmx_repl_ex_t
+init_replica_exchange(FILE *fplog,
+ const gmx_multisim_t *ms,
+ const t_state *state,
+ const t_inputrec *ir,
+ const ReplicaExchangeParameters &replExParams);
+/* Should only be called on the master ranks */
gmx_bool replica_exchange(FILE *fplog,
const t_commrec *cr,
t_state *state, gmx_enerdata_t *enerd,
t_state *state_local,
gmx_int64_t step, real time);
-/* Attempts replica exchange, should be called on all nodes.
+/* Attempts replica exchange, should be called on all ranks.
* Returns TRUE if this state has been exchanged.
* When running each replica in parallel,
- * this routine collects the state on the master node before exchange.
+ * this routine collects the state on the master rank before exchange.
* With domain decomposition, the global state after exchange is stored
- * in state and still needs to be redistributed over the nodes.
+ * in state and still needs to be redistributed over the ranks.
*/
void print_replica_exchange_statistics(FILE *fplog, gmx_repl_ex_t re);
-/* Should only be called on the master nodes */
+/* Should only be called on the master ranks */
#endif /* _repl_ex_h */
struct mdrunner_arglist
{
- gmx_hw_opt_t hw_opt;
- FILE *fplog;
- t_commrec *cr;
- int nfile;
- const t_filenm *fnm;
- const gmx_output_env_t *oenv;
- gmx_bool bVerbose;
- int nstglobalcomm;
- ivec ddxyz;
- int dd_rank_order;
- int npme;
- real rdd;
- real rconstr;
- const char *dddlb_opt;
- real dlb_scale;
- const char *ddcsx;
- const char *ddcsy;
- const char *ddcsz;
- const char *nbpu_opt;
- int nstlist_cmdline;
- gmx_int64_t nsteps_cmdline;
- int nstepout;
- int resetstep;
- int nmultisim;
- int repl_ex_nst;
- int repl_ex_nex;
- int repl_ex_seed;
- real pforce;
- real cpt_period;
- real max_hours;
- int imdport;
- unsigned long Flags;
+ gmx_hw_opt_t hw_opt;
+ FILE *fplog;
+ t_commrec *cr;
+ int nfile;
+ const t_filenm *fnm;
+ const gmx_output_env_t *oenv;
+ gmx_bool bVerbose;
+ int nstglobalcomm;
+ ivec ddxyz;
+ int dd_rank_order;
+ int npme;
+ real rdd;
+ real rconstr;
+ const char *dddlb_opt;
+ real dlb_scale;
+ const char *ddcsx;
+ const char *ddcsy;
+ const char *ddcsz;
+ const char *nbpu_opt;
+ int nstlist_cmdline;
+ gmx_int64_t nsteps_cmdline;
+ int nstepout;
+ int resetstep;
+ int nmultisim;
+ const ReplicaExchangeParameters *replExParams;
+ real pforce;
+ real cpt_period;
+ real max_hours;
+ int imdport;
+ unsigned long Flags;
};
mc.ddcsx, mc.ddcsy, mc.ddcsz,
mc.nbpu_opt, mc.nstlist_cmdline,
mc.nsteps_cmdline, mc.nstepout, mc.resetstep,
- mc.nmultisim, mc.repl_ex_nst, mc.repl_ex_nex, mc.repl_ex_seed, mc.pforce,
+ mc.nmultisim, *mc.replExParams, mc.pforce,
mc.cpt_period, mc.max_hours, mc.imdport, mc.Flags);
}
GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
const char *nbpu_opt, int nstlist_cmdline,
gmx_int64_t nsteps_cmdline,
int nstepout, int resetstep,
- int nmultisim, int repl_ex_nst, int repl_ex_nex, int repl_ex_seed,
+ int nmultisim,
+ const ReplicaExchangeParameters &replExParams,
real pforce, real cpt_period, real max_hours,
unsigned long Flags)
{
mda->nstepout = nstepout;
mda->resetstep = resetstep;
mda->nmultisim = nmultisim;
- mda->repl_ex_nst = repl_ex_nst;
- mda->repl_ex_nex = repl_ex_nex;
- mda->repl_ex_seed = repl_ex_seed;
+ mda->replExParams = &replExParams;
mda->pforce = pforce;
mda->cpt_period = cpt_period;
mda->max_hours = max_hours;
const char *ddcsx, const char *ddcsy, const char *ddcsz,
const char *nbpu_opt, int nstlist_cmdline,
gmx_int64_t nsteps_cmdline, int nstepout, int resetstep,
- int gmx_unused nmultisim, int repl_ex_nst, int repl_ex_nex,
- int repl_ex_seed, real pforce, real cpt_period, real max_hours,
+ int gmx_unused nmultisim,
+ const ReplicaExchangeParameters &replExParams,
+ real pforce, real cpt_period, real max_hours,
int imdport, unsigned long Flags)
{
gmx_bool bForceUseGPU, bTryUseGPU, bRerunMD;
dddlb_opt, dlb_scale, ddcsx, ddcsy, ddcsz,
nbpu_opt, nstlist_cmdline,
nsteps_cmdline, nstepout, resetstep, nmultisim,
- repl_ex_nst, repl_ex_nex, repl_ex_seed, pforce,
+ replExParams, pforce,
cpt_period, max_hours,
Flags);
/* the main thread continues here with a new cr. We don't deallocate
snew(fcd, 1);
/* This needs to be called before read_checkpoint to extend the state */
- init_disres(fplog, mtop, inputrec, cr, fcd, state, repl_ex_nst > 0);
+ init_disres(fplog, mtop, inputrec, cr, fcd, state, replExParams.exchangeInterval > 0);
init_orires(fplog, mtop, as_rvec_array(state->x.data()), inputrec, cr, &(fcd->orires),
state);
inputrec, mtop,
fcd, state, &observablesHistory,
mdatoms, nrnb, wcycle, fr,
- repl_ex_nst, repl_ex_nex, repl_ex_seed,
+ replExParams,
membed,
cpt_period, max_hours,
imdport,
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015, by the GROMACS development team, led by
+ * Copyright (c) 2015,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.
#include "gromacs/utility/real.h"
struct gmx_output_env_t;
+struct ReplicaExchangeParameters;
struct t_commrec;
struct t_filenm;
* \param[in] nstepout How often to write to the console
* \param[in] resetstep Reset the step counter
* \param[in] nmultisim Number of parallel simulations to run
- * \param[in] repl_ex_nst Number steps between replica exchange attempts
- * \param[in] repl_ex_nex Number of replicas in REMD
- * \param[in] repl_ex_seed The seed for Monte Carlo swaps
+ * \param[in] replExParams Parameters for the replica exchange algorithm
* \param[in] pforce Minimum force for printing (for debugging)
* \param[in] cpt_period How often to checkpoint the simulation
* \param[in] max_hours Maximume length of the simulation (wall time)
const char *ddcsx, const char *ddcsy, const char *ddcsz,
const char *nbpu_opt, int nstlist_cmdline,
gmx_int64_t nsteps_cmdline, int nstepout, int resetstep,
- int nmultisim, int repl_ex_nst, int repl_ex_nex,
- int repl_ex_seed, real pforce, real cpt_period, real max_hours,
+ int nmultisim,
+ const ReplicaExchangeParameters &replExParams,
+ real pforce, real cpt_period, real max_hours,
int imdport, unsigned long Flags);