https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MemoryUsageReporter.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
unsigned long long _memory_total
total RAM installed in the local node
const std::vector< unsigned int > & _hardware_id
hardware IDs for each MPI rank (valid on rank zero only)
std::vector< unsigned long long > _hardware_memory_total
total RAM for each hardware ID (node) (valid on rank zero only)
processor_id_type _nrank
number of ranks in the object's communicator
MemoryUsageReporter(const MooseObject *moose_object)
const Parallel::Communicator & _mur_communicator
communicator for this object
processor_id_type _my_rank
this objects rank
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
std::size_t getTotalRAM()
get the total amount of physical RAM available
Definition MemoryUtils.C:59