MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions | Variables
mymalloc.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <omp.h>
#include "mymalloc.h"
#include "memory.h"
#include "system.h"
#include "endrun.h"
Include dependency graph for mymalloc.c:

Go to the source code of this file.

Functions

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

Variables

Allocator A_MAIN [1]
 
Allocator A_TEMP [1]
 
static size_t highest_memory_usage = 0
 

Function Documentation

◆ mymalloc_init()

void mymalloc_init ( double  MaxMemSizePerNode)

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]

Definition at line 17 of file mymalloc.c.

Referenced by mymalloc_init(), and report_detailed_memory_usage().

◆ A_TEMP

Allocator A_TEMP[1]

Definition at line 22 of file mymalloc.c.

Referenced by tamalloc_init().

◆ highest_memory_usage

size_t highest_memory_usage = 0
static

Definition at line 73 of file mymalloc.c.

Referenced by report_detailed_memory_usage().