mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Add and use gatherStrings() for exception messages.
Ensures user sees any useful exception messages during initialization.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <opm/models/utils/propertysystem.hh>
|
||||
#include <opm/models/utils/timer.hh>
|
||||
#include <opm/models/utils/timerguard.hh>
|
||||
#include <opm/models/parallel/mpiutil.hh>
|
||||
|
||||
#include <dune/common/version.hh>
|
||||
#include <dune/common/parallel/mpihelper.hh>
|
||||
@@ -147,16 +148,24 @@ public:
|
||||
std::cout << "Allocating the simulation vanguard\n" << std::flush;
|
||||
|
||||
int exceptionThrown = 0;
|
||||
std::string what;
|
||||
try
|
||||
{ vanguard_.reset(new Vanguard(*this)); }
|
||||
catch (const std::exception& e) {
|
||||
exceptionThrown = 1;
|
||||
what = e.what();
|
||||
if (comm.size() > 1) {
|
||||
what += " (on rank " + std::to_string(comm.rank()) + ")";
|
||||
}
|
||||
if (verbose_)
|
||||
std::cerr << "Rank " << comm.rank() << " threw an exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (comm.max(exceptionThrown))
|
||||
throw std::runtime_error("Allocating the simulation vanguard failed.");
|
||||
if (comm.max(exceptionThrown)) {
|
||||
auto all_what = gatherStrings(what);
|
||||
assert(!all_what.empty());
|
||||
throw std::runtime_error("Allocating the simulation vanguard failed: " + all_what.front());
|
||||
}
|
||||
|
||||
if (verbose_)
|
||||
std::cout << "Distributing the vanguard's data\n" << std::flush;
|
||||
@@ -165,12 +174,19 @@ public:
|
||||
{ vanguard_->loadBalance(); }
|
||||
catch (const std::exception& e) {
|
||||
exceptionThrown = 1;
|
||||
what = e.what();
|
||||
if (comm.size() > 1) {
|
||||
what += " (on rank " + std::to_string(comm.rank()) + ")";
|
||||
}
|
||||
if (verbose_)
|
||||
std::cerr << "Rank " << comm.rank() << " threw an exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (comm.max(exceptionThrown))
|
||||
throw std::runtime_error("Could not distribute the vanguard data.");
|
||||
if (comm.max(exceptionThrown)) {
|
||||
auto all_what = gatherStrings(what);
|
||||
assert(!all_what.empty());
|
||||
throw std::runtime_error("Could not distribute the vanguard data: " + all_what.front());
|
||||
}
|
||||
|
||||
if (verbose_)
|
||||
std::cout << "Allocating the model\n" << std::flush;
|
||||
@@ -187,12 +203,19 @@ public:
|
||||
{ model_->finishInit(); }
|
||||
catch (const std::exception& e) {
|
||||
exceptionThrown = 1;
|
||||
what = e.what();
|
||||
if (comm.size() > 1) {
|
||||
what += " (on rank " + std::to_string(comm.rank()) + ")";
|
||||
}
|
||||
if (verbose_)
|
||||
std::cerr << "Rank " << comm.rank() << " threw an exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (comm.max(exceptionThrown))
|
||||
throw std::runtime_error("Could not initialize the model.");
|
||||
if (comm.max(exceptionThrown)) {
|
||||
auto all_what = gatherStrings(what);
|
||||
assert(!all_what.empty());
|
||||
throw std::runtime_error("Could not initialize the model: " + all_what.front());
|
||||
}
|
||||
|
||||
if (verbose_)
|
||||
std::cout << "Initializing the problem\n" << std::flush;
|
||||
@@ -201,12 +224,19 @@ public:
|
||||
{ problem_->finishInit(); }
|
||||
catch (const std::exception& e) {
|
||||
exceptionThrown = 1;
|
||||
what = e.what();
|
||||
if (comm.size() > 1) {
|
||||
what += " (on rank " + std::to_string(comm.rank()) + ")";
|
||||
}
|
||||
if (verbose_)
|
||||
std::cerr << "Rank " << comm.rank() << " threw an exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (comm.max(exceptionThrown))
|
||||
throw std::runtime_error("Could not initialize the problem.");
|
||||
if (comm.max(exceptionThrown)) {
|
||||
auto all_what = gatherStrings(what);
|
||||
assert(!all_what.empty());
|
||||
throw std::runtime_error("Could not initialize the problem: " + all_what.front());
|
||||
}
|
||||
|
||||
setupTimer_.stop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user