1#ifndef MADNESS_WORLD_WORLDMEM_H__INCLUDED
2#define MADNESS_WORLD_WORLDMEM_H__INCLUDED
40#ifdef WORLD_GATHER_MEM_STATS
47#if defined(MADNESS_HAS_GOOGLE_PERF_TCMALLOC)
48#include <gperftools/malloc_extension.h>
49#elif defined(HAVE_IBMBGQ)
50#include <spi/include/kernel/memory.h>
51#elif defined(ON_A_MAC)
52#include <malloc/malloc.h>
58#include <sys/sysinfo.h>
72#ifdef WORLD_GATHER_MEM_STATS
73 friend void*
::operator new(
size_t size)
throw (std::bad_alloc);
74 friend void ::operator
delete(
void *
p)
throw();
78 void do_new(
void *
p, std::size_t size);
81 void do_del(
void *
p, std::size_t size);
163 int rank,
const String& tag,
166#if defined(WORLD_MEM_PROFILE_ENABLE)
175 std::basic_ios<wchar_t>::out |
176 std::basic_ios<wchar_t>::app);
179 if constexpr (std::is_same_v<String, std::basic_string<char>> || std::is_same_v<String, std::basic_string_view<char>>) {
180 std::wstring
wtag;
wtag.resize(tag.size());
181 std::copy(tag.begin(), tag.end(),
wtag.begin());
188 1 / (1024.0 * 1024.0);
189#if defined(MADNESS_HAS_GOOGLE_PERF_TCMALLOC)
192 MallocExtension::instance()->GetStats(&buf[0], 100000);
197 MallocExtension::instance()->GetStats(&buf[0], 9999);
200#elif defined(HAVE_IBMBGQ)
221#elif defined(ON_A_MAC)
242 std::string(
"/proc/") + std::to_string(
getpid()) + std::string(
"/status");
245 std::basic_string<char> line;
Used to output memory statistics and control tracing, etc.
Definition worldmem.h:71
void print() const
Prints memory use statistics to std::cout.
Definition worldmem.cc:91
void reset()
Resets all counters to zero.
Definition worldmem.cc:105
void set_trace(bool trace)
If trace is set true a message is printed for every new and delete.
Definition worldmem.h:102
void set_max_mem_limit(unsigned long max_mem_limit)
Set the maximum memory limit (trying to allocate more will throw MadnessException)
Definition worldmem.h:107
unsigned long num_new_calls
If you add new stats be sure that the initialization in worldmem.cc is OK.
Definition worldmem.h:86
void do_del(void *p, std::size_t size)
Invoked when user pointer p is deleted with size bytes.
Definition worldmem.cc:82
unsigned long cur_num_bytes
Current amount of allocated memory in bytes.
Definition worldmem.h:90
void do_new(void *p, std::size_t size)
Invoked when user pointer p is allocated with size bytes.
Definition worldmem.cc:71
unsigned long max_num_frags
Lifetime maximum number of allocated fragments.
Definition worldmem.h:89
unsigned long cur_num_frags
Current number of allocated fragments.
Definition worldmem.h:88
unsigned long num_del_calls
Counts calls to delete.
Definition worldmem.h:87
unsigned long max_mem_limit
if size+cur_num_bytes>max_mem_limit new will throw MadnessException
Definition worldmem.h:92
static const unsigned long overhead
Definition worldmem.h:84
unsigned long max_num_bytes
Lifetime maximum number of allocated bytes.
Definition worldmem.h:91
bool trace
Definition worldmem.h:93
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
Macros and tools pertaining to the configuration of MADNESS.
bool & print_meminfo_flag_accessor()
Definition worldmem.cc:184
const char * Vm_cstr< char >()
Definition worldmem.cc:181
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static const char * filename
Definition legendre.cc:96
bool print_meminfo_enabled()
Definition worldmem.cc:200
WorldMemInfo * world_mem_info()
Returns pointer to internal structure.
Definition worldmem.cc:67
void print_meminfo(int rank, const String &tag, const std::string filename_prefix=std::string("MEMORY"), bool verbose=false)
print aggregate memory stats to file filename_prefix.<rank> , tagged with tag
Definition worldmem.h:162
void print_meminfo_disable()
disables print_meminfo() profiling (i.e. calling it is a no-op)
Definition worldmem.cc:194
void print_meminfo_enable()
Definition worldmem.cc:197
bool print_meminfo_keep_ostream_open()
Definition worldmem.cc:208
std::basic_ofstream< wchar_t > & print_meminfo_ostream(int rank, const std::string filename_prefix)
Definition worldmem.cc:213
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371