diff --git a/flow/flow.cpp b/flow/flow.cpp index 58bc9b12d..cf0ba776b 100644 --- a/flow/flow.cpp +++ b/flow/flow.cpp @@ -278,11 +278,15 @@ int main(int argc, char** argv) PreProblem::setBriefDescription("Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project."); int status = Opm::FlowMainEbos::setupParameters_(argc, argv); - if (status != 0) + if (status != 0) { // if setupParameters_ returns a value smaller than 0, there was no error, but // the program should abort. This is the case e.g. for the --help and the // --print-properties parameters. +#if HAVE_MPI + MPI_Finalize(); +#endif return (status >= 0)?status:0; + } FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE; bool outputCout = false; diff --git a/opm/simulators/flow/FlowMainEbos.hpp b/opm/simulators/flow/FlowMainEbos.hpp index 799308550..ce752eae7 100644 --- a/opm/simulators/flow/FlowMainEbos.hpp +++ b/opm/simulators/flow/FlowMainEbos.hpp @@ -150,14 +150,45 @@ namespace Opm // read in the command line parameters int status = Opm::setupParameters_(argc, const_cast(argv), /*doRegistration=*/false, /*allowUnused=*/true, /*handleHelp=*/true); if (status == 0) { - // deal with --print-properties and --print-parameters - - bool doExit = false; int mpiRank = 0; #if HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank); #endif + + // deal with unknown parameters. + + int unknownKeyWords = 0; + if (mpiRank == 0) { + unknownKeyWords = Opm::Parameters::printUnused(std::cerr); + } +#if HAVE_MPI + int globalUnknownKeyWords; + MPI_Allreduce(&unknownKeyWords, &globalUnknownKeyWords, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + unknownKeyWords = globalUnknownKeyWords; +#endif + if ( unknownKeyWords ) + { + if ( mpiRank == 0 ) + { + std::string msg = "Aborting simulation due to unknown " + "parameters. Please query \"flow --help\" for " + "supported command line parameters."; + if (OpmLog::hasBackend("STREAMLOG")) + { + OpmLog::error(msg); + } + else { + std::cerr << msg << std::endl; + } + } + return EXIT_FAILURE; + } + + // deal with --print-properties and --print-parameters and unknown parameters. + + bool doExit = false; + if (EWOMS_GET_PARAM(TypeTag, int, PrintProperties) == 1) { doExit = true; if (mpiRank == 0) @@ -209,33 +240,7 @@ namespace Opm setupParallelism(); setupEbosSimulator(output_cout); - int unknownKeyWords = printPRTHeader(output_cout); -#if HAVE_MPI - int globalUnknownKeyWords; - MPI_Allreduce(&unknownKeyWords, &globalUnknownKeyWords, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - unknownKeyWords = globalUnknownKeyWords; -#endif - if ( unknownKeyWords ) - { - if ( output_cout ) - { - std::string msg = "Aborting simulation due to unknown " - "parameters. Please query \"flow --help\" for " - "supported command line parameters."; - if (OpmLog::hasBackend("STREAMLOG")) - { - OpmLog::error(msg); - } - else { - std::cerr << msg << std::endl; - } - } - -#if HAVE_MPI - MPI_Finalize(); -#endif - return EXIT_FAILURE; - } + printPRTHeader(output_cout); runDiagnostics(output_cout); createSimulator(); @@ -290,10 +295,9 @@ namespace Opm ThreadManager::init(); } - // Print an ASCII-art header to the PRT and DEBUG files. // \return Whether unkown keywords were seen during parsing. - bool printPRTHeader(bool output_cout) + void printPRTHeader(bool output_cout) { if (output_cout) { const std::string version = moduleVersion(); @@ -333,15 +337,6 @@ namespace Opm OpmLog::note(ss.str()); } - - if ( mpi_rank_ == 0 ) - { - return Opm::Parameters::printUnused(std::cerr); - } - else - { - return false; - } } void mergeParallelLogFiles(bool output_to_files)