Replacing use of MPI_COMM_WORLD with a variable communicator.

This commit is contained in:
Elyes Ahmed
2021-05-25 12:57:11 +02:00
committed by Atgeirr Flø Rasmussen
parent 61ef539bf5
commit f53c597f90
48 changed files with 584 additions and 420 deletions

View File

@@ -149,8 +149,27 @@ namespace Opm
initMPI();
}
#define DEMONSTRATE_RUN_WITH_NONWORLD_COMM 1
~Main()
{
#if DEMONSTRATE_RUN_WITH_NONWORLD_COMM
#if HAVE_MPI
// Cannot use EclGenericVanguard::comm()
// to get world size here, as it may be
// a split communication at this point.
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
if (world_size > 1) {
MPI_Comm new_comm = EclGenericVanguard::comm();
int result;
MPI_Comm_compare(MPI_COMM_WORLD, new_comm, &result);
assert(result == MPI_UNEQUAL);
MPI_Comm_free(&new_comm);
}
#endif // HAVE_MPI
#endif // DEMONSTRATE_RUN_WITH_NONWORLD_COMM
EclGenericVanguard::setCommunication(nullptr);
#if HAVE_MPI && !HAVE_DUNE_FEM
@@ -175,28 +194,43 @@ namespace Opm
#elif HAVE_MPI
MPI_Init(&argc_, &argv_);
#endif
EclGenericVanguard::setCommunication(std::make_unique<EclGenericVanguard::CommunicationType>());
EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>());
#if DEMONSTRATE_RUN_WITH_NONWORLD_COMM
#if HAVE_MPI
if (EclGenericVanguard::comm().size() > 1) {
int world_rank = EclGenericVanguard::comm().rank();
int color = (world_rank == 0);
MPI_Comm new_comm;
MPI_Comm_split(EclGenericVanguard::comm(), color, world_rank, &new_comm);
isSimulationRank_ = (world_rank > 0);
EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>(new_comm));
}
#endif // HAVE_MPI
#endif // DEMONSTRATE_RUN_WITH_NONWORLD_COMM
}
int runDynamic()
{
int exitCode = EXIT_SUCCESS;
if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
return dispatchDynamic_();
} else {
return exitCode;
if (isSimulationRank_) {
if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
return dispatchDynamic_();
}
}
return exitCode;
}
template <class TypeTag>
int runStatic()
{
int exitCode = EXIT_SUCCESS;
if (initialize_<TypeTag>(exitCode)) {
return dispatchStatic_<TypeTag>();
} else {
return exitCode;
if (isSimulationRank_) {
if (initialize_<TypeTag>(exitCode)) {
return dispatchStatic_<TypeTag>();
}
}
return exitCode;
}
// To be called from the Python interface code. Only do the
@@ -388,7 +422,7 @@ namespace Opm
using PreProblem = GetPropType<PreTypeTag, Properties::Problem>;
PreProblem::setBriefDescription("Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
int status = FlowMainEbos<PreTypeTag>::setupParameters_(argc_, argv_);
int status = FlowMainEbos<PreTypeTag>::setupParameters_(argc_, argv_, EclGenericVanguard::comm());
if (status != 0) {
// if setupParameters_ returns a value smaller than 0, there was no error, but
// the program should abort. This is the case e.g. for the --help and the
@@ -433,7 +467,7 @@ namespace Opm
return false;
}
if (outputCout_) {
FlowMainEbos<PreTypeTag>::printBanner();
FlowMainEbos<PreTypeTag>::printBanner(EclGenericVanguard::comm());
}
// Create Deck and EclipseState.
try {
@@ -466,7 +500,7 @@ namespace Opm
if (output_param >= 0)
outputInterval = output_param;
readDeck(mpiRank, deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_,
readDeck(EclGenericVanguard::comm(), deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_,
summaryConfig_, nullptr, python, std::move(parseContext),
init_from_restart_file, outputCout_, outputInterval);
@@ -552,6 +586,8 @@ namespace Opm
std::shared_ptr<EclipseState> eclipseState_;
std::shared_ptr<Schedule> schedule_;
std::shared_ptr<SummaryConfig> summaryConfig_;
// To demonstrate run with non_world_comm
bool isSimulationRank_ = true;
};
} // namespace Opm