diff --git a/CMakeLists.txt b/CMakeLists.txt index e911f13..3dc023b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ include (${project}-prereqs) include (CMakeLists_files.cmake) macro (config_hook) - # opm_need_version_of ("dune-common") + opm_need_version_of ("dune-common") list (APPEND ${project}_CONFIG_IMPL_VARS HAVE_LAPACK ) diff --git a/examples/cpchop.cpp b/examples/cpchop.cpp index db06779..4ff9fbe 100644 --- a/examples/cpchop.cpp +++ b/examples/cpchop.cpp @@ -40,17 +40,13 @@ #include #include -#ifdef HAVE_MPI -#include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include #endif -void shutdown() -{ -#ifdef HAVE_MPI - MPI_Finalize(); -#endif -} - int main(int argc, char** argv) try { @@ -63,9 +59,8 @@ try std::cout << " [rock_list=] [anisotropicrocks=false]" << std::endl; exit(1); } -#ifdef HAVE_MPI - MPI_Init(&argc, &argv); -#endif + + Dune::MPIHelper::instance(argc, argv); Opm::parameter::ParameterGroup param(argc, argv); std::string gridfilename = param.get("gridfilename"); @@ -165,7 +160,6 @@ try catch (const char * errormessage) { std::cerr << "Error: " << errormessage << std::endl; std::cerr << "Check filename" << std::endl; - shutdown(); exit(1); } @@ -175,7 +169,6 @@ try } else { std::cerr << "Error: Jfunction " << i+1 << " in rock file " << rockname << " was not invertible." << std::endl; - shutdown(); exit(1); } @@ -196,7 +189,6 @@ try catch (const char * errormessage) { std::cerr << "Error: " << errormessage << std::endl; std::cerr << "Check filename and columns 1 and 2 (Pc and Sw)" << std::endl; - shutdown(); exit(1); } if (cappres) { @@ -206,7 +198,6 @@ try } else { std::cerr << "Error: Pc(Sw) curve " << i+1 << " in rock file " << rockname << " was not invertible." << std::endl; - shutdown(); exit(1); } } @@ -660,11 +651,9 @@ try std::cout << outputtmp.str(); - shutdown(); } catch (const std::exception &e) { std::cerr << "Program threw an exception: " << e.what() << "\n"; - shutdown(); throw; } diff --git a/examples/cpchop_depthtrend.cpp b/examples/cpchop_depthtrend.cpp index 4784fe9..b3fc28c 100644 --- a/examples/cpchop_depthtrend.cpp +++ b/examples/cpchop_depthtrend.cpp @@ -38,6 +38,13 @@ #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + /** This program is a variant of cpchop. Instead of subsampling randomly, it picks subsamples downwards in a model. It is specifically designed @@ -60,6 +67,8 @@ try exit(1); } + Dune::MPIHelper::instance(argc, argv); + Opm::parameter::ParameterGroup param(argc, argv); std::string gridfilename = param.get("gridfilename"); Opm::CornerPointChopper ch(gridfilename); diff --git a/examples/cpregularize.cpp b/examples/cpregularize.cpp index 72874ab..ce137f9 100644 --- a/examples/cpregularize.cpp +++ b/examples/cpregularize.cpp @@ -49,6 +49,12 @@ #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif int main(int argc, char** argv) try @@ -60,6 +66,8 @@ try std::cout << " [resultgrid=regularizedgrid.grdecl]" << std::endl; exit(1); } + + Dune::MPIHelper::instance(argc, argv); Opm::parameter::ParameterGroup param(argc, argv); std::string gridfilename = param.get("gridfilename"); diff --git a/examples/exp_variogram.cpp b/examples/exp_variogram.cpp index 7cc35d6..91f3215 100644 --- a/examples/exp_variogram.cpp +++ b/examples/exp_variogram.cpp @@ -50,10 +50,18 @@ #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif int main(int argc, char** argv) try { + Dune::MPIHelper::instance(argc, argv); + Opm::parameter::ParameterGroup param(argc, argv); std::string gridfilename = param.get("gridfilename"); Opm::CornerPointChopper ch(gridfilename); diff --git a/examples/grdecldips.cpp b/examples/grdecldips.cpp index d63adf1..b3a68a5 100644 --- a/examples/grdecldips.cpp +++ b/examples/grdecldips.cpp @@ -38,7 +38,12 @@ #include #include - +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif using namespace std; @@ -49,6 +54,9 @@ int main(int argc, char** argv) try { cout << " [listallcells=false] [output=filename.txt]" << endl; exit(1); } + + Dune::MPIHelper::instance(argc, argv); + Opm::parameter::ParameterGroup param(argc, argv); std::string gridfilename = param.get("gridfilename"); diff --git a/examples/steadystate_test_implicit.cpp b/examples/steadystate_test_implicit.cpp index 02ff20b..cf30ca8 100644 --- a/examples/steadystate_test_implicit.cpp +++ b/examples/steadystate_test_implicit.cpp @@ -42,6 +42,14 @@ #include #include #include + +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + namespace Opm{ template struct Implicit @@ -66,6 +74,8 @@ using namespace Opm; int main(int argc, char** argv) try { + Dune::MPIHelper::instance(argc, argv); + // Initialize. Opm::parameter::ParameterGroup param(argc, argv); // MPIHelper::instance(argc,argv) ; diff --git a/examples/upscale_avg.cpp b/examples/upscale_avg.cpp index 81ae917..d8f35c1 100644 --- a/examples/upscale_avg.cpp +++ b/examples/upscale_avg.cpp @@ -52,6 +52,13 @@ #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + using namespace Opm; using namespace std; @@ -73,6 +80,8 @@ void usageandexit() { */ int main(int varnum, char** vararg) try { + Dune::MPIHelper::instance(varnum, vararg); + const double emptycellvolumecutoff = 1e-10; bool anisotropic_input = false; diff --git a/examples/upscale_cap.cpp b/examples/upscale_cap.cpp index a09b8a0..36a36d0 100644 --- a/examples/upscale_cap.cpp +++ b/examples/upscale_cap.cpp @@ -67,6 +67,13 @@ #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + using namespace Opm; using namespace std; @@ -118,6 +125,8 @@ try * Process command line options */ + Dune::MPIHelper::instance(varnum, vararg); + if (varnum == 1) { /* If no arguments supplied ("upscale_cap" is the first ('zero') "argument") */ usage(); exit(1); diff --git a/examples/upscale_cond.cpp b/examples/upscale_cond.cpp index c13124a..105a152 100644 --- a/examples/upscale_cond.cpp +++ b/examples/upscale_cond.cpp @@ -61,8 +61,11 @@ #include #include -#ifdef USEMPI -#include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include #endif #include @@ -122,9 +125,6 @@ void usage() void usageandexit() { usage(); -#ifdef USEMPI - MPI_Finalize(); -#endif exit(1); } // Assumes that permtensor_t use C ordering. @@ -176,14 +176,8 @@ try double timeused = 0, timeused_tesselation = 0; double timeused_upscale_wallclock = 0.0; - - int mpi_rank = 0; -#ifdef USEMPI - int mpi_nodecount = 1; - MPI_Init(&varnum, &vararg); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_nodecount); -#endif + Dune::MPIHelper& mpi=Dune::MPIHelper::instance(varnum, vararg); + const int mpi_rank = mpi.rank(); bool isMaster = (mpi_rank == 0); if (varnum == 1) { /* If no arguments supplied ("upscale_cond" is the first "argument") */ usageandexit(); @@ -819,7 +813,7 @@ try node_vs_pressurepoint.push_back(0); } -#if USEMPI +#ifdef HAVE_MPI // Distribute work load over mpi nodes. for (int idx=0; idx < points; ++idx) { // Ensure master node gets equal or less work than the other nodes, since @@ -930,7 +924,7 @@ try //timeused_upscale_acc += timeused; // Output computed values for impatient users.. -#ifdef USEMPI +#ifdef HAVE_MPI cout << "Rank " << mpi_rank << ": "; #endif cout << Ptestvalue << "\t" << waterVolumeLF/poreVolume; @@ -946,7 +940,7 @@ try /****** FINISHED WITH MAIN COMPUTATION ******/ -#ifdef USEMPI +#ifdef HAVE_MPI /* Step 7b: Transfer all computed data to master node. Master node should post a receive for all values missing, other nodes should post a send for all the values they have. @@ -986,7 +980,7 @@ try // Average time pr. upscaling point: -#ifdef USEMPI +#ifdef HAVE_MPI // Sum the upscaling time used by all processes double timeused_total; MPI_Reduce(&timeused_upscale_wallclock, &timeused_total, 1, MPI_DOUBLE, @@ -1014,7 +1008,7 @@ try outputtmp << "######################################################################" << endl; outputtmp << "# Results from upscaling resistivity."<< endl; outputtmp << "#" << endl; -#if USEMPI +#ifdef HAVE_MPI outputtmp << "# (MPI-version)" << endl; #endif time_t now = std::time(NULL); @@ -1037,7 +1031,7 @@ try outputtmp << "#" << endl; outputtmp << "# Timings: Tesselation: " << timeused_tesselation << " secs" << endl; outputtmp << "# Upscaling: " << timeused_upscale_wallclock << " secs"; -#ifdef USEMPI +#ifdef HAVE_MPI outputtmp << " (wallclock time)" << endl; outputtmp << "# " << avg_upscaling_time_pr_point << " secs pr. saturation point" << endl; outputtmp << "# MPI-nodes: " << mpi_nodecount << endl; @@ -1195,9 +1189,6 @@ try outfile.close(); } } -#if USEMPI - MPI_Finalize(); -#endif return 0; } diff --git a/examples/upscale_elasticity.cpp b/examples/upscale_elasticity.cpp index 88fb994..ecf8161 100644 --- a/examples/upscale_elasticity.cpp +++ b/examples/upscale_elasticity.cpp @@ -17,6 +17,7 @@ #include #include #include // We use exceptions +#include #include #include #include @@ -25,8 +26,11 @@ #include #endif -#ifdef HAVE_MPI -#include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include #endif #include @@ -215,29 +219,17 @@ 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 + Dune::MPIHelper& mpi=Dune::MPIHelper::instance(argc, argv); + const int size = mpi.size(); + if (size != 1) { + std::cerr << "This program does not support MPI parallelization" << std::endl; + return 2; + } static const int dim = 3; typedef Dune::CpGrid GridType; @@ -246,7 +238,6 @@ try || strcmp(argv[1],"--help") == 0 || strcmp(argv[1],"-?") == 0) { syntax(argv); - shutdown(); exit(1); } Params p; @@ -360,7 +351,6 @@ try writeOutput(p,watch,grid.size(0),upscale.volumeFractions,C); } - shutdown(); return 0; } catch (Dune::Exception &e) { @@ -369,12 +359,10 @@ 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; } diff --git a/examples/upscale_perm.cpp b/examples/upscale_perm.cpp index d88d377..0d3930c 100644 --- a/examples/upscale_perm.cpp +++ b/examples/upscale_perm.cpp @@ -53,7 +53,13 @@ #include #include + +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else #include +#endif using namespace std; @@ -83,8 +89,7 @@ void usage() { @return int */ int upscale(int varnum, char** vararg) { - Dune::MPIHelper& mpi=Dune::MPIHelper::instance(varnum, vararg); - mpi.rank(); + Dune::MPIHelper::instance(varnum, vararg); if (varnum == 1) { // If no arguments supplied ("upscale_perm" is the first argument) cout << "Error: No eclipsefile provided" << endl; usage(); diff --git a/examples/upscale_relperm.cpp b/examples/upscale_relperm.cpp index 7981102..6ac72b0 100644 --- a/examples/upscale_relperm.cpp +++ b/examples/upscale_relperm.cpp @@ -69,8 +69,11 @@ #include #include -#ifdef HAVE_MPI -#include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include #endif #include @@ -147,9 +150,6 @@ void usage() void usageandexit() { usage(); -#ifdef HAVE_MPI - MPI_Finalize(); -#endif exit(1); } @@ -207,13 +207,11 @@ try * Process command line options */ - int mpi_rank = 0; + Dune::MPIHelper& mpi=Dune::MPIHelper::instance(varnum, vararg); + const int mpi_rank = mpi.rank(); #ifdef HAVE_MPI - int mpi_nodecount = 1; - MPI_Init(&varnum, &vararg); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_nodecount); -#endif + const int mpi_nodecount = mpi.size(); +#endif bool isMaster = (mpi_rank == 0); if (varnum == 1) { /* If no arguments supplied ("upscale_relperm" is the first "argument") */ usage(); @@ -2044,10 +2042,6 @@ try } -#if HAVE_MPI - MPI_Finalize(); -#endif - return 0; } catch (const std::exception &e) { diff --git a/examples/upscale_relpermvisc.cpp b/examples/upscale_relpermvisc.cpp index 106edda..135acb1 100644 --- a/examples/upscale_relpermvisc.cpp +++ b/examples/upscale_relpermvisc.cpp @@ -79,13 +79,16 @@ #include #include -#ifdef USEMPI -#include -#endif - #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + using namespace Opm; using namespace std; @@ -137,9 +140,6 @@ void usage() } void usageandexit() { -#ifdef USEMPI - MPI_Finalize(); -#endif usage(); exit(1); } @@ -198,13 +198,11 @@ try * Process command line options */ - int mpi_rank = 0; -#ifdef USEMPI - int mpi_nodecount = 1; - MPI_Init(&varnum, &vararg); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_nodecount); -#endif + Dune::MPIHelper& mpi=Dune::MPIHelper::instance(varnum, vararg); + const int mpi_rank = mpi.rank(); +#ifdef HAVE_MPI + const int mpi_nodecount = mpi.size(); +#endif bool isMaster = (mpi_rank == 0); if (varnum == 1) { /* If no arguments supplied ("upscale_relpermvisc" is the first "argument") */ usage(); @@ -1220,7 +1218,7 @@ try node_vs_fracflowratiopoint.push_back(0); } -#if USEMPI +#ifdef HAVE_MPI // Distribute work load over mpi nodes. for (int idx=0; idx < points; ++idx) { // Ensure master node gets equal or less work than the other nodes, since @@ -1366,7 +1364,7 @@ try //cout << waterVolumeLF/poreVolume; WaterSaturation[pointidx] = waterVolumeLF/poreVolume; -#ifdef USEMPI +#ifdef HAVE_MPI cout << "Rank " << mpi_rank << ": " << endl;; #endif cout << fracFlowRatioTestvalue << "\t" << WaterSaturation[pointidx]; @@ -1382,7 +1380,7 @@ try clock_t finish_upscale_wallclock = clock(); timeused_upscale_wallclock = (double(finish_upscale_wallclock)-double(start_upscale_wallclock))/CLOCKS_PER_SEC; //double timeused_upscale_total = timeused_upscale_wallclock; -#ifdef USEMPI +#ifdef HAVE_MPI /* Step Xb: Transfer all computed data to master node. Master node should post a receive for all values missing, other nodes should post a send for all the values they have. @@ -1425,7 +1423,7 @@ try #endif // Average time pr. upscaling point: -#ifdef USEMPI +#ifdef HAVE_MPI // Sum the upscaling time used by all processes double timeused_total; MPI_Reduce(&timeused_upscale_wallclock, &timeused_total, 1, MPI_DOUBLE, @@ -1519,7 +1517,7 @@ try outheadtmp << "#" << endl; outheadtmp << "# Timings: Tesselation: " << timeused_tesselation << " secs" << endl; outheadtmp << "# Upscaling: " << timeused_upscale_wallclock << " secs"; -#ifdef USEMPI +#ifdef HAVE_MPI outheadtmp << " (wallclock time)" << endl; outheadtmp << "# " << avg_upscaling_time_pr_point << " secs pr. saturation point" << endl; outheadtmp << "# MPI-nodes: " << mpi_nodecount << endl; @@ -1670,10 +1668,6 @@ try } } -#if USEMPI - MPI_Finalize(); -#endif - return 0; } catch (const std::exception &e) { diff --git a/examples/upscale_singlephase.cpp b/examples/upscale_singlephase.cpp index 807c338..56b9a68 100644 --- a/examples/upscale_singlephase.cpp +++ b/examples/upscale_singlephase.cpp @@ -26,6 +26,13 @@ #include #include +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + using namespace Opm; using namespace Opm::prefix; using namespace Opm::unit; @@ -33,6 +40,8 @@ using namespace Opm::unit; int main(int argc, char** argv) try { + Dune::MPIHelper::instance(argc, argv); + Opm::parameter::ParameterGroup param(argc, argv); // MPIHelper::instance(argc,argv); SinglePhaseUpscaler upscaler; diff --git a/examples/upscale_steadystate_implicit.cpp b/examples/upscale_steadystate_implicit.cpp index 97a9869..2f1606b 100644 --- a/examples/upscale_steadystate_implicit.cpp +++ b/examples/upscale_steadystate_implicit.cpp @@ -43,6 +43,14 @@ #include #include #include + +#include +#if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 3) +#include +#else +#include +#endif + namespace Opm{ template struct Implicit @@ -173,6 +181,8 @@ std::string toString(T const& value) { int main(int argc, char** argv) try { + Dune::MPIHelper::instance(argc, argv); + if (argc == 1) { usageandexit(); }