Reference documentation for deal.II version GIT relicensing-453-g9b4d7b6a5a 2024-04-20 16:00: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 - 2022 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
22#include <deal.II/base/mutex.h>
24
25#include <deal.II/lac/vector.h>
26
27#include <iostream>
28#include <memory>
29#include <vector>
30
32
33
104template <typename VectorType = ::Vector<double>>
106{
107public:
113 virtual ~VectorMemory() override = default;
114
133 virtual VectorType *
134 alloc() = 0;
135
150 virtual void
151 free(const VectorType *const) = 0;
152
163 "You are trying to deallocate a vector from a memory pool, but this "
164 "vector has not actually been allocated by the same pool before.");
165
189 : public std::unique_ptr<VectorType, std::function<void(VectorType *)>>
190 {
191 public:
199 Pointer() = default;
200
205 Pointer(Pointer &&p) noexcept = default;
206
211 Pointer &
212 operator=(Pointer &&p) noexcept = default;
213
219
223 ~Pointer() = default;
224 };
225};
226
227
228
236template <typename VectorType = ::Vector<double>>
237class PrimitiveVectorMemory : public VectorMemory<VectorType>
238{
239public:
262 virtual VectorType *
263 alloc() override;
264
282 virtual void
283 free(const VectorType *const v) override;
284};
285
286
287
313template <typename VectorType = ::Vector<double>>
314class GrowingVectorMemory : public VectorMemory<VectorType>
315{
316public:
321
326 GrowingVectorMemory(const size_type initial_size = 0,
327 const bool log_statistics = false);
328
335 virtual ~GrowingVectorMemory() override;
336
355 virtual VectorType *
356 alloc() override;
357
375 virtual void
376 free(const VectorType *const) override;
377
381 static void
383
387 virtual std::size_t
389
390private:
397 using entry_type = std::pair<bool, std::unique_ptr<VectorType>>;
398
406 struct Pool
407 {
412
417
421 void
423
427 std::vector<entry_type> *data;
428 };
429
433 static Pool &
435
441
447
452
458};
459
460
461
462namespace internal
463{
464 namespace GrowingVectorMemoryImplementation
465 {
466 void
468 }
469} // namespace internal
470
473#ifndef DOXYGEN
474/* --------------------- inline functions ---------------------- */
475
476
477template <typename VectorType>
479 : std::unique_ptr<VectorType, std::function<void(VectorType *)>>(
480 mem.alloc(),
481 [&mem](VectorType *v) { mem.free(v); })
482{}
483
484
485
486template <typename VectorType>
487VectorType *
489{
490 return new VectorType();
491}
492
493
494
495template <typename VectorType>
496void
497PrimitiveVectorMemory<VectorType>::free(const VectorType *const v)
498{
499 delete v;
500}
501
502
503
504#endif // DOXYGEN
505
507
508#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
STL namespace.
unsigned int global_dof_index
Definition types.h:81
void initialize(const size_type size)
std::vector< entry_type > * data