15 #if !defined(KRATOS_FIXED_SIZE_MEMORY_POOL_H_INCLUDED )
16 #define KRATOS_FIXED_SIZE_MEMORY_POOL_H_INCLUDED
66 mThreadsPool.emplace_back(BlockSizeInBytes,
ChunkSize, i_thread);
100 if (mThreadsPool[i_thread].
Deallocate(pPointrerToRelease)) {
104 KRATOS_ERROR <<
"The Pointer with address " << pPointrerToRelease <<
" was not found in this pool" << std::endl;
110 memory_used += mThreadsPool[i_thread].
MemoryUsed();
118 return memory_overhead;
122 std::size_t number_of_allocated_chunks = 0;
124 number_of_allocated_chunks += mThreadsPool[i_thread].GetNumberOfChunks() - mThreadsPool[i_thread].GetNumberOfReleasedChunks();
125 return number_of_allocated_chunks;
146 return "FixedSizeMemoryPool";
158 double overhead_percentage = memory_overhead;
159 if (memory_overhead < memory_used)
160 overhead_percentage =
static_cast<double>(memory_overhead)/(memory_used - memory_overhead);
161 overhead_percentage *= 100.00;
164 << SizeInBytesToString(
ChunkSize()) <<
" bytes each. Total memory usage: "
165 << SizeInBytesToString(
MemoryUsed()) <<
" bytes and memory overhead "
166 << SizeInBytesToString(
MemoryOverhead()) <<
"(" << overhead_percentage <<
"%)" << std::endl;
177 std::vector<ThreadFixedSizeMemoryPool> mThreadsPool;
183 std::string SizeInBytesToString(std::size_t Bytes)
const {
184 std::stringstream buffer;
185 double result = Bytes;
186 constexpr
int units_size = 5;
187 constexpr
char units[units_size] = {
' ',
'k',
'M',
'G',
'T' };
189 for (;
i < units_size;
i++)
196 buffer << result << units[
i];
216 rOStream << std::endl;
std::size_t SizeType
Definition: chunk.h:56
FixedSizeMemoryPool is the multi-thread manager of Kratos memory management.
Definition: fixed_size_memory_pool.h:40
std::size_t GetNumberOfAllocatedChunks() const
Definition: fixed_size_memory_pool.h:121
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: fixed_size_memory_pool.h:150
void * Allocate()
This function does not throw and returns zero if cannot allocate.
Definition: fixed_size_memory_pool.h:86
FixedSizeMemoryPool()=delete
Default constructor is deleted.
void Deallocate(void *pPointrerToRelease)
Definition: fixed_size_memory_pool.h:91
std::string Info() const
Turn back information as a string.
Definition: fixed_size_memory_pool.h:145
FixedSizeMemoryPool(FixedSizeMemoryPool const &rOther)=delete
Copy constructor is deleted.
FixedSizeMemoryPool & operator=(FixedSizeMemoryPool const &rOther)=delete
Assignment operator is deleted.
Chunk::SizeType SizeType
Definition: fixed_size_memory_pool.h:45
FixedSizeMemoryPool(std::size_t BlockSizeInBytes, SizeType ChunkSize=DefaultChunkSize)
The constructor to be called.
Definition: fixed_size_memory_pool.h:61
std::size_t MemoryUsed() const
Definition: fixed_size_memory_pool.h:107
virtual ~FixedSizeMemoryPool()
Destructor.
Definition: fixed_size_memory_pool.h:70
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: fixed_size_memory_pool.h:155
SizeType ChunkSize() const
Definition: fixed_size_memory_pool.h:132
std::size_t MemoryOverhead() const
Definition: fixed_size_memory_pool.h:114
static constexpr SizeType DefaultChunkSize
Definition: fixed_size_memory_pool.h:49
This class defines and stores a lock and gives an interface to it.
Definition: lock_object.h:42
static int GetCurrentNumberOfThreads()
Wrapper for omp_get_num_threads().
Definition: openmp_utils.h:73
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
integer i
Definition: TensorModule.f:17