]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove communication during stack unwinding.
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 17 Oct 2022 19:17:18 +0000 (15:17 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 17 Oct 2022 19:24:46 +0000 (15:24 -0400)
source/base/mpi.cc

index 33e1160f2252dbb965592afab179d0af68e683f9..605c00fffd7bc71b35219c49679fa2ee98fe9865 100644 (file)
@@ -1143,20 +1143,33 @@ namespace Utilities
         ExcMessage(
           "Error: MPI::CollectiveMutex needs to be locked before unlock()"));
 
+      // Only communicate with other processes if there is no uncaught
+      // exception to avoid a deadlock.
 #ifdef DEAL_II_WITH_MPI
-
-      // TODO: For now, we implement this mutex with a blocking barrier
-      // in the lock and unlock. It needs to be tested, if we can move
-      // to a nonblocking barrier (code disabled below):
+#  if __cpp_lib_uncaught_exceptions >= 201411
+      // std::uncaught_exception() is deprecated in c++17
+      if (std::uncaught_exceptions() == 0 && comm != MPI_COMM_SELF)
+#  else
+      if (std::uncaught_exception() == false && comm != MPI_COMM_SELF)
+#  endif
+        {
+          // TODO: For now, we implement this mutex with a blocking barrier
+          // in the lock and unlock. It needs to be tested, if we can move
+          // to a nonblocking barrier (code disabled below):
 #  if 0
-      const int ierr = MPI_Ibarrier(comm, &request);
-      AssertThrowMPI(ierr);
+          const int ierr = MPI_Ibarrier(comm, &request);
+          AssertThrowMPI(ierr);
 #  else
-      const int ierr = MPI_Barrier(comm);
-      AssertThrowMPI(ierr);
+          const int ierr = MPI_Barrier(comm);
+          AssertThrowMPI(ierr);
 #  endif
+        }
 #endif
 
+      // Unlock the mutex in either case. Either we successfully
+      // synchronized processes in the barrier, or we want to
+      // continue to unwind the stack without throwing exceptions
+      // in the destructor of this class.
       locked = false;
     }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.