Loading...
Searching...
No Matches
MemoryPool.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::MemoryPool
28
29Description
30 Optional memory management using a memory pool such as Umpire
31 (https://github.com/LLNL/Umpire).
32
33 When compiled with Umpire, its use can be controlled by the
34 \c FOAM_MEMORY_POOL environment variable, or the
35 \c memory_pool Optimisation switch (etc/controlDict).
36
37 It currently looks for any of the following entries, in this order:
38 - true - same as \em "host"
39 - false/none - disabled.
40 - \em "host" - uses host memory pool
41 - \em "system" - same as \em "host"
42 - \em "device" - uses device memory pool
43 - \em "managed" - uses managed host/device memory pool
44 .
45
46 The parameters "size=nn" and "incr=nn" (in MegaBytes) can be used
47 to specify alternatives to the default sizing.
48
49\*---------------------------------------------------------------------------*/
50
51#ifndef Foam_MemoryPool_H
52#define Foam_MemoryPool_H
53
54#include <cstddef> // For std::size_t
55
56// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57
58namespace Foam
59{
60
61/*---------------------------------------------------------------------------*\
62 Class MemoryPool Declaration
63\*---------------------------------------------------------------------------*/
64
65class MemoryPool
66{
67public:
68
69 // Constructors
70
71 //- Create a memory pool instance (if not already active).
72 // Uses environment or etc/controlDict entry
73 static bool create(bool verbose = false);
74
75
76 // Destructor
78 //- Remove the memory pool instance (currently does nothing)
79 static void destroy(bool verbose = false);
80
81
82 // Member Functions
83
84 //- True if pool is active (ie, created and not suspended)
85 static bool active() noexcept;
86
87 //- Suspend use of memory pool (for allocation).
88 // \return previous suspend status
89 static bool suspend() noexcept;
90
91 //- Resume use of memory pool (if previously active)
92 static void resume() noexcept;
93
94 //- Test if given pointer belongs to the pool
95 static bool is_pool(void *ptr);
96
97 //- Allocate from pool (if active).
98 // \returns nullptr if the pool is not active
99 static void* try_allocate(std::size_t nbytes);
100
101 //- Deallocate a pointer managed by the pool
102 // \returns True if a nullptr (no-op) or when the pointer was
103 // managed by the pool.
104 static bool try_deallocate(void *ptr);
105};
106
107
108// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110} // End namespace Foam
111
112// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113
114#endif
115
116// ************************************************************************* //
Optional memory management using a memory pool such as Umpire (https://github.com/LLNL/Umpire).
Definition MemoryPool.H:59
static void destroy(bool verbose=false)
Remove the memory pool instance (currently does nothing).
static void * try_allocate(std::size_t nbytes)
Allocate from pool (if active).
static bool is_pool(void *ptr)
Test if given pointer belongs to the pool.
static bool try_deallocate(void *ptr)
Deallocate a pointer managed by the pool.
static bool create(bool verbose=false)
Create a memory pool instance (if not already active).
static void resume() noexcept
Resume use of memory pool (if previously active).
static bool active() noexcept
True if pool is active (ie, created and not suspended).
static bool suspend() noexcept
Suspend use of memory pool (for allocation).
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265