Skip to content

Commit

Permalink
Move MPI comm and rank information from Model to ModelMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
draenog committed Jun 12, 2023
1 parent 9a1d13d commit 785a312
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
6 changes: 2 additions & 4 deletions core/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Model::Model()
#endif
{
#ifdef USE_MPI
mpiComm = comm;
MPI_Comm_size(mpiComm, &mpiSize);
MPI_Comm_rank(mpiComm, &mpiMyRank);
m_etadata.setMpiMetadata(comm);
#endif

iterator.setIterant(&modelStep);
Expand Down Expand Up @@ -93,7 +91,7 @@ void Model::configure()
std::string partitionFile = Configured::getConfiguration(keyMap.at(PARTITIONFILE_KEY), std::string("partition.nc"));

#ifdef USE_MPI
ModelState initialState(StructureFactory::stateFromFile(initialFileName, partitionFile, mpiComm));
ModelState initialState(StructureFactory::stateFromFile(initialFileName, partitionFile, m_etadata.mpiComm));
#else
ModelState initialState(StructureFactory::stateFromFile(initialFileName));
#endif
Expand Down
8 changes: 8 additions & 0 deletions core/src/ModelMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ const std::string& ModelMetadata::structureName() const
return Module::getImplementation<IStructure>().structureType();
}

#ifdef USE_MPI
void ModelMetadata::setMpiMetadata(MPI_Comm comm) {
mpiComm = comm;
MPI_Comm_size(mpiComm, &mpiSize);
MPI_Comm_rank(mpiComm, &mpiMyRank);
}
#endif

} /* namespace Nextsim */
10 changes: 0 additions & 10 deletions core/src/include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "DevStep.hpp"
#include <string>

#ifdef USE_MPI
#include <mpi.h>
#endif

namespace Nextsim {

//! A class that encapsulates the whole of the model
Expand Down Expand Up @@ -79,12 +75,6 @@ class Model : public Configured<Model> {
std::string stopTimeStr;
std::string durationStr;
std::string stepStr;

#ifdef USE_MPI
MPI_Comm mpiComm;
int mpiSize = 0;
int mpiMyRank = -1;
#endif
};

} /* namespace Nextsim */
Expand Down
12 changes: 12 additions & 0 deletions core/src/include/ModelMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include <string>

#ifdef USE_MPI
#include <mpi.h>
#endif

namespace Nextsim {

class CommonRestartMetadata;
Expand Down Expand Up @@ -51,6 +55,14 @@ class ModelMetadata {
// The metadata writer should be a friend
friend CommonRestartMetadata;

#ifdef USE_MPI
void setMpiMetadata(MPI_Comm comm);

MPI_Comm mpiComm;
int mpiSize = 0;
int mpiMyRank = -1;
#endif

private:
TimePoint m_time;
ConfigMap m_config;
Expand Down

0 comments on commit 785a312

Please sign in to comment.