]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MPI_InitFinalize: add an at_mpi_init and at_mpi_finalize signal handler
authorMatthias Maier <tamiko@43-1.org>
Mon, 19 Apr 2021 18:13:50 +0000 (13:13 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 19 Apr 2021 22:01:12 +0000 (17:01 -0500)
include/deal.II/base/mpi.h
source/base/mpi.cc

index 5bda17c693cb03fbee1939efebe840f81eccc3e1..2a0e52342b04b9ca107f1804d076bb5abb6fa8ef 100644 (file)
@@ -23,6 +23,8 @@
 #include <deal.II/base/mpi_tags.h>
 #include <deal.II/base/numbers.h>
 
+#include <boost/signals2.hpp>
+
 #include <map>
 #include <numeric>
 #include <set>
@@ -991,6 +993,32 @@ namespace Utilities
       static void
       unregister_request(MPI_Request &request);
 
+      /**
+       * A structure that has boost::signal objects to register a call back
+       * to run after MPI init or finalize.
+       *
+       * For documentation on signals, see
+       * http://www.boost.org/doc/libs/release/libs/signals2 .
+       */
+      struct Signals
+      {
+        /**
+         * A signal that is triggered immediately after we have
+         * initialized the MPI context with <code>MPI_Init()</code>.
+         */
+        boost::signals2::signal<void()> at_mpi_init;
+
+        /**
+         * A signal that is triggered just before we close the MPI context
+         * with <code>MPI_Finalize()</code>. It can be used to deallocate
+         * statically allocated MPI resources that need to be deallocated
+         * before <code>MPI_Finalize()</code> is called.
+         */
+        boost::signals2::signal<void()> at_mpi_finalize;
+      };
+
+      static Signals signals;
+
     private:
       /**
        * Requests to MPI_Wait before finalizing
index c47c1eb2449e8cbf8b6524d1715a56996dc793e5..4829c7889163366819f5e0148a1165bddd172ed4 100644 (file)
@@ -922,6 +922,9 @@ namespace Utilities
           // finally set this number of threads
           MultithreadInfo::set_thread_limit(n_threads);
         }
+
+      // As a final step call the at_mpi_init() signal handler.
+      signals.at_mpi_init();
     }
 
 
@@ -954,6 +957,9 @@ namespace Utilities
 
     MPI_InitFinalize::~MPI_InitFinalize()
     {
+      // First, call the at_mpi_finalize() signal handler.
+      signals.at_mpi_finalize();
+
       // make memory pool release all PETSc/Trilinos/MPI-based vectors that
       // are no longer used at this point. this is relevant because the static
       // object destructors run for these vectors at the end of the program

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.