https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VectorMemoryUsage.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 "VectorMemoryUsage.h"
11#include "MemoryUtils.h"
12#include <algorithm>
13
14#include "Conversion.h"
15
17
20{
22 params.addClassDescription("Get memory stats for all ranks in the simulation");
23 params.addParam<bool>("report_peak_value",
24 true,
25 "If the vectorpostprocessor is executed more than once "
26 "during a time step, report the aggregated peak "
27 "value.");
28 params.addParam<MooseEnum>("mem_units",
30 "The unit prefix used to report memory usage, default: Mebibytes");
31 return params;
32}
33
35 : GeneralVectorPostprocessor(parameters),
37 _mem_units(getParam<MooseEnum>("mem_units").getEnum<MemoryUtils::MemUnits>()),
38 _col_hardware_id(declareVector("hardware_id")),
39 _col_total_ram(declareVector("total_ram")),
40 _col_physical_mem(declareVector("physical_mem")),
41 _col_virtual_mem(declareVector("virtual_mem")),
42 _col_page_faults(declareVector("page_faults")),
43 _col_node_utilization(declareVector("node_utilization")),
44 _report_peak_value(getParam<bool>("report_peak_value")),
45 _peak_physical_mem(0.0),
46 _peak_virtual_mem(0.0)
47{
49 _col_total_ram.resize(_nrank);
54
55 if (_my_rank == 0)
56 {
57 std::copy(_hardware_id.begin(), _hardware_id.end(), _col_hardware_id.begin());
58 for (std::size_t i = 0; i < _nrank; ++i)
61 }
62}
63
64void
70
71void
73{
74 // skip during checking uo/aux state so that this postprocessor returns the memory
75 // usage during the regular execution
77 return;
78
81
83 {
84 _peak_physical_mem = std::max(_peak_physical_mem, static_cast<Real>(stats._physical_memory));
85 _peak_virtual_mem = std::max(_peak_virtual_mem, static_cast<Real>(stats._virtual_memory));
86 }
87
91}
92
93void
95{
96 // skip during checking uo/aux state so that this postprocessor returns the memory
97 // usage during the regular execution
99 return;
100
101 // send data to rank zero (avoid buffer aliasing error using out-of-vector copies)
102 auto local_physical_mem = _col_physical_mem[_my_rank];
103 _communicator.gather(0, local_physical_mem, _col_physical_mem);
104
105 auto local_virtual_mem = _col_virtual_mem[_my_rank];
106 _communicator.gather(0, local_virtual_mem, _col_virtual_mem);
107
108#ifndef __APPLE__
109 auto local_page_faults = _col_page_faults[_my_rank];
110 _communicator.gather(0, local_page_faults, _col_page_faults);
111#endif
112
113 // prepare node utilization column
114 if (_my_rank == 0)
115 {
116 std::vector<Real> physical_per_node(_hardware_memory_total.size());
117 for (std::size_t i = 0; i < _nrank; ++i)
118 physical_per_node[_hardware_id[i]] += _col_physical_mem[i];
119
120 for (std::size_t i = 0; i < _nrank; ++i)
121 _col_node_utilization[i] = physical_per_node[_hardware_id[i]] /
122 static_cast<Real>(_hardware_memory_total[_hardware_id[i]]);
123 }
124
125 // unit prefix conversion
126 for (std::size_t i = 0; i < _nrank; ++i)
127 {
130 }
131}
registerMooseObject("MooseApp", VectorMemoryUsage)
bool checkingUOAuxState() const
Return a flag to indicate whether we are executing user objects and auxliary kernels for state check ...
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Mix-in class for querying memory metrics used by MemoryUsage and VectorMemoryUsage.
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
processor_id_type _my_rank
this objects rank
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Generate a table of various memory metrics indexed by MPI rank.
VectorPostprocessorValue & _col_node_utilization
RAM utilization of the physical node (i.e. what fraction of the total RAM is the simulation using)
static InputParameters validParams()
VectorPostprocessorValue & _col_virtual_mem
virtual memory usage per rank
virtual void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job.
VectorPostprocessorValue & _col_total_ram
total RAM available on the physical node the rank is located at
VectorPostprocessorValue & _col_physical_mem
physical memory usage per rank
VectorMemoryUsage(const InputParameters &parameters)
VectorPostprocessorValue & _col_page_faults
hard page faults per rank (Linux only), i.e. swap frequency
MemoryUtils::MemUnits _mem_units
The unit prefix for the reported memory statistics (kilobyte, megabyte, etc).
virtual void finalize() override
Finalize.
virtual void execute() override
Execute method.
const bool _report_peak_value
peak values
VectorPostprocessorValue & _col_hardware_id
hardware id for the physical node the rank is located at
const Parallel::Communicator & _communicator
std::size_t convertBytes(std::size_t bytes, MemUnits unit)
convert bytes to selected unit prefix
bool getMemoryStats(Stats &stats)
get all memory stats for the current process stats The Stats object to fill with the data
Definition MemoryUtils.C:79
MooseEnum getMemUnitsEnum()
get the moose enum for the mem_unit_prefix parameter
Definition MemoryUtils.C:52
std::size_t _virtual_memory
Definition MemoryUtils.h:24
std::size_t _physical_memory
Definition MemoryUtils.h:23
std::size_t _page_faults
Definition MemoryUtils.h:25