SST 12.1.0
Structural Simulation Toolkit
mempool.h
1// Copyright 2009-2022 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2022, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_MEMPOOL_H
13#define SST_CORE_MEMPOOL_H
14
15#include "sst/core/serialization/serializable.h"
16
17namespace SST {
18class Output;
19
20namespace Core {
21
22// Class to access stats/data about the mempools. This is here to
23// limit exposure to the USE_MEMPOOL #define, which will only be in
24// core .cc files.
26{
27public:
28 // Gets the arena size for the specified pool size on the current
29 // thread. If mempools aren't enabled, it will return 0.
30 static size_t getArenaSize(size_t size);
31
32 // Gets the number of arenas allocated for the specified pool size
33 // on the current thread. If mempools aren't enabled, it will
34 // return 0.
35 static size_t getNumArenas(size_t size);
36
37 // Gets the total bytes used for the specified pool size on the
38 // current thread. If mempools aren't enabled, it will return 0.
39 static uint64_t getBytesMemUsedBy(size_t size);
40
41 // Gets the total mempool usage for the rank. Returns both the
42 // bytes and the number of active entries. Bytes and entries are
43 // added to the value passed into the function. If mempools
44 // aren't enabled, then nothing will be counted.
45 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_entries);
46
47 // Initialize the global mempool data structures
48 static void initializeGlobalData(int num_threads);
49
50 // Initialize the per thread mempool ata structures
51 static void initializeLocalData(int thread);
52};
53
54// Base class for those classes that will use mempools. Mempools are
55// designed to be used primarily with Activities/Events and small data
56// strcutures that are part of events. Thus, MemPoolItem inherits
57// from Serializable because all these classes will generally need to
58// serialize.
60{
61protected:
62 MemPoolItem() {}
63
64public:
65 /** Allocates memory from a memory pool for a new Activity */
66 void* operator new(std::size_t size) noexcept;
67
68 /** Returns memory for this Activity to the appropriate memory pool */
69 void operator delete(void* ptr);
70
71 /** Get a string represenation of the entry. The default version
72 * will just use the name of the class, retrieved through the
73 * cls_name() function inherited from the serialzable class, which
74 * will return the name of the last class to call one of the
75 * serialization macros (ImplementSerializable(),
76 * ImplementVirtualSerializable(), or NotSerializable()).
77 * Subclasses can override this function if they want to add
78 * additional information.
79 */
80 virtual std::string toString() const;
81
82
83 virtual void print(const std::string& header, Output& out) const;
84
85 ImplementVirtualSerializable(SST::Core::MemPoolItem)
86};
87
88} // namespace Core
89} // namespace SST
90
91#endif // SST_CORE_MEMPOOL_H
Definition: mempool.h:26
Definition: mempool.h:60
virtual std::string toString() const
Get a string represenation of the entry.
Definition: mempool.cc:453
Definition: serializable.h:119
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition: output.h:52