https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MemoryUsage.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 "MemoryUsage.h"
11#include "MemoryUtils.h"
12
13#include <array>
14
16
19{
21 params.addClassDescription("Memory usage statistics for the running simulation.");
22 MooseEnum mem_type("physical_memory virtual_memory page_faults", "physical_memory");
23 params.addParam<MooseEnum>("mem_type", mem_type, "Memory metric to report.");
24 MooseEnum value_type("total average max_process min_process", "total");
25 params.addParam<MooseEnum>(
26 "value_type", value_type, "Aggregation method to apply to the requested memory metric.");
27 params.addParam<MooseEnum>(
28 "mem_units", MemoryUtils::getMemUnitsEnum(), "The unit prefix used to report memory usage.");
29 params.addParam<bool>("report_peak_value",
30 true,
31 "If the postprocessor is executed more than once "
32 "during a time step, report the aggregated peak "
33 "value.");
34 return params;
35}
36
38 : GeneralPostprocessor(parameters),
40 _mem_type(getParam<MooseEnum>("mem_type").getEnum<MemType>()),
41 _value_type(getParam<MooseEnum>("value_type").getEnum<ValueType>()),
42 _mem_units(getParam<MooseEnum>("mem_units").getEnum<MemoryUtils::MemUnits>()),
43 _value(0.0),
44 _peak_value(0.0),
45 _report_peak_value(getParam<bool>("report_peak_value"))
46{
47}
48
49void
54
55void
57{
58 // skip during checking uo/aux state so that this postprocessor returns the memory
59 // usage during the regular execution
61 return;
62
65
66 // get the requested per core metric
67 switch (_mem_type)
68 {
71 break;
72
75 break;
76
78 // major page faults are currently only reported on Linux systems
79 _value = stats._page_faults;
80 break;
81 }
82}
83
84void
86{
87 // skip during checking uo/aux state so that this postprocessor returns the memory
88 // usage during the regular execution
90 return;
91
92 // perform the requested reduction
93 switch (_value_type)
94 {
95 case ValueType::total:
97 break;
98
99 case ValueType::average:
101 _value /= n_processors();
102 break;
103
104 case ValueType::max_process:
106 break;
107
108 case ValueType::min_process:
110 break;
111
112 default:
113 mooseError("Invalid value_type");
114 }
115
116 if (_value > _peak_value)
118}
119
registerMooseObject("MooseApp", MemoryUsage)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
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 Postprocessor interface and the base class Postprocessor object alo...
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.
Output maximum, average, or total process memory usage.
Definition MemoryUsage.h:20
enum MemoryUsage::ValueType _value_type
Real _peak_value
peak memory usage metric in bytes (of multiple samples in the current time step)
Definition MemoryUsage.h:56
MemoryUsage(const InputParameters &parameters)
Definition MemoryUsage.C:37
static InputParameters validParams()
Definition MemoryUsage.C:18
virtual void execute() override
Execute method.
Definition MemoryUsage.C:56
MemoryUtils::MemUnits _mem_units
The unit prefix for the reported memory statistics (kilobyte, megabyte, etc).
Definition MemoryUsage.h:50
virtual void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job.
Definition MemoryUsage.C:50
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
const bool _report_peak_value
report peak value for multiple samples in a time step
Definition MemoryUsage.h:59
enum MemoryUsage::MemType _mem_type
Real _value
memory usage metric in bytes
Definition MemoryUsage.h:53
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
Definition MemoryUsage.C:85
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 gatherSum(T &value)
Gather the parallel sum of the variable passed in.
void gatherMin(T &value)
Gather the parallel min of the variable passed in.
void gatherMax(T &value)
Gather the parallel max of the variable passed in.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
processor_id_type n_processors() const
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