From: Martin Kronbichler Date: Sat, 7 Nov 2009 19:50:55 +0000 (+0000) Subject: Apply patch 20058 even on mainline. X-Git-Tag: v8.0.0~6836 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c12f7834b201403aa85a4f2787e934e7c982bf79;p=dealii.git Apply patch 20058 even on mainline. git-svn-id: https://svn.dealii.org/trunk@20065 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/utilities.cc b/deal.II/base/source/utilities.cc index 1fffed43ed..6dd3470dd5 100644 --- a/deal.II/base/source/utilities.cc +++ b/deal.II/base/source/utilities.cc @@ -35,6 +35,9 @@ #ifdef DEAL_II_USE_TRILINOS # ifdef DEAL_II_COMPILER_SUPPORTS_MPI # include +# include +# include +# include # 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 + ::release_unused_memory (); + GrowingVectorMemory + ::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, diff --git a/deal.II/lac/include/lac/vector_memory.h b/deal.II/lac/include/lac/vector_memory.h index 166e951de5..e62f6759bc 100644 --- a/deal.II/lac/include/lac/vector_memory.h +++ b/deal.II/lac/include/lac/vector_memory.h @@ -316,6 +316,12 @@ class GrowingVectorMemory : public VectorMemory */ 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::free(const VECTOR* const v) +template +void +GrowingVectorMemory::release_unused_memory () +{ + Threads::ThreadMutex::ScopedLock lock(mutex); + + std::vector new_data; + + if (pool.data != 0) + { + const typename std::vector::const_iterator + end = pool.data->end(); + for (typename std::vector::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 inline unsigned int