www.mooseframework.org
MemoryUsageReporter.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MemoryUsageReporter.h"
11 #include "MemoryUtils.h"
12 #include "MooseApp.h"
13 
15  : _mur_communicator(moose_object->comm()),
16  _my_rank(_mur_communicator.rank()),
17  _nrank(_mur_communicator.size()),
18  _hardware_id(moose_object->getMooseApp().rankMap().rankHardwareIds())
19 {
20  // get total available ram
22  if (!_memory_total)
23  mooseWarning("Unable to query hardware memory size in ", moose_object->name());
24 
25  // gather all per node memory to processor zero
26  std::vector<unsigned long long> memory_totals(_nrank);
27  _mur_communicator.gather(0, _memory_total, memory_totals);
28 
29  // validate and store per node memory
30  if (_my_rank == 0)
31  {
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  }
45 }
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:219
std::vector< unsigned long long > _hardware_memory_total
total RAM for each hardware ID (node) (valid on rank zero only)
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
unsigned long long _memory_total
total RAM installed in the local node
MemoryUsageReporter(const MooseObject *moose_object)
std::size_t getTotalRAM()
get the total amount of physical RAM available
Definition: MemoryUtils.C:54
processor_id_type _nrank
number of ranks in teh object&#39;s communicator
MPI_Comm comm
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
processor_id_type _my_rank
this objects rank
const std::vector< unsigned int > & _hardware_id
hardware IDs for each MPI rank (valid on rank zero only)