Allow Python bindings to setup MPI

Allows the Python bindings to control whether MPI_Init() and
MPI_Finalize() will be called when creating an OPM::Main object.
This commit is contained in:
Håkon Hægland
2024-05-01 11:04:36 +02:00
parent 9529c18235
commit a1b7d4b5dd
9 changed files with 85 additions and 10 deletions

View File

@@ -171,6 +171,15 @@ setPrimaryVariable(
getFluidState().setPrimaryVariable(variable, data, size_);
}
void PyBlackOilSimulator::setupMpi(bool mpi_init, bool mpi_finalize)
{
if (this->has_run_init_) {
throw std::logic_error("mpi_init() called after step_init()");
}
this->mpi_init_ = mpi_init;
this->mpi_finalize_ = mpi_finalize;
}
int PyBlackOilSimulator::step()
{
if (!this->has_run_init_) {
@@ -211,11 +220,17 @@ int PyBlackOilSimulator::stepInit()
this->deck_->getDataFile(),
this->eclipse_state_,
this->schedule_,
this->summary_config_
this->summary_config_,
this->mpi_init_,
this->mpi_finalize_
);
}
else {
this->main_ = std::make_unique<Opm::Main>( this->deck_filename_ );
this->main_ = std::make_unique<Opm::Main>(
this->deck_filename_,
this->mpi_init_,
this->mpi_finalize_
);
}
int exit_code = EXIT_SUCCESS;
this->flow_main_ = this->main_->initFlowBlackoil(exit_code);
@@ -305,6 +320,7 @@ void export_PyBlackOilSimulator(py::module& m)
.def("set_porosity", &PyBlackOilSimulator::setPorosity, setPorosity_docstring, py::arg("array"))
.def("set_primary_variable", &PyBlackOilSimulator::setPrimaryVariable,
py::arg("variable"), py::arg("value"))
.def("setup_mpi", &PyBlackOilSimulator::setupMpi, setupMpi_docstring, py::arg("init"), py::arg("finalize"))
.def("step", &PyBlackOilSimulator::step, step_docstring)
.def("step_cleanup", &PyBlackOilSimulator::stepCleanup, stepCleanup_docstring)
.def("step_init", &PyBlackOilSimulator::stepInit, stepInit_docstring);