[bugfix] Make sure MPI_FInalize is called before the return in main.

A correct MPI program should do that.

As MPI_Finalize is part of the destructor of MainObject we need to
make sure that it's destructor is called before the return statement.
We do that manually  by resetting the unique_ptr that we now use to
store the MainObject,
This commit is contained in:
Markus Blatt 2023-07-19 13:20:03 +02:00
parent 7551229e77
commit 859e00254e
34 changed files with 170 additions and 68 deletions

View File

@ -25,7 +25,10 @@
int main(int argc, char** argv)
{
auto mainObject = Opm::Main(argc, argv);
return mainObject.runDynamic();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runDynamic();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}

View File

@ -35,6 +35,9 @@ struct EclEnableAquifers<TypeTag, TTag::EclFlowProblemAlugrid> {
int main(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::EclFlowProblemAlugrid;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}

View File

@ -60,8 +60,11 @@ std::vector<int> loadBalanceInZOnly(const Dune::CpGrid& grid)
int main(int argc, char** argv)
{
auto mainObject = Opm::Main(argc, argv);
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
Opm::EclCpGridVanguard<Opm::Properties::TTag::EclFlowProblem>::setExternalLoadBalancer(loadBalanceInZOnly);
return mainObject.runDynamic();
auto ret = mainObject->runDynamic();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}

View File

@ -70,8 +70,11 @@ int flowEbosBlackoilTpfaMain(int argc, char** argv, bool outputCout, bool output
int flowEbosBlackoilTpfaMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowProblemTPFA;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
} // namespace Opm

View File

@ -45,8 +45,11 @@ int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFile
int flowEbosBlackoilMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -31,8 +31,11 @@ namespace Properties {
int flowEbosBlackoilPolyMain(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::EclFlowProblemPoly;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosBrineMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosBrineMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowBrineProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -37,8 +37,11 @@ struct EnableEnergy<TypeTag, TTag::EclFlowBrineProblem> {
int flowEbosBrineEnergyMain(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::EclFlowBrineProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -63,8 +63,11 @@ int flowEbosBrinePrecsaltVapwatMain(int argc, char** argv, bool outputCout, bool
int flowEbosBrinePrecsaltVapwatMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowBrinePrecsaltVapwatProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -58,8 +58,11 @@ int flowEbosBrineSaltPrecipitationMain(int argc, char** argv, bool outputCout, b
int flowEbosBrineSaltPrecipitationMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowBrineSaltPrecipitationProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosEnergyMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosEnergyMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowEnergyProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosExtboMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosExtboMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowExtboProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosFoamMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosFoamMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowFoamProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -86,8 +86,11 @@ int flowEbosGasOilMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosGasOilMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasOilProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -78,8 +78,11 @@ int flowEbosGasOilEnergyMain(int argc, char** argv, bool outputCout, bool output
int flowEbosGasOilEnergyMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasOilEnergyProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -78,8 +78,11 @@ int flowEbosGasOilDiffuseMain(int argc, char** argv, bool outputCout, bool outpu
int flowEbosGasOilDiffuseMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasOilDiffuseProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -90,8 +90,11 @@ int flowEbosGasWaterMain(int argc, char** argv, bool outputCout, bool outputFile
int flowEbosGasWaterMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -77,8 +77,11 @@ int flowEbosGasWaterBrineMain(int argc, char** argv, bool outputCout, bool outpu
int flowEbosGasWaterBrineMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterBrineProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -100,8 +100,11 @@ int flowEbosGasWaterDissolutionMain(int argc, char** argv, bool outputCout, bool
int flowEbosGasWaterDissolutionMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterDissolutionProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -100,8 +100,11 @@ int flowEbosGasWaterDissolutionDiffuseMain(int argc, char** argv, bool outputCou
int flowEbosGasWaterDissolutionDiffuseMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterDissolutionDiffuseProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -105,8 +105,11 @@ int flowEbosGasWaterEnergyMain(int argc, char** argv, bool outputCout, bool outp
int flowEbosGasWaterEnergyMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterEnergyProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -98,8 +98,11 @@ int flowEbosGasWaterSaltprecEnergyMain(int argc, char** argv, bool outputCout, b
int flowEbosGasWaterSaltprecEnergyMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterSaltprecEnergyProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -93,8 +93,11 @@ int flowEbosGasWaterSaltprecVapwatMain(int argc, char** argv, bool outputCout, b
int flowEbosGasWaterSaltprecVapwatMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterSaltprecVapwatProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -83,8 +83,11 @@ int flowEbosGasWaterSolventMain(int argc, char** argv, bool outputCout, bool out
int flowEbosGasWaterSolventMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowGasWaterSolventProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -77,8 +77,11 @@ int flowEbosMICPMain(int argc, char** argv, bool outputCout, bool outputFiles)
int flowEbosMICPMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowMICPProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -89,8 +89,11 @@ int flowEbosOilWaterMain(int argc, char** argv, bool outputCout, bool outputFile
int flowEbosOilWaterMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowOilWaterProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -77,8 +77,11 @@ int flowEbosOilWaterBrineMain(int argc, char** argv, bool outputCout, bool outpu
int flowEbosOilWaterBrineMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowOilWaterBrineProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -77,8 +77,11 @@ int flowEbosOilWaterPolymerMain(int argc, char** argv, bool outputCout, bool out
int flowEbosOilWaterPolymerMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowOilWaterPolymerProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -90,8 +90,11 @@ int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv, bool outputCou
int flowEbosOilWaterPolymerInjectivityMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowOilWaterPolymerInjectivityProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -84,8 +84,11 @@ int flowEbosWaterOnlyMain(int argc, char** argv, bool outputCout, bool outputFil
int flowEbosWaterOnlyMainStandalone(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::EclFlowProblemWaterOnly;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -79,8 +79,11 @@ int flowEbosWaterOnlyEnergyMain(int argc, char** argv, bool outputCout, bool out
int flowEbosWaterOnlyEnergyMainStandalone(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::EclFlowProblemWaterOnlyEnergy;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles
int flowEbosPolymerMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowPolymerProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -53,8 +53,11 @@ int flowEbosSolventMain(int argc, char** argv, bool outputCout, bool outputFiles
int flowEbosSolventMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowSolventProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}

View File

@ -58,8 +58,11 @@ int flowEbosSolventFoamMain(int argc, char** argv, bool outputCout, bool outputF
int flowEbosSolventFoamMainStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::EclFlowSolventFoamProblem;
auto mainObject = Opm::Main(argc, argv);
return mainObject.runStatic<TypeTag>();
auto mainObject = std::make_unique<Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}
}