Merge pull request #2650 from blattms/prevent-deadlock-after-parsing

Prevent deadlock after parsing if there were error in parallel
This commit is contained in:
Markus Blatt 2020-06-04 12:24:44 +02:00 committed by GitHub
commit c57a901e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -293,6 +293,10 @@ namespace Opm
return Opm::flowEbosMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
}
/// \brief Initialize
/// \param exitCode The exitCode of the program.
/// \return Whether to actually run the simulator. I.e. true if parsing of command line
/// was successful and no --help, --print-properties, or --print-parameters have been found.
template <class TypeTagEarlyBird>
bool initialize_(int& exitCode)
{
@ -333,10 +337,13 @@ namespace Opm
// the program should abort. This is the case e.g. for the --help and the
// --print-properties parameters.
#if HAVE_MPI
MPI_Finalize();
if (status < 0)
MPI_Finalize(); // graceful stop for --help or --print-properties command line.
else
MPI_Abort(MPI_COMM_WORLD, status);
#endif
exitCode = (status >= 0) ? status : EXIT_SUCCESS;
return false;
exitCode = (status > 0) ? status : EXIT_SUCCESS;
return false; // Whether to run the simulator
}
FileOutputMode outputMode = FileOutputMode::OUTPUT_NONE;
@ -363,7 +370,7 @@ namespace Opm
std::cerr << "Exception received: " << e.what() << ". Try '--help' for a usage description.\n";
}
#if HAVE_MPI
MPI_Finalize();
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
#endif
exitCode = EXIT_FAILURE;
return false;
@ -398,42 +405,53 @@ namespace Opm
Opm::FlowMainEbos<PreTypeTag>::printPRTHeader(outputCout_);
if (mpiRank == 0) {
if (!deck_)
deck_.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
Opm::MissingFeatures::checkKeywords(*deck_, parseContext, errorGuard);
if ( outputCout_ )
Opm::checkDeck(*deck_, parser, parseContext, errorGuard);
int parseSuccess = 0;
std::string failureMessage;
if (!eclipseState_) {
if (mpiRank == 0) {
try
{
if (!deck_)
deck_.reset( new Opm::Deck( parser.parseFile(deckFilename , parseContext, errorGuard)));
Opm::MissingFeatures::checkKeywords(*deck_, parseContext, errorGuard);
if ( outputCout_ )
Opm::checkDeck(*deck_, parser, parseContext, errorGuard);
if (!eclipseState_) {
#if HAVE_MPI
eclipseState_.reset(new Opm::ParallelEclipseState(*deck_));
eclipseState_.reset(new Opm::ParallelEclipseState(*deck_));
#else
eclipseState_.reset(new Opm::EclipseState(*deck_));
eclipseState_.reset(new Opm::EclipseState(*deck_));
#endif
}
/*
For the time being initializing wells and groups from the
restart file is not possible, but work is underways and it is
included here as a switch.
*/
const bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag, bool, SchedRestart);
const auto& init_config = eclipseState_->getInitConfig();
if (init_config.restartRequested() && init_from_restart_file) {
int report_step = init_config.getRestartStep();
const auto& rst_filename = eclipseState_->getIOConfig().getRestartFileName( init_config.getRestartRootName(), report_step, false );
Opm::EclIO::ERst rst_file(rst_filename);
const auto& rst_state = Opm::RestartIO::RstState::load(rst_file, report_step);
if (!schedule_)
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python, &rst_state) );
}
else {
if (!schedule_)
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
}
setupMessageLimiter_(schedule_->getMessageLimits(), "STDOUT_LOGGER");
if (!summaryConfig_)
summaryConfig_.reset( new Opm::SummaryConfig(*deck_, *schedule_, eclipseState_->getTableManager(), parseContext, errorGuard));
parseSuccess = 1;
}
/*
For the time being initializing wells and groups from the
restart file is not possible, but work is underways and it is
included here as a switch.
*/
const bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag, bool, SchedRestart);
const auto& init_config = eclipseState_->getInitConfig();
if (init_config.restartRequested() && init_from_restart_file) {
int report_step = init_config.getRestartStep();
const auto& rst_filename = eclipseState_->getIOConfig().getRestartFileName( init_config.getRestartRootName(), report_step, false );
Opm::EclIO::ERst rst_file(rst_filename);
const auto& rst_state = Opm::RestartIO::RstState::load(rst_file, report_step);
if (!schedule_)
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python, &rst_state) );
catch(const std::exception& e)
{
failureMessage = e.what();
}
else {
if (!schedule_)
schedule_.reset(new Opm::Schedule(*deck_, *eclipseState_, parseContext, errorGuard, python));
}
setupMessageLimiter_(schedule_->getMessageLimits(), "STDOUT_LOGGER");
if (!summaryConfig_)
summaryConfig_.reset( new Opm::SummaryConfig(*deck_, *schedule_, eclipseState_->getTableManager(), parseContext, errorGuard));
}
#if HAVE_MPI
else {
@ -444,6 +462,18 @@ namespace Opm
if (!eclipseState_)
eclipseState_.reset(new Opm::ParallelEclipseState);
}
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
@ -465,6 +495,9 @@ namespace Opm
std::cerr << "Failed to create valid EclipseState object." << std::endl;
std::cerr << "Exception caught: " << e.what() << std::endl;
}
#if HAVE_MPI
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
#endif
exitCode = EXIT_FAILURE;
return false;
}