MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
mymalloc.h File Reference
#include "memory.h"
Include dependency graph for mymalloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define mymalloc(name, size)   allocator_alloc_bot(A_MAIN, name, size)
 
#define mymalloc2(name, size)   allocator_alloc_top(A_MAIN, name, size)
 
#define myrealloc(ptr, size)   allocator_realloc(A_MAIN, ptr, size)
 
#define myfree(x)   allocator_free(x)
 
#define ma_malloc(name, type, nele)   (type*) allocator_alloc_bot(A_MAIN, name, sizeof(type) * (nele))
 
#define ma_malloc2(name, type, nele)   (type*) allocator_alloc_top(A_MAIN, name, sizeof(type) * (nele))
 
#define ma_free(p)   allocator_free(p)
 
#define ta_malloc(name, type, nele)   (type*) allocator_alloc_bot(A_TEMP, name, sizeof(type) * (nele))
 
#define ta_malloc2(name, type, nele)   (type*) allocator_alloc_top(A_TEMP, name, sizeof(type) * (nele))
 
#define ta_reset()   allocator_reset(A_TEMP, 0)
 
#define ta_free(p)   allocator_free(p)
 
#define report_memory_usage(x)   report_detailed_memory_usage(x, "%s:%d", __FILE__, __LINE__)
 
#define mymalloc_freebytes()   allocator_get_free_size(A_MAIN)
 
#define mymalloc_usedbytes()   allocator_get_used_size(A_MAIN, ALLOC_DIR_BOTH)
 

Functions

void mymalloc_init (double MemoryMB)
 
void tamalloc_init (void)
 
void report_detailed_memory_usage (const char *label, const char *fmt,...)
 

Variables

Allocator A_MAIN [1]
 
Allocator A_TEMP [1]
 

Macro Definition Documentation

◆ ma_free

#define ma_free (   p)    allocator_free(p)

Definition at line 23 of file mymalloc.h.

◆ ma_malloc

#define ma_malloc (   name,
  type,
  nele 
)    (type*) allocator_alloc_bot(A_MAIN, name, sizeof(type) * (nele))

Definition at line 21 of file mymalloc.h.

◆ ma_malloc2

#define ma_malloc2 (   name,
  type,
  nele 
)    (type*) allocator_alloc_top(A_MAIN, name, sizeof(type) * (nele))

Definition at line 22 of file mymalloc.h.

◆ myfree

#define myfree (   x)    allocator_free(x)

Definition at line 19 of file mymalloc.h.

◆ mymalloc

#define mymalloc (   name,
  size 
)    allocator_alloc_bot(A_MAIN, name, size)

Definition at line 15 of file mymalloc.h.

◆ mymalloc2

#define mymalloc2 (   name,
  size 
)    allocator_alloc_top(A_MAIN, name, size)

Definition at line 16 of file mymalloc.h.

◆ mymalloc_freebytes

#define mymalloc_freebytes ( )    allocator_get_free_size(A_MAIN)

Definition at line 31 of file mymalloc.h.

◆ mymalloc_usedbytes

#define mymalloc_usedbytes ( )    allocator_get_used_size(A_MAIN, ALLOC_DIR_BOTH)

Definition at line 32 of file mymalloc.h.

◆ myrealloc

#define myrealloc (   ptr,
  size 
)    allocator_realloc(A_MAIN, ptr, size)

Definition at line 18 of file mymalloc.h.

◆ report_memory_usage

#define report_memory_usage (   x)    report_detailed_memory_usage(x, "%s:%d", __FILE__, __LINE__)

Definition at line 30 of file mymalloc.h.

◆ ta_free

#define ta_free (   p)    allocator_free(p)

Definition at line 28 of file mymalloc.h.

◆ ta_malloc

#define ta_malloc (   name,
  type,
  nele 
)    (type*) allocator_alloc_bot(A_TEMP, name, sizeof(type) * (nele))

Definition at line 25 of file mymalloc.h.

◆ ta_malloc2

#define ta_malloc2 (   name,
  type,
  nele 
)    (type*) allocator_alloc_top(A_TEMP, name, sizeof(type) * (nele))

Definition at line 26 of file mymalloc.h.

◆ ta_reset

#define ta_reset ( )    allocator_reset(A_TEMP, 0)

Definition at line 27 of file mymalloc.h.

Function Documentation

◆ mymalloc_init()

void mymalloc_init ( double  MemoryMB)

Definition at line 48 of file mymalloc.c.

