Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error and abort in CollectiveMutex during stack unwinding #14356

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions source/base/mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,46 @@ namespace Utilities



namespace internal
{
namespace CollectiveMutexImplementation
{
/**
* Abort, should there be an exception being processed (see the error
* message).
*/
void
check_exception()
{
#ifdef DEAL_II_WITH_MPI
# if __cpp_lib_uncaught_exceptions >= 201411
// std::uncaught_exception() is deprecated in c++17
if (std::uncaught_exceptions() != 0)
# else
if (std::uncaught_exception() == true)
# endif
{
std::cerr
<< "---------------------------------------------------------\n"
<< "An exception was thrown inside a section of the program\n"
<< "guarded by a CollectiveMutex.\n"
<< "Because a CollectiveMutex guards critical communication\n"
<< "handling the exception would likely\n"
<< "deadlock because only the current process is aware of the\n"
<< "exception. To prevent this deadlock, the program will be\n"
<< "aborted.\n"
<< "---------------------------------------------------------"
<< std::endl;

MPI_Abort(MPI_COMM_WORLD, 1);
}
#endif
}
} // namespace CollectiveMutexImplementation
} // namespace internal



CollectiveMutex::CollectiveMutex()
: locked(false)
, request(MPI_REQUEST_NULL)
Expand All @@ -1089,6 +1129,10 @@ namespace Utilities

CollectiveMutex::~CollectiveMutex()
{
// First check if this destructor is called during exception handling
// if so, abort.
internal::CollectiveMutexImplementation::check_exception();

Assert(
!locked,
ExcMessage(
Expand Down Expand Up @@ -1138,6 +1182,10 @@ namespace Utilities
{
(void)comm;

// First check if this function is called during exception handling
// if so, abort. This can happen if a ScopedLock is destroyed.
internal::CollectiveMutexImplementation::check_exception();

Assert(
locked,
ExcMessage(
Expand Down