www.mooseframework.org
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
MemoryUsageReporter Class Reference

Mix-in class for querying memory metrics used by MemoryUsage and VectorMemoryUsage. More...

#include <MemoryUsageReporter.h>

Inheritance diagram for MemoryUsageReporter:
[legend]

Public Member Functions

 MemoryUsageReporter (const MooseObject *moose_object)
 

Protected Attributes

const Parallel::Communicator & _mur_communicator
 communicator for this object More...
 
processor_id_type _my_rank
 this objects rank More...
 
processor_id_type _nrank
 number of ranks in teh object's communicator More...
 
std::vector< unsigned int > _hardware_id
 hardware IDs for each MPI rank (valid on rank zero only) More...
 
unsigned long long _memory_total
 total RAM installed in the local node More...
 
std::vector< unsigned long long > _hardware_memory_total
 total RAM for each hardware ID (node) (valid on rank zero only) More...
 

Private Member Functions

void sharedMemoryRanksBySplitCommunicator ()
 Use a share memory type communicator split (MPI3) More...
 
void sharedMemoryRanksByProcessorname ()
 Identify hardware by MPI processor name. More...
 

Detailed Description

Mix-in class for querying memory metrics used by MemoryUsage and VectorMemoryUsage.

Definition at line 20 of file MemoryUsageReporter.h.

Constructor & Destructor Documentation

◆ MemoryUsageReporter()

MemoryUsageReporter::MemoryUsageReporter ( const MooseObject moose_object)

Definition at line 13 of file MemoryUsageReporter.C.

14  : _mur_communicator(moose_object->comm()),
16  _nrank(_mur_communicator.size()),
18 {
19  // get total available ram
21  if (!_memory_total)
22  mooseWarning("Unable to query hardware memory size in ", moose_object->name());
23 
24  // gather all per node memory to processor zero
25  std::vector<unsigned long long> memory_totals(_nrank);
26  _mur_communicator.gather(0, _memory_total, memory_totals);
27 
29 
30  // validate and store per node memory
31  if (_my_rank == 0)
32  for (std::size_t i = 0; i < _nrank; ++i)
33  {
34  auto id = _hardware_id[i];
35  if (id == _hardware_memory_total.size())
36  {
37  _hardware_memory_total.resize(id + 1);
38  _hardware_memory_total[id] = memory_totals[i];
39  }
40  else if (_hardware_memory_total[id] != memory_totals[i])
41  mooseWarning("Inconsistent total memory reported by ranks on the same hardware node in ",
42  moose_object->name());
43  }
44 }
const Parallel::Communicator & _mur_communicator
communicator for this object
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:220
std::vector< unsigned long long > _hardware_memory_total
total RAM for each hardware ID (node) (valid on rank zero only)
unsigned long long _memory_total
total RAM installed in the local node
std::size_t getTotalRAM()
get the total amount of physical RAM available
Definition: MemoryUtils.C:32
void sharedMemoryRanksBySplitCommunicator()
Use a share memory type communicator split (MPI3)
processor_id_type _nrank
number of ranks in teh object&#39;s communicator
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:51
processor_id_type _my_rank
this objects rank
std::vector< unsigned int > _hardware_id
hardware IDs for each MPI rank (valid on rank zero only)

Member Function Documentation

◆ sharedMemoryRanksByProcessorname()

void MemoryUsageReporter::sharedMemoryRanksByProcessorname ( )
private

Identify hardware by MPI processor name.

Definition at line 81 of file MemoryUsageReporter.C.

