#include "gromacs/math/vec.h"
#include "gromacs/mdlib/force.h"
#include "gromacs/mdlib/mdatoms.h"
+#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/fcdata.h"
#include "gromacs/mdtypes/inputrec.h"
#include "gromacs/mdtypes/md_enums.h"
}
ir->dr_tau = 0.0;
- init_disres(fplog, topInfo.mtop(), ir, nullptr, nullptr, &fcd, nullptr, FALSE);
+ init_disres(fplog, topInfo.mtop(), ir, DisResRunMode::AnalysisTool, DDRole::Master,
+ NumRanks::Single, MPI_COMM_NULL, nullptr, &fcd, nullptr, FALSE);
int natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
snew(f, 5 * natoms);
void init_disres(FILE* fplog,
const gmx_mtop_t* mtop,
t_inputrec* ir,
- const t_commrec* cr,
+ DisResRunMode disResRunMode,
+ DDRole ddRole,
+ NumRanks numRanks,
+ MPI_Comm communicator,
const gmx_multisim_t* ms,
t_fcdata* fcd,
t_state* state,
{
/* We store the r^-6 time averages in an array that is indexed
* with the local disres iatom index, so this doesn't work with DD.
- * Note that DD is not initialized yet here, so we check for PAR(cr),
+ * Note that DD is not initialized yet here, so we check that we are on multiple ranks,
* but there are probably also issues with e.g. NM MPI parallelization.
*/
- if (cr && PAR(cr))
+ if ((disResRunMode == DisResRunMode::MDRun) && (numRanks == NumRanks::Multiple))
{
gmx_fatal(FARGS,
"Time-averaged distance restraints are not supported with MPI "
}
}
- if (cr && PAR(cr) && ir->nstdisreout > 0)
+ if ((disResRunMode == DisResRunMode::MDRun) && (numRanks == NumRanks::Multiple) && ir->nstdisreout > 0)
{
/* With DD we currently only have local pair information available */
gmx_fatal(FARGS,
dd->Rtav_6 = &(dd->Rt_6[dd->nres]);
ptr = getenv("GMX_DISRE_ENSEMBLE_SIZE");
- if (cr && ms != nullptr && ptr != nullptr && !bIsREMD)
+ if ((disResRunMode == DisResRunMode::MDRun) && ms != nullptr && ptr != nullptr && !bIsREMD)
{
#if GMX_MPI
dd->nsystems = 0;
/* This check is only valid on MASTER(cr), so probably
* ensemble-averaged distance restraints are broken on more
* than one processor per simulation system. */
- if (MASTER(cr))
+ if (ddRole == DDRole::Master)
{
check_multi_int(fplog, ms, dd->nsystems, "the number of systems per ensemble", FALSE);
}
- gmx_bcast(sizeof(int), &dd->nsystems, cr->mpi_comm_mysim);
+ gmx_bcast(sizeof(int), &dd->nsystems, communicator);
/* We use to allow any value of nsystems which was a divisor
* of ms->nsim. But this required an extra communicator which
* checks from appropriate processes (since check_multi_int is
* too broken to check whether the communication will
* succeed...) */
- if (cr && ms && dd->nsystems > 1 && MASTER(cr))
+ if ((disResRunMode == DisResRunMode::MDRun) && ms && dd->nsystems > 1 && (ddRole == DDRole::Master))
{
check_multi_int(fplog, ms, fcd->disres.nres, "the number of distance restraints", FALSE);
}
#include "gromacs/topology/ifunc.h"
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/gmxmpi.h"
struct gmx_mtop_t;
struct gmx_multisim_t;
struct t_inputrec;
struct t_pbc;
class t_state;
+enum class DDRole;
+enum class NumRanks;
+
+//! Whether distance restraints are called from mdrun or from an analysis tool
+enum class DisResRunMode
+{
+ MDRun,
+ AnalysisTool
+};
/*! \brief
* Initiates *fcd data.
void init_disres(FILE* fplog,
const gmx_mtop_t* mtop,
t_inputrec* ir,
- const t_commrec* cr,
+ DisResRunMode disResRunMode,
+ DDRole ddRole,
+ NumRanks numRanks,
+ MPI_Comm communicator,
const gmx_multisim_t* ms,
t_fcdata* fcd,
t_state* state,
snew(fcd, 1);
/* This needs to be called before read_checkpoint to extend the state */
- init_disres(fplog, &mtop, inputrec, cr, ms, fcd, globalState.get(), replExParams.exchangeInterval > 0);
+ init_disres(fplog, &mtop, inputrec, DisResRunMode::MDRun, MASTER(cr) ? DDRole::Master : DDRole::Agent,
+ PAR(cr) ? NumRanks::Multiple : NumRanks::Single, cr->mpi_comm_mysim, ms, fcd,
+ globalState.get(), replExParams.exchangeInterval > 0);
init_orires(fplog, &mtop, inputrec, cr, ms, globalState.get(), &(fcd->orires));
#define DUTY_PP (1U << 0U)
#define DUTY_PME (1U << 1U)
+//! Whether the current DD role is master or slave
+enum class DDRole
+{
+ Master,
+ Agent
+};
+
+//! Whether one or more ranks are used
+enum class NumRanks
+{
+ Single,
+ Multiple
+};
+
typedef struct
{
int bUse;