Reference documentation for deal.II version GIT relicensing-1062-gc06da148b8 2024-07-15 19:20: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\}}\)
Loading...
Searching...
No Matches
vector_memory.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1998 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_vector_memory_h
16#define dealii_vector_memory_h
17
18
19#include <deal.II/base/config.h>
20
21#include <deal.II/base/mutex.h>
23
24#include <deal.II/lac/vector.h>
25
26#include <iostream>
27#include <memory>
28#include <vector>
29
31
32
103template <typename VectorType = ::Vector<double>>
105{
106public:
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
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
235template <typename VectorType = ::Vector<double>>
236class PrimitiveVectorMemory : public VectorMemory<VectorType>
237{
238public:
261 virtual VectorType *
262 alloc() override;
263
281 virtual void
282 free(const VectorType *const v) override;
283};
284
285
286
312template <typename VectorType = ::Vector<double>>
313class GrowingVectorMemory : public VectorMemory<VectorType>
314{
315public:
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
382
386 virtual std::size_t
388
389private:
396 using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
397
405 struct Pool
406 {
411
416
420 void
422
426 std::vector<entry_type> *data;
427 };
428
432 static Pool &
434
440
446
451
457};
458
459
460
461namespace internal
462{
463 namespace GrowingVectorMemoryImplementation
464 {
465 void
467 }
468} // namespace internal
469
472#ifndef DOXYGEN
473/* --------------------- inline functions ---------------------- */
474
475
476template <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
485template <typename VectorType>
488{
489 return new VectorType();
490}
491
492
493
494template <typename VectorType>
495void
496PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
497{
498 delete v;
499}
500
501
502
503#endif // DOXYGEN
504
506
507#endif
virtual VectorType * alloc() override
static void release_unused_memory()
static Pool & get_pool()
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 VectorType * alloc()=0
virtual ~VectorMemory() override=default
virtual void free(const VectorType *const)=0
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
static ::ExceptionBase & ExcNotAllocatedHere()
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:494
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
STL namespace.
unsigned int global_dof_index
Definition types.h:81
void initialize(const size_type size)
std::vector< entry_type > * data