27#include <boost/mpi/collectives.hpp>
28#include <boost/serialization/string.hpp>
39void ParallelExceptionHandler::handle_impl(std::exception
const *error)
const {
40 auto const head_node = 0;
43 enum :
unsigned char {
45 SOME_RANK_FAILED = 1u,
46 THIS_RANK_SUCCESS = 0u,
47 THIS_RANK_FAILED = 1u,
48 MAIN_RANK_FAILED = 2u,
50 auto const this_fail_flag =
52 ? ((
this_node == head_node) ? MAIN_RANK_FAILED : THIS_RANK_FAILED)
54 auto const fail_flag = boost::mpi::all_reduce(
55 m_comm,
static_cast<unsigned char>(this_fail_flag), std::bit_or<>());
56 auto const main_rank_failed = fail_flag & MAIN_RANK_FAILED;
57 auto const some_rank_failed = fail_flag & SOME_RANK_FAILED;
59 if (main_rank_failed) {
67 if (some_rank_failed) {
69 std::vector<std::string> messages;
70 std::string this_message{(error) ? error->what() :
""};
71 boost::mpi::gather(m_comm, this_message, messages, head_node);
73 std::string error_message{
"an error occurred on one or more MPI ranks:"};
74 for (std::size_t i = 0; i < messages.size(); ++i) {
75 error_message +=
"\n rank " + std::to_string(i) +
": " + messages[i];
77 throw std::runtime_error(error_message.c_str());
int this_node
The number of this node.
void flush_runtime_errors_local()
Flush runtime errors to standard error on the local node.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...