From 28cadec77b5e2594f6785bb4ece5f627b75d9272 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 16 Sep 2013 17:10:11 +0200 Subject: [PATCH] fixed: enable running upscale_elasticity compiled against MPI enabled libraries make sure to call MPI_Init/MPI_Finalize. the code still does not support MPI parallelization in any way, so it halts if MPI_COMM_WORLD size is > 1. --- examples/upscale_elasticity.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/upscale_elasticity.cpp b/examples/upscale_elasticity.cpp index 17c29d5..88fb994 100644 --- a/examples/upscale_elasticity.cpp +++ b/examples/upscale_elasticity.cpp @@ -25,6 +25,10 @@ #include #endif +#ifdef HAVE_MPI +#include +#endif + #include #include @@ -211,11 +215,29 @@ void writeOutput(const Params& p, Opm::time::StopWatch& watch, int cells, << C << std::endl; } +void shutdown() +{ +#ifdef HAVE_MPI + MPI_Finalize(); +#endif +} + //! \brief Main driver int main(int argc, char** argv) try { try { +#ifdef HAVE_MPI + int rank, size; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size != 1) { + std::cerr << "This program does not support MPI parallelization" << std::endl; + shutdown(); + return 2; + } +#endif static const int dim = 3; typedef Dune::CpGrid GridType; @@ -224,6 +246,7 @@ try || strcmp(argv[1],"--help") == 0 || strcmp(argv[1],"-?") == 0) { syntax(argv); + shutdown(); exit(1); } Params p; @@ -337,6 +360,7 @@ try writeOutput(p,watch,grid.size(0),upscale.volumeFractions,C); } + shutdown(); return 0; } catch (Dune::Exception &e) { @@ -345,10 +369,12 @@ try catch (...) { std::cerr << "Unknown exception thrown!" << std::endl; } + shutdown(); return 1; } catch (const std::exception &e) { std::cerr << "Program threw an exception: " << e.what() << "\n"; + shutdown(); throw; }