NEURON
memory_usage.cpp
Go to the documentation of this file.
1 /* do not want the redef in the dynamic load case */
2 #include <nrnmpiuse.h>
3 
4 #if NRNMPI_DYNAMICLOAD
5 #include <nrnmpi_dynam.h>
6 #endif
7 
8 #include <nrnmpi.h>
9 
10 #if NRNMPI
11 #include <mpi.h>
12 #include <nrnmpidec.h>
13 #include "nrnmpi_impl.h"
14 
15 #include <iostream>
16 
17 #include "utils/logger.hpp"
18 
20 
21 static void sum_reduce_memory_usage(void* invec, void* inoutvec, int* len_, MPI_Datatype*) {
22  int len = *len_;
23 
24  auto a = static_cast<neuron::container::MemoryUsage*>(invec);
25  auto ab = static_cast<neuron::container::MemoryUsage*>(inoutvec);
26 
27  for (int i = 0; i < len; ++i) {
28  ab[i] += a[i];
29  }
30 }
31 
32 void nrnmpi_memory_stats(neuron::container::MemoryStats& stats,
34  MPI_Op op;
35  MPI_Op_create(sum_reduce_memory_usage, /* commute = */ 1, &op);
36 
37  MPI_Datatype memory_usage_mpitype;
38  MPI_Type_contiguous(sizeof(neuron::container::MemoryUsage), MPI_BYTE, &memory_usage_mpitype);
39  MPI_Type_commit(&memory_usage_mpitype);
40 
41  MPI_Allreduce(&local_memory_usage, &stats.total, 1, memory_usage_mpitype, op, nrnmpi_comm);
42 
43  MPI_Op_free(&op);
44  MPI_Type_free(&memory_usage_mpitype);
45 }
46 
47 void nrnmpi_print_memory_stats(neuron::container::MemoryStats const& memory_stats) {
48  if (nrnmpi_myid_world == 0) {
49  Printf(fmt::format("{}\n", format_memory_usage(memory_stats.total)).c_str());
50  }
51 }
52 #endif
#define i
Definition: md1redef.h:19
MemoryUsage local_memory_usage()
Gather memory usage of this process.
std::string format_memory_usage(const VectorMemoryUsage &memory_usage)
Aligned, human readable representation of memory_usage.
MPI_Comm nrnmpi_comm
int nrnmpi_myid_world
Overall SoA datastructures related memory usage.
int Printf(const char *fmt, Args... args)
Definition: logger.hpp:18