Reference documentation for deal.II version GIT 5dd0dfed0b 2022-12-08 21:45:02+00:00
\(\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>
23 #include <deal.II/base/mutex.h>
25 
26 #include <deal.II/lac/vector.h>
27 
28 #include <iostream>
29 #include <memory>
30 #include <vector>
31 
33 
34 
105 template <typename VectorType = ::Vector<double>>
106 class VectorMemory : public Subscriptor
107 {
108 public:
114  virtual ~VectorMemory() override = default;
115 
134  virtual VectorType *
135  alloc() = 0;
136 
151  virtual void
152  free(const VectorType *const) = 0;
153 
164  "You are trying to deallocate a vector from a memory pool, but this "
165  "vector has not actually been allocated by the same pool before.");
166 
189  class Pointer
190  : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
191  {
192  public:
200  Pointer() = default;
201 
206  Pointer(Pointer &&p) noexcept = default;
207 
212  Pointer &
213  operator=(Pointer &&p) noexcept = default;
214 
220 
224  ~Pointer() = default;
225  };
226 };
227 
228 
229 
237 template <typename VectorType = ::Vector<double>>
238 class PrimitiveVectorMemory : public VectorMemory<VectorType>
239 {
240 public:
263  virtual VectorType *
264  alloc() override;
265 
283  virtual void
284  free(const VectorType *const v) override;
285 };
286 
287 
288 
314 template <typename VectorType = ::Vector<double>>
315 class GrowingVectorMemory : public VectorMemory<VectorType>
316 {
317 public:
322 
327  GrowingVectorMemory(const size_type initial_size = 0,
328  const bool log_statistics = false);
329 
336  virtual ~GrowingVectorMemory() override;
337 
356  virtual VectorType *
357  alloc() override;
358 
376  virtual void
377  free(const VectorType *const) override;
378 
382  static void
384 
388  virtual std::size_t
390 
391 private:
398  using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
399 
407  struct Pool
408  {
412  Pool();
413 
417  ~Pool();
418 
422  void
423  initialize(const size_type size);
424 
428  std::vector<entry_type> *data;
429  };
430 
434  static Pool &
436 
442 
448 
453 
459 };
460 
461 
462 
463 namespace internal
464 {
465  namespace GrowingVectorMemoryImplementation
466  {
467  void
469  }
470 } // namespace internal
471 
474 #ifndef DOXYGEN
475 /* --------------------- inline functions ---------------------- */
476 
477 
478 template <typename VectorType>
480  : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
481  mem.alloc(),
482  [&mem](VectorType *v) { mem.free(v); })
483 {}
484 
485 
486 
487 template <typename VectorType>
488 VectorType *
490 {
491  return new VectorType();
492 }
493 
494 
495 
496 template <typename VectorType>
497 void
498 PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
499 {
500  delete v;
501 }
502 
503 
504 
505 #endif // DOXYGEN
506 
508 
509 #endif
virtual VectorType * alloc() override
static void release_unused_memory()
static Pool & get_pool()
types::global_dof_index size_type
static Threads::Mutex mutex
virtual void free(const VectorType *const) override
virtual std::size_t memory_consumption() const
virtual ~GrowingVectorMemory() override
GrowingVectorMemory(const size_type initial_size=0, const bool log_statistics=false)
std::pair< bool, std::unique_ptr< VectorType > > entry_type
virtual void free(const VectorType *const v) override
virtual VectorType * alloc() override
Pointer & operator=(Pointer &&p) noexcept=default
Pointer(Pointer &&p) noexcept=default
Pointer(VectorMemory< VectorType > &mem)
virtual ~VectorMemory() override=default
virtual VectorType * alloc()=0
virtual void free(const VectorType *const)=0
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
static ::ExceptionBase & ExcNotAllocatedHere()
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:487
unsigned int global_dof_index
Definition: types.h:81
void initialize(const size_type size)
std::vector< entry_type > * data