]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add default memory pool
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 21 Sep 2007 01:24:32 +0000 (01:24 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 21 Sep 2007 01:24:32 +0000 (01:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@15228 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/vector_memory.h
deal.II/lac/source/vector_memory.cc [new file with mode: 0644]

index 774592e157d423ae680b44351c1cf2988b60df56..852eb042f6c5aab7a5c317d3c795296fde8aa1e4 100644 (file)
@@ -99,6 +99,21 @@ class VectorMemory : public Subscriptor
                                      */
     virtual void free (const VECTOR * const) = 0;
 
+                                    /**
+                                     * Access the default memory
+                                     * space deal.II is offering for
+                                     * vectors of this kind.
+                                     *
+                                     * This function accesses static
+                                     * VectorMemory objects used by
+                                     * deal.II classes to allocate
+                                     * vectors. It is good practice
+                                     * to use these in your program
+                                     * as well, in order to optimize
+                                     * memory usage.
+                                     */
+    static VectorMemory<VECTOR>& default_pool();
+    
                                     /** @addtogroup Exceptions
                                      * @{ */
     
@@ -111,6 +126,16 @@ class VectorMemory : public Subscriptor
                                      * this memory pool.
                                      */
     DeclException0(ExcNotAllocatedHere);
+
+                                    /**
+                                     * You tried to access the
+                                     * deal.II
+                                     * VectorMemory::default_pool(),
+                                     * but the vector class you are
+                                     * using is not a standard
+                                     * deal.II vector class.
+                                     */
+    DeclException0(ExcNoDefaultMemoryForThisVectorClass);
                                     //@}
 };
 
@@ -251,6 +276,12 @@ class GrowingVectorMemory : public VectorMemory<VECTOR>
                                      */
     unsigned int memory_consumption() const;
 
+                                    /**
+                                     * A flag controlling the logging
+                                     * of statistics at the end.
+                                     */
+    bool log_statistics;
+    
   private:
                                     /**
                                      * Type to enter into the
@@ -292,6 +323,7 @@ class GrowingVectorMemory : public VectorMemory<VECTOR>
 template <typename VECTOR>
 GrowingVectorMemory<VECTOR>::GrowingVectorMemory (const unsigned int initial_size)
                :
+               log_statistics(false),
                pool(initial_size)
 {
   Threads::ThreadMutex::ScopedLock lock(mutex);
@@ -326,10 +358,13 @@ GrowingVectorMemory<VECTOR>::~GrowingVectorMemory()
        ++n;
       delete i->second;
     }
-  deallog << "GrowingVectorMemory:Overall allocated vectors: "
-         << n_alloc << std::endl;
-  deallog << "GrowingVectorMemory:Maximum allocated vectors: "
-         << pool.size() << std::endl;
+  if (log_statistics)
+    {
+      deallog << "GrowingVectorMemory:Overall allocated vectors: "
+             << n_alloc << std::endl;
+      deallog << "GrowingVectorMemory:Maximum allocated vectors: "
+             << pool.size() << std::endl;
+    }
   pool.clear ();
 
                                   // write out warning if memory leak
diff --git a/deal.II/lac/source/vector_memory.cc b/deal.II/lac/source/vector_memory.cc
new file mode 100644 (file)
index 0000000..d77f5b1
--- /dev/null
@@ -0,0 +1,92 @@
+//---------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2007 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+#include <lac/vector_memory.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+  
+namespace
+{
+  GrowingVectorMemory<Vector<double> > default_pool_Vector_double;
+  GrowingVectorMemory<Vector<float> > default_pool_Vector_float;
+  GrowingVectorMemory<BlockVector<double> > default_pool_BlockVector_double;
+  GrowingVectorMemory<BlockVector<float> > default_pool_BlockVector_float;
+  
+  template<class VECTOR>
+  inline
+  VectorMemory<VECTOR>*
+  default_pool_select()
+  {
+    Assert(false, typename VectorMemory<VECTOR>::ExcNoDefaultMemoryForThisVectorClass());
+    return 0;
+  }
+
+
+  template <>
+  inline
+  VectorMemory<Vector<double> >*
+  default_pool_select<Vector<double> >()
+  {
+    return &default_pool_Vector_double;
+  }
+  
+  
+  template <>
+  inline
+  VectorMemory<Vector<float> >*
+  default_pool_select<Vector<float> >()
+  {
+    return &default_pool_Vector_float;
+  }
+  
+  
+  
+  template <>
+  inline
+  VectorMemory<BlockVector<double> >*
+  default_pool_select<BlockVector<double> >()
+  {
+    return &default_pool_BlockVector_double;
+  }
+  
+  
+  template <>
+  inline
+  VectorMemory<BlockVector<float> >*
+  default_pool_select<BlockVector<float> >()
+  {
+    return &default_pool_BlockVector_float;
+  }
+  
+}
+
+
+template <class VECTOR>
+VectorMemory<VECTOR>&
+VectorMemory<VECTOR>::default_pool()
+{
+  return *default_pool_select<VECTOR>();
+}
+
+
+template class VectorMemory<Vector<double> >;
+template class VectorMemory<Vector<float> >;
+template class VectorMemory<BlockVector<double> >;
+template class VectorMemory<BlockVector<float> >;
+
+
+DEAL_II_NAMESPACE_CLOSE

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.