From 519e4ac0026456afde635e83fb474b24d75e3f7f Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 14 Sep 2020 12:53:02 +0200 Subject: [PATCH] Improves error handling and reporting in parallel. As the ErrorGuard also dumps warnings we now always dump it (previously only on error) to get these messages in the console. If there are error encountered, we log a meaningful error message (the real cause was missing previously) and do a graceful exit after MPI_Finalize. --- opm/simulators/utils/readDeck.cpp | 83 ++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/opm/simulators/utils/readDeck.cpp b/opm/simulators/utils/readDeck.cpp index a103c3277..2da496072 100644 --- a/opm/simulators/utils/readDeck.cpp +++ b/opm/simulators/utils/readDeck.cpp @@ -170,9 +170,7 @@ void readDeck(int rank, std::string& deckFilename, std::unique_ptr& d errorGuard = std::make_unique(); } -#if HAVE_MPI - int parseSuccess = 0; -#endif + int parseSuccess = 1; // > 0 is success std::string failureMessage; if (rank==0) { @@ -223,13 +221,12 @@ void readDeck(int rank, std::string& deckFilename, std::unique_ptr& d } if (!summaryConfig) summaryConfig = std::make_unique(*deck, *schedule, eclipseState->getTableManager(), *parseContext, *errorGuard); -#if HAVE_MPI - parseSuccess = 1; -#endif + } catch(const std::exception& e) { failureMessage = e.what(); + parseSuccess = 0; } } #if HAVE_MPI @@ -241,28 +238,66 @@ void readDeck(int rank, std::string& deckFilename, std::unique_ptr& d if (!eclipseState) eclipseState = std::make_unique(); } - - auto comm = Dune::MPIHelper::getCollectiveCommunication(); - parseSuccess = comm.max(parseSuccess); - if (!parseSuccess) - { - if (*errorGuard) { - errorGuard->dump(); - errorGuard->clear(); - } - MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); - } - - Opm::eclStateBroadcast(*eclipseState, *schedule, *summaryConfig); #endif - Opm::checkConsistentArrayDimensions(*eclipseState, *schedule, *parseContext, *errorGuard); + if (*errorGuard) { // errors encountered + parseSuccess = 0; + } - if (*errorGuard) { - errorGuard->dump(); - errorGuard->clear(); + // print errors and warnings! + errorGuard->dump(); + errorGuard->clear(); - throw std::runtime_error("Unrecoverable errors were encountered while loading input."); + auto comm = Dune::MPIHelper::getCollectiveCommunication(); + parseSuccess = comm.min(parseSuccess); + + if (!parseSuccess) + { + if (rank == 0) + { + OpmLog::error(std::string("Unrecoverable errors were encountered while loading input: ")+failureMessage); + } +#if HAVE_MPI + MPI_Finalize(); +#endif + exit(1); + } + + parseSuccess = 1; + + try + { +#if HAVE_MPI + Opm::eclStateBroadcast(*eclipseState, *schedule, *summaryConfig); +#endif + Opm::checkConsistentArrayDimensions(*eclipseState, *schedule, *parseContext, *errorGuard); + } + catch(const std::exception& e) + { + failureMessage = e.what(); + parseSuccess = 0; + } + + if (*errorGuard) { // errors encountered + parseSuccess = 0; + } + + // Print warnings and erors on every rank! Maybe too much? + errorGuard->dump(); + errorGuard->clear(); + + parseSuccess = comm.min(parseSuccess); + + if (!parseSuccess) + { + if (rank == 0) + { + OpmLog::error(std::string("Unrecoverable errors were encountered while loading input: ")+failureMessage); + } +#if HAVE_MPI + MPI_Finalize(); +#endif + exit(1); } } } // end namespace Opm