]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Apply patch 20058 even on mainline.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Nov 2009 19:50:55 +0000 (19:50 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 7 Nov 2009 19:50:55 +0000 (19:50 +0000)
git-svn-id: https://svn.dealii.org/trunk@20065 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/utilities.cc
deal.II/lac/include/lac/vector_memory.h

index 1fffed43ed1a8de442003df94724ed1b3d668fe9..6dd3470dd50fa1e91220d9bad8f3f8d9ef5d5e60 100644 (file)
@@ -35,6 +35,9 @@
 #ifdef DEAL_II_USE_TRILINOS
 #  ifdef DEAL_II_COMPILER_SUPPORTS_MPI
 #    include <Epetra_MpiComm.h>
+#    include <lac/vector_memory.h>
+#    include <lac/trilinos_vector.h>
+#    include <lac/trilinos_block_vector.h>
 #  endif
 #  include "Epetra_SerialComm.h"
 #endif
@@ -578,9 +581,29 @@ namespace Utilities
     MPI_InitFinalize::~MPI_InitFinalize()
     {
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+
+#  ifdef DEAL_II_USE_TRILINOS
+                                      // make memory pool release all
+                                      // 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 would run after
+                                      // MPI_Finalize is called,
+                                      // leading to errors
+      GrowingVectorMemory<TrilinosWrappers::MPI::Vector>
+       ::release_unused_memory ();
+      GrowingVectorMemory<TrilinosWrappers::MPI::BlockVector>
+       ::release_unused_memory ();
+#  endif
+
       int mpi_err = 0;
 
-      if (program_uses_mpi() == true && owns_mpi == true)
+      int MPI_has_been_started = 0;
+      MPI_Initialized(&MPI_has_been_started);
+      if (program_uses_mpi() == true && owns_mpi == true &&
+         MPI_has_been_started != 0)
        mpi_err = MPI_Finalize();
 
       AssertThrow (mpi_err == 0,
index 166e951de55fb76ccb8865dfc1a1356283d3b3a7..e62f6759bc0cd22ab83dbe00944e1804315f75dc 100644 (file)
@@ -316,6 +316,12 @@ class GrowingVectorMemory : public VectorMemory<VECTOR>
                                      */
     virtual void free (const VECTOR * const);
 
+                                    /**
+                                     * Release all vectors that are
+                                     * not currently in use.
+                                     */
+    static void release_unused_memory ();
+    
                                     /**
                                      * Memory consumed by this class
                                      * and all currently allocated
@@ -577,6 +583,31 @@ GrowingVectorMemory<VECTOR>::free(const VECTOR* const v)
 
 
 
+template<typename VECTOR>
+void
+GrowingVectorMemory<VECTOR>::release_unused_memory ()
+{
+  Threads::ThreadMutex::ScopedLock lock(mutex);
+
+  std::vector<entry_type> new_data;
+
+  if (pool.data != 0)
+    {
+      const typename std::vector<entry_type>::const_iterator
+       end = pool.data->end();
+      for (typename std::vector<entry_type>::const_iterator
+            i = pool.data->begin(); i != end ; ++i)
+       if (i->first == false)
+         delete i->second;
+       else
+         new_data.push_back (*i);
+  
+      *pool.data = new_data;
+    }
+}
+
+
+
 template<typename VECTOR>
 inline
 unsigned int

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.