82 {
83  // get processor names and assign a unique number to each piece of hardware
84  std::string processor_name = MemoryUtils::getMPIProcessorName();
85 
86  // gather all names at processor zero
87  std::vector<std::string> processor_names(_nrank);
88  _mur_communicator.gather(0, processor_name, processor_names);
89 
90  // assign a unique numerical id to them on processor zero
91  unsigned int id = 0;
92  if (_my_rank == 0)
93  {
94  // map to assign an id to each processor name string
95  std::map<std::string, unsigned int> hardware_id_map;
96  for (std::size_t i = 0; i < _nrank; ++i)
97  {
98  // generate or look up unique ID for the current processor name
99  auto it = hardware_id_map.lower_bound(processor_names[i]);
100  if (it == hardware_id_map.end() || it->first != processor_names[i])
101  it = hardware_id_map.emplace_hint(it, processor_names[i], id++);
102  _hardware_id[i] = it->second;
103  }
104  }
105 }
const Parallel::Communicator & _mur_communicator
communicator for this object
std::string getMPIProcessorName()
get the MPI hostname
Definition: MemoryUtils.C:48
processor_id_type _nrank
number of ranks in teh object&#39;s communicator
processor_id_type _my_rank
this objects rank
std::vector< unsigned int > _hardware_id
hardware IDs for each MPI rank (valid on rank zero only)

◆ sharedMemoryRanksBySplitCommunicator()

void MemoryUsageReporter::sharedMemoryRanksBySplitCommunicator ( )
private

Use a share memory type communicator split (MPI3)

Definition at line 47 of file MemoryUsageReporter.C.

Referenced by MemoryUsageReporter().

48 {
49  // figure out which ranks share memory
50  processor_id_type world_rank = 0;
51 #ifdef LIBMESH_HAVE_MPI
52  // create a split communicator among shared memory ranks
53  MPI_Comm shmem_raw_comm;
54  MPI_Comm_split_type(
55  _mur_communicator.get(), MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmem_raw_comm);
56  Parallel::Communicator shmem_comm(shmem_raw_comm);
57 
58  // broadcast the world rank of the sub group root
59  world_rank = _my_rank;
60  shmem_comm.broadcast(world_rank, 0);
61 #endif
62  std::vector<processor_id_type> world_ranks(_nrank);
63  _mur_communicator.gather(0, world_rank, world_ranks);
64 
65  // assign a contiguous unique numerical id to each shared memory group on processor zero
66  unsigned int id = 0;
67  processor_id_type last = world_ranks[0];
68  if (_my_rank == 0)
69  for (std::size_t i = 0; i < _nrank; ++i)
70  {
71  if (world_ranks[i] != last)
72  {
73  last = world_ranks[i];
74  id++;
75  }
76  _hardware_id[i] = id;
77  }
78 }
const Parallel::Communicator & _mur_communicator
communicator for this object
processor_id_type _nrank
number of ranks in teh object&#39;s communicator
processor_id_type _my_rank
this objects rank
std::vector< unsigned int > _hardware_id
hardware IDs for each MPI rank (valid on rank zero only)

Member Data Documentation

◆ _hardware_id

std::vector<unsigned int> MemoryUsageReporter::_hardware_id
protected

◆ _hardware_memory_total

std::vector<unsigned long long> MemoryUsageReporter::_hardware_memory_total
protected

total RAM for each hardware ID (node) (valid on rank zero only)

Definition at line 42 of file MemoryUsageReporter.h.

Referenced by VectorMemoryUsage::finalize(), MemoryUsageReporter(), and VectorMemoryUsage::VectorMemoryUsage().

◆ _memory_total

unsigned long long MemoryUsageReporter::_memory_total
protected

total RAM installed in the local node

Definition at line 39 of file MemoryUsageReporter.h.

Referenced by MemoryUsageReporter().

◆ _mur_communicator

const Parallel::Communicator& MemoryUsageReporter::_mur_communicator
protected

communicator for this object

Definition at line 27 of file MemoryUsageReporter.h.

Referenced by MemoryUsageReporter(), sharedMemoryRanksByProcessorname(), and sharedMemoryRanksBySplitCommunicator().

◆ _my_rank

processor_id_type MemoryUsageReporter::_my_rank
protected

◆ _nrank

processor_id_type MemoryUsageReporter::_nrank
protected

The documentation for this class was generated from the following files: