Permalink
Browse files

Merge pull request #12660 from permcody/mem_usage

Add memory units to documentation
  • Loading branch information...
friedmud committed Jan 10, 2019
2 parents 99bc5c6 + 825886a commit 02289fb0e58efdefd5b85ff409513228c62076c6
@@ -8,6 +8,9 @@ This postprocessor collects various memory usage metrics:
- virtual memory
- major page faults (how often disk swap is accessed)

The units for memory default to MegaBytes, but users can report usage in other
units through the mem_units parameter: (bytes, kilobytes, megabytes, gigabytes).

The data can be reduced in parallel as

- maximum out of all MPI ranks
@@ -8,8 +8,8 @@ This vector postprocessor generates multiple output columns with one row per MPI
|---------------|--------------|
| `hardware_id` | Ranks with a common hardware ID share common RAM (i.e. are located on the same compute node)|
| `total_ram` | Total available RAM on the compute node the respective MPI rank is located on.|
| `physical_mem`| Physical memory the current rank uses.|
| `virtual_mem` | Virtual memory the current rank uses (the amount returned strongly depends on the operating system and does not reflect the physical RAM used by the simualtion).|
| `physical_mem`| Physical memory the current rank uses (default unit: MBs).|
| `virtual_mem` | Virtual memory the current rank uses (the amount returned strongly depends on the operating system and does not reflect the physical RAM used by the simualtion - default unit: MBs).|
| `page_faults` | Number of hard page faults encountered by the MPI rank. This number is only available on Linux systems and indicates the amount of swap activity (indicating low performance due to insufficient available RAM)|
| `node_utilization`| Indicates which fraction of the total RAM available on the compute node is occupied by MOOSE processes of the current simulation.|

@@ -12,6 +12,7 @@

#include "GeneralPostprocessor.h"
#include "MemoryUsageReporter.h"
#include "MemoryUtils.h"

class MemoryUsage;

@@ -49,6 +50,9 @@ class MemoryUsage : public GeneralPostprocessor, public MemoryUsageReporter
min_process
} _value_type;

/// The units in which to report memory statistics (kilobyte, megabyte, etc).
MemoryUtils::MemUnit _mem_units;

/// memory usage metric in bytes
Real _value;

@@ -28,8 +28,16 @@ struct Stats
std::size_t _page_faults;
};

enum class MemUnit
{
Bytes,
Kilobytes,
Megabytes,
Gigabytes,
};

/// get all memory stats for the current process
void getMemoryStats(Stats & stats);
void getMemoryStats(Stats & stats, MemUnit units = MemUnit::Megabytes);

} // namespace MemoryUtils

@@ -12,6 +12,7 @@

#include "GeneralVectorPostprocessor.h"
#include "MemoryUsageReporter.h"
#include "MemoryUtils.h"

class VectorMemoryUsage;

@@ -34,10 +35,13 @@ class VectorMemoryUsage : public GeneralVectorPostprocessor, public MemoryUsageR
virtual void finalize() override;

protected:
/// hardware id for the phyical node the rank is located at
/// The units in which to report memory statistics (kilobyte, megabyte, etc).
MemoryUtils::MemUnit _mem_units;

/// hardware id for the physical node the rank is located at
VectorPostprocessorValue & _col_hardware_id;

/// total RAM available on the phyical node the rank is located at
/// total RAM available on the physical node the rank is located at
VectorPostprocessorValue & _col_total_ram;

/// physical memory usage per rank
@@ -25,6 +25,9 @@ validParams<MemoryUsage>()
MooseEnum value_type("total average max_process min_process", "total");
params.addParam<MooseEnum>(
"value_type", value_type, "Aggregation method to apply to the requested memory metric.");
MooseEnum mem_units("bytes kilobytes megabytes gigabytes", "megabytes");
params.addParam<MooseEnum>(
"mem_units", mem_units, "The unit used to report memory usage, default: Megabytes");
params.addParam<bool>("report_peak_value",
true,
"If the postprocessor is executed more than once "
@@ -38,6 +41,7 @@ MemoryUsage::MemoryUsage(const InputParameters & parameters)
MemoryUsageReporter(this),
_mem_type(getParam<MooseEnum>("mem_type").getEnum<MemType>()),
_value_type(getParam<MooseEnum>("value_type").getEnum<ValueType>()),
_mem_units(getParam<MooseEnum>("mem_units").getEnum<MemoryUtils::MemUnit>()),
_value(0.0),
_peak_value(0.0),
_report_peak_value(getParam<bool>("report_peak_value"))
@@ -54,7 +58,7 @@ void
MemoryUsage::execute()
{
MemoryUtils::Stats stats;
MemoryUtils::getMemoryStats(stats);
MemoryUtils::getMemoryStats(stats, _mem_units);

// get the requested per core metric
switch (_mem_type)
@@ -8,6 +8,7 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "MemoryUtils.h"
#include "MooseError.h"

#include <unistd.h>
#include <mpi.h>
@@ -18,6 +19,7 @@
#include <mach/task.h>
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/vm_page_size.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
@@ -58,7 +60,7 @@ getMPIProcessorName()
}

void
getMemoryStats(Stats & stats)
getMemoryStats(Stats & stats, MemUnit units)
{
enum StatItem
{
@@ -96,17 +98,22 @@ getMemoryStats(Stats & stats)
reinterpret_cast<task_info_t>(&t_info),
&t_info_count))
{
val[index_virtual_size] = t_info.virtual_size;
val[index_resident_size] = t_info.resident_size;
val[index_virtual_size] = t_info.virtual_size; // in bytes
val[index_resident_size] = t_info.resident_size; // in bytes
}
else
mooseDoOnce(::mooseWarning("task_info call failed, memory usage numbers will be incorrect"));
#endif
}

// Create the proper divisor based on the units
const long divisor = 1 << (static_cast<unsigned int>(units) * 10);

// physical mem
stats._physical_memory = val[index_resident_size];
stats._physical_memory = val[index_resident_size] / divisor;

// virtual mem
stats._virtual_memory = val[index_virtual_size];
stats._virtual_memory = val[index_virtual_size] / divisor;

// page faults
stats._page_faults = val[index_page_faults];
@@ -26,12 +26,16 @@ validParams<VectorMemoryUsage>()
"If the vectorpostprocessor is executed more than once "
"during a time step, report the aggregated peak "
"value.");
MooseEnum mem_units("bytes kilobytes megabytes gigabytes", "megabytes");
params.addParam<MooseEnum>(
"mem_units", mem_units, "The unit used to report memory usage, default: Megabytes");
return params;
}

VectorMemoryUsage::VectorMemoryUsage(const InputParameters & parameters)
: GeneralVectorPostprocessor(parameters),
MemoryUsageReporter(this),
_mem_units(getParam<MooseEnum>("mem_units").getEnum<MemoryUtils::MemUnit>()),
_col_hardware_id(declareVector("hardware_id")),
_col_total_ram(declareVector("total_ram")),
_col_physical_mem(declareVector("physical_mem")),
@@ -69,6 +73,7 @@ VectorMemoryUsage::execute()
{
MemoryUtils::Stats stats;
MemoryUtils::getMemoryStats(stats);
MemoryUtils::getMemoryStats(stats, _mem_units);

if (_report_peak_value)
{
@@ -38,6 +38,7 @@
type = VectorMemoryUsage
execute_on = 'INITIAL TIMESTEP_END NONLINEAR LINEAR'
report_peak_value = true
mem_units = kilobytes # or bytes, megabytes, gigabytes
[../]
[]

0 comments on commit 02289fb

Please sign in to comment.