Skip to content

Commit

Permalink
Obtain the replicas communicator from GROMACS
Browse files Browse the repository at this point in the history
Simplified version of the code in Colvars/gromacs#4

Patch core GROMACS files
  • Loading branch information
giacomofiorin committed Oct 2, 2024
1 parent dd8bd4d commit 7467faa
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
32 changes: 32 additions & 0 deletions gromacs/gromacs-mdmodules.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp
index 321833a6d6..e847921390 100644
--- a/src/gromacs/mdrun/runner.cpp
+++ b/src/gromacs/mdrun/runner.cpp
@@ -1837,6 +1837,7 @@ int Mdrunner::mdrunner()
if (thisRankHasDuty(cr, DUTY_PP))
{
setupNotifier.notify(*cr);
+ setupNotifier.notify(ms);
setupNotifier.notify(&atomSets);
setupNotifier.notify(mtop);
setupNotifier.notify(inputrec->pbcType);
diff --git a/src/gromacs/mdrunutility/mdmodulesnotifiers.h b/src/gromacs/mdrunutility/mdmodulesnotifiers.h
index 913cb0b3c4..76c8ebc09a 100644
--- a/src/gromacs/mdrunutility/mdmodulesnotifiers.h
+++ b/src/gromacs/mdrunutility/mdmodulesnotifiers.h
@@ -62,6 +62,7 @@ struct gmx_mtop_t;
class WarningHandler;
enum class PbcType : int;
struct t_inputrec;
+struct gmx_multisim_t;

namespace gmx
{
@@ -395,6 +396,7 @@ struct MDModulesNotifiers
const SimulationTimeStep&,
const EnsembleTemperature&,
const t_commrec&,
+ const gmx_multisim_t*,
const MdRunInputFilename&,
const EdrOutputFilename&,
const PlumedInputFilename&>::type simulationSetupNotifier_;
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@
*/
#include "gmxpre.h"

#include "colvarsMDModule.h"

#include <functional>
#include <memory>
#include <string>

#include "gromacs/domdec/localatomsetmanager.h"
#include "gromacs/fileio/checkpoint.h"
#include "gromacs/mdrunutility/mdmodulesnotifiers.h"
#include "gromacs/mdrunutility/multisim.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/iforceprovider.h"
#include "gromacs/mdtypes/imdmodule.h"
Expand All @@ -58,6 +57,8 @@
#include "colvarsoptions.h"
#include "colvarssimulationsparameters.h"

#include "colvarsMDModule.h"

enum class PbcType : int;
struct gmx_mtop_t;

Expand Down Expand Up @@ -97,7 +98,7 @@ class ColvarsMDModule final : public IMDModule
* KeyValueTreeObjectBuilder as parameter
* - Acess topology using gmx_mtop_t notification
* - Access MDLogger for notifications output
* - Access warninp for for grompp warnings output
* - Access warning for for grompp warnings output
* - Coordinates, PBC and box for setting up the proxy
*/
void subscribeToPreProcessingNotifications(MDModulesNotifiers* notifier) override
Expand Down Expand Up @@ -192,6 +193,12 @@ class ColvarsMDModule final : public IMDModule
};
notifier->simulationSetupNotifier_.subscribe(setCommFunction);

// Retrieve the Multisim Record during simulations setup
const auto setMultisimFunction = [this](const gmx_multisim_t *ms) {
this->ColvarsSimulationsParameters_.setMultisim(ms);
};
notifier->simulationSetupNotifier_.subscribe(setMultisimFunction);

// setting the simulation time step
const auto setSimulationTimeStepFunction = [this](const SimulationTimeStep& simulationTimeStep) {
this->ColvarsSimulationsParameters_.setSimulationTimeStep(simulationTimeStep.delta_t);
Expand Down Expand Up @@ -251,6 +258,7 @@ class ColvarsMDModule final : public IMDModule
colvarsOptions_.colvarsSeed(),
ColvarsSimulationsParameters_.localAtomSetManager(),
ColvarsSimulationsParameters_.comm(),
ColvarsSimulationsParameters_.ms(),
ColvarsSimulationsParameters_.simulationTimeStep(),
colvarsOptions_.colvarsAtomCoords(),
colvarsOptions_.colvarsOutputPrefix(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@
* \ingroup module_applied_forces
*/

#include "colvarsforceprovider.h"

#include <cstddef>
#include <cstdint>

#include <array>
#include <string>

#include "external/colvars/colvars_memstream.h"

#include "gromacs/applied_forces/colvars/colvarproxygromacs.h"
#include "gromacs/compat/pointers.h"
#include "gromacs/domdec/localatomsetmanager.h"
Expand All @@ -57,6 +53,7 @@
#include "gromacs/math/vec.h"
#include "gromacs/mdlib/broadcaststructs.h"
#include "gromacs/mdlib/groupcoord.h"
#include "gromacs/mdrunutility/multisim.h"
#include "gromacs/mdtypes/commrec.h"
#include "gromacs/mdtypes/enerdata.h"
#include "gromacs/mdtypes/forceoutput.h"
Expand All @@ -65,10 +62,15 @@
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxmpi.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/keyvaluetreebuilder.h"
#include "gromacs/utility/smalloc.h"

#include "colvarsforceprovider.h"

#include "external/colvars/colvars_memstream.h"

enum class PbcType : int;


Expand Down Expand Up @@ -173,6 +175,7 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin
int seed,
LocalAtomSetManager* localAtomSetManager,
const t_commrec* cr,
const gmx_multisim_t* ms,
double simulationTimeStep,
const std::vector<RVec>& colvarsCoords,
const std::string& outputPrefix,
Expand Down Expand Up @@ -236,6 +239,14 @@ ColvarsForceProvider::ColvarsForceProvider(const std::string& colvarsConfigStrin
snew(fColvars, nColvarsAtoms);
snew(xColvarsOldWhole, nColvarsAtoms);

#if GMX_MPI
if (MAIN(cr))
{
if (isMultiSim(ms)) {
colvarproxy::set_replicas_mpi_communicator(ms->mainRanksComm_);
}
}
#endif

// Check state status (did we read a cpt file?)
if (MAIN(cr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

enum class PbcType : int;
struct t_commrec;
struct gmx_multisim_t;


namespace gmx
Expand Down Expand Up @@ -196,6 +197,7 @@ class ColvarsForceProvider final : public ColvarProxyGromacs, public IForceProvi
int seed,
LocalAtomSetManager* localAtomSetManager,
const t_commrec* cr,
const gmx_multisim_t* ms,
double simulationTimeStep,
const std::vector<RVec>& colvarsCoords,
const std::string& outputPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ const t_commrec* ColvarsSimulationsParameters::comm() const
return cr_;
}

void ColvarsSimulationsParameters::setMultisim(const gmx_multisim_t *ms)
{
ms_ = ms;
}

const gmx_multisim_t* ColvarsSimulationsParameters::ms() const
{
return ms_;
}


void ColvarsSimulationsParameters::setLogger(const MDLogger& logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "gromacs/pbcutil/pbc.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/utility/logger.h"
struct gmx_multisim_t;

struct gmx_mtop_t;

Expand Down Expand Up @@ -109,7 +110,12 @@ class ColvarsSimulationsParameters
//! Return the communicator
const t_commrec* comm() const;

/*! \brief Set the logger for QMMM during mdrun
//! Set the Multisim record
void setMultisim(const gmx_multisim_t *ms);
//! Return Multisim record
const gmx_multisim_t* ms() const;

/*! \brief Set the logger for Colvars during mdrun
* \param[in] logger Logger instance to be used for output
*/
void setLogger(const MDLogger& logger);
Expand All @@ -128,6 +134,8 @@ class ColvarsSimulationsParameters
t_atoms gmxAtoms_;
//! The communicator
const t_commrec* cr_;
//! The multisim record
const gmx_multisim_t *ms_;
//! MDLogger for notifications during mdrun
const MDLogger* logger_ = nullptr;

Expand Down

0 comments on commit 7467faa

Please sign in to comment.