Reference documentation for deal.II version Git 32ab9f15fd 2020-11-24 23:04:10 -0500
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
vector_memory.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_vector_memory_h
17 #define dealii_vector_memory_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/logstream.h>
25 
26 #include <deal.II/lac/vector.h>
27 
28 #include <iostream>
29 #include <memory>
30 #include <vector>
31 
33 
34 
37 
103 template <typename VectorType = ::Vector<double>>
104 class VectorMemory : public Subscriptor
105 {
106 public:
112  virtual ~VectorMemory() override = default;
113 
132  virtual VectorType *
133  alloc() = 0;
134 
149  virtual void
150  free(const VectorType *const) = 0;
151 
162  "You are trying to deallocate a vector from a memory pool, but this "
163  "vector has not actually been allocated by the same pool before.");
164 
166 
187  class Pointer
188  : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
189  {
190  public:
198  Pointer() = default;
199 
204  Pointer(Pointer &&p) noexcept = default;
205 
210  Pointer &
211  operator=(Pointer &&p) noexcept = default;
212 
218 
222  ~Pointer() = default;
223  };
224 };
225 
226 
227 
235 template <typename VectorType = ::Vector<double>>
236 class PrimitiveVectorMemory : public VectorMemory<VectorType>
237 {
238 public:
261  virtual VectorType *
262  alloc() override;
263 
281  virtual void
282  free(const VectorType *const v) override;
283 };
284 
285 
286 
312 template <typename VectorType = ::Vector<double>>
313 class GrowingVectorMemory : public VectorMemory<VectorType>
314 {
315 public:
320 
325  GrowingVectorMemory(const size_type initial_size = 0,
326  const bool log_statistics = false);
327 
334  virtual ~GrowingVectorMemory() override;
335 
354  virtual VectorType *
355  alloc() override;
356 
374  virtual void
375  free(const VectorType *const) override;
376 
380  static void
381  release_unused_memory();
382 
386  virtual std::size_t
387  memory_consumption() const;
388 
389 private:
396  using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
397 
405  struct Pool
406  {
410  Pool();
411 
415  ~Pool();
416 
420  void
421  initialize(const size_type size);
422 
426  std::vector<entry_type> *data;
427  };
428 
432  static Pool &
433  get_pool();
434 
440 
446 
451 
457 };
458 
459 
460 
461 namespace internal
462 {
463  namespace GrowingVectorMemoryImplementation
464  {
465  void
467  }
468 } // namespace internal
469 
472 #ifndef DOXYGEN
473 /* --------------------- inline functions ---------------------- */
474 
475 
476 template <typename VectorType>
478  : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
479  mem.alloc(),
480  [&mem](VectorType *v) { mem.free(v); })
481 {}
482 
483 
484 
485 template <typename VectorType>
486 VectorType *
488 {
489  return new VectorType();
490 }
491 
492 
493 
494 template <typename VectorType>
495 void
497 {
498  delete v;
499 }
500 
501 
502 
503 #endif // DOXYGEN
504 
506 
507 #endif
virtual VectorType * alloc()=0
std::pair< bool, std::unique_ptr< BlockVector< number > > > entry_type
std::vector< entry_type > * data
virtual void free(const VectorType *const)=0
static ::ExceptionBase & ExcNotAllocatedHere()
virtual ~VectorMemory() override=default
virtual void free(const VectorType *const v) override
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:372
static Threads::Mutex mutex
unsigned int global_dof_index
Definition: types.h:76
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:371
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
virtual VectorType * alloc() override
Pointer & operator=(Pointer &&p) noexcept=default