Merge pull request #81 from akva2/fix_mpi

fixed: enable running upscale_elasticity compiled against MPI enabled li...

Merging directly since this currently breaks building.
This commit is contained in:
Alf Birger Rustad 2013-09-18 04:44:51 -07:00
commit aaaf2183fc

View File

@ -25,6 +25,10 @@
#include <omp.h> #include <omp.h>
#endif #endif
#ifdef HAVE_MPI
#include <mpi.h>
#endif
#include <opm/elasticity/elasticity_upscale.hpp> #include <opm/elasticity/elasticity_upscale.hpp>
#include <opm/elasticity/matrixops.hpp> #include <opm/elasticity/matrixops.hpp>
@ -211,11 +215,29 @@ void writeOutput(const Params& p, Opm::time::StopWatch& watch, int cells,
<< C << std::endl; << C << std::endl;
} }
void shutdown()
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
}
//! \brief Main driver //! \brief Main driver
int main(int argc, char** argv) int main(int argc, char** argv)
try try
{ {
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; static const int dim = 3;
typedef Dune::CpGrid GridType; typedef Dune::CpGrid GridType;
@ -224,6 +246,7 @@ try
|| strcmp(argv[1],"--help") == 0 || strcmp(argv[1],"--help") == 0
|| strcmp(argv[1],"-?") == 0) { || strcmp(argv[1],"-?") == 0) {
syntax(argv); syntax(argv);
shutdown();
exit(1); exit(1);
} }
Params p; Params p;
@ -337,6 +360,7 @@ try
writeOutput(p,watch,grid.size(0),upscale.volumeFractions,C); writeOutput(p,watch,grid.size(0),upscale.volumeFractions,C);
} }
shutdown();
return 0; return 0;
} }
catch (Dune::Exception &e) { catch (Dune::Exception &e) {
@ -345,10 +369,12 @@ try
catch (...) { catch (...) {
std::cerr << "Unknown exception thrown!" << std::endl; std::cerr << "Unknown exception thrown!" << std::endl;
} }
shutdown();
return 1; return 1;
} }
catch (const std::exception &e) { catch (const std::exception &e) {
std::cerr << "Program threw an exception: " << e.what() << "\n"; std::cerr << "Program threw an exception: " << e.what() << "\n";
shutdown();
throw; throw;
} }