49 {
50  /* Warning: this uses ta_malloc*/
51  size_t Nhost = cluster_get_num_hosts();
52 
53  MPI_Comm comm = MPI_COMM_WORLD;
54 
55  int NTask;
56 
57  MPI_Comm_size(comm, &NTask);
58 
59  double nodespercpu = (1.0 * Nhost) / (1.0 * NTask);
60  size_t n = 1.0 * MaxMemSizePerNode * nodespercpu * 1024. * 1024.;
61  message(0, "Nhost = %d\n", Nhost);
62  message(0, "Reserving %td bytes per rank for MAIN memory allocator. \n", n);
63  if(n < 1)
64  endrun(2, "Mem too small! MB/node=%g, nodespercpu = %g NTask = %d\n", MaxMemSizePerNode, nodespercpu, NTask);
65 
66 
67  if (MPIU_Any(ALLOC_ENOMEMORY == allocator_init(A_MAIN, "MAIN", n, 1, NULL), MPI_COMM_WORLD)) {
68  endrun(0, "Insufficient memory for the MAIN allocator on at least one nodes."
69  "Requestion %td bytes. Try reducing MaxMemSizePerNode. Also check the node health status.\n", n);
70  }
71 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
int allocator_init(Allocator *alloc, const char *name, const size_t request_size, const int zero, Allocator *parent)
Definition: memory.c:24
#define ALLOC_ENOMEMORY
Definition: memory.h:10
Allocator A_MAIN[1]
Definition: mymalloc.c:17
int cluster_get_num_hosts(void)
Definition: system.c:434
int MPIU_Any(int condition, MPI_Comm comm)
Definition: system.c:545
int NTask
Definition: test_exchange.c:23

References A_MAIN, ALLOC_ENOMEMORY, allocator_init(), cluster_get_num_hosts(), endrun(), message(), MPIU_Any(), and NTask.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ report_detailed_memory_usage()

void report_detailed_memory_usage ( const char *  label,
const char *  fmt,
  ... 
)

Definition at line 75 of file mymalloc.c.

76 {
78  return;
79  }
80 
81  MPI_Comm comm = MPI_COMM_WORLD;
82 
83  int NTask;
84  int ThisTask;
85  MPI_Comm_size(comm, &NTask);
86  MPI_Comm_rank(comm, &ThisTask);
87 
88 
89  if (ThisTask != 0) {
90  return;
91  }
92 
94 
95  va_list va;
96  va_start(va, fmt);
97  char * buf = fastpm_strdup_vprintf(fmt, va);
98  va_end(va);
99 
100  message(1, "Peak Memory usage induced by %s\n", buf);
101  myfree(buf);
103 }
void allocator_print(Allocator *alloc)
Definition: memory.c:284
size_t allocator_get_used_size(Allocator *alloc, int dir)
Definition: memory.c:256
#define ALLOC_DIR_BOTH
Definition: memory.h:14
static size_t highest_memory_usage
Definition: mymalloc.c:73
#define myfree(x)
Definition: mymalloc.h:19
char * fastpm_strdup_vprintf(const char *fmt, va_list va)
Definition: string.c:51
int ThisTask
Definition: test_exchange.c:23

References A_MAIN, ALLOC_DIR_BOTH, allocator_get_used_size(), allocator_print(), fastpm_strdup_vprintf(), highest_memory_usage, message(), myfree, NTask, and ThisTask.

Here is the call graph for this function:

◆ tamalloc_init()

void tamalloc_init ( void  )

Definition at line 29 of file mymalloc.c.

30 {
31  int Nt = omp_get_max_threads();
32  int NTask;
33  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
34 
35  /* Reserve 4MB, 512 bytes per thread, 128 bytes per task and 128 bytes per thread per task (for export) for TEMP storage.*/
36  size_t n = 4096 * 1024 + 128 * NTask + 128 * Nt * NTask + 512 * Nt;
37 
38  message(0, "Reserving %td bytes per rank for TEMP memory allocator. \n", n);
39 
40  if (MPIU_Any(ALLOC_ENOMEMORY == allocator_init(A_TEMP, "TEMP", n, 1, NULL), MPI_COMM_WORLD)) {
41  endrun(0, "Insufficient memory for the TEMP allocator on at least one nodes."
42  "Requestion %td bytes. Try reducing MaxMemSizePerNode. Also check the node health status.\n", n);
43 
44  }
45 }
Allocator A_TEMP[1]
Definition: mymalloc.c:22

References A_TEMP, ALLOC_ENOMEMORY, allocator_init(), endrun(), message(), MPIU_Any(), and NTask.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ A_MAIN

Allocator A_MAIN[1]
extern

Definition at line 17 of file mymalloc.c.

Referenced by mymalloc_init(), and report_detailed_memory_usage().

◆ A_TEMP

Allocator A_TEMP[1]
extern

Definition at line 22 of file mymalloc.c.

Referenced by tamalloc_init().