deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_vector_memory_h
14#define dealii_vector_memory_h
15
16
17#include <deal.II/base/config.h>
18
19#include <deal.II/base/mutex.h>
21
22#include <deal.II/lac/vector.h>
23
24#include <iostream>
25#include <memory>
26#include <vector>
27
29
30
101template <typename VectorType = ::Vector<double>>
103{
104public:
110 virtual ~VectorMemory() override = default;
111
130 virtual VectorType *
131 alloc() = 0;
132
147 virtual void
148 free(const VectorType *const) = 0;
149
160 "You are trying to deallocate a vector from a memory pool, but this "
161 "vector has not actually been allocated by the same pool before.");
162
186 : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
187 {
188 public:
196 Pointer() = default;
197
202 Pointer(Pointer &&p) noexcept = default;
203
208 Pointer &
209 operator=(Pointer &&p) noexcept = default;
210
216
220 ~Pointer() = default;
221 };
222};
223
224
225
233template <typename VectorType = ::Vector<double>>
234class PrimitiveVectorMemory : public VectorMemory<VectorType>
235{
236public:
259 virtual VectorType *
260 alloc() override;
261
279 virtual void
280 free(const VectorType *const v) override;
281};
282
283
284
310template <typename VectorType = ::Vector<double>>
311class GrowingVectorMemory : public VectorMemory<VectorType>
312{
313public:
318
323 GrowingVectorMemory(const size_type initial_size = 0,
324 const bool log_statistics = false);
325
332 virtual ~GrowingVectorMemory() override;
333
352 virtual VectorType *
353 alloc() override;
354
372 virtual void
373 free(const VectorType *const) override;
374
378 static void
380
384 virtual std::size_t
386
387private:
394 using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
395
403 struct Pool
404 {
409
414
418 void
420
424 std::vector<entry_type> *data;
425 };
426
430 static Pool &
432
438
444
449
455};
456
457
458
459namespace internal
460{
461 namespace GrowingVectorMemoryImplementation
462 {
463 void
465 }
466} // namespace internal
467
470#ifndef DOXYGEN
471/* --------------------- inline functions ---------------------- */
472
473
474template <typename VectorType>
476 : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
477 mem.alloc(),
478 [&mem](VectorType *v) { mem.free(v); })
479{}
480
481
482
483template <typename VectorType>
486{
487 return new VectorType();
488}
489
490
491
492template <typename VectorType>
493void
494PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
495{
496 delete v;
497}
498
499
500
501#endif // DOXYGEN
502
504
505#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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcNotAllocatedHere()
#define DeclExceptionMsg(Exception, defaulttext)
std::size_t size
Definition mpi.cc:733
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
STL namespace.
unsigned int global_dof_index
Definition types.h:92
void initialize(const size_type size)
std::vector< entry_type > * data