OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
memory_reporter.hpp File Reference

Memory usage reporting utilities for parallel simulations. More...

#include "openpfc/core/world.hpp"
#include "openpfc/core/world_queries.hpp"
#include "openpfc/logging.hpp"
#include "openpfc/mpi.hpp"
#include "openpfc/utils.hpp"
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <mpi.h>
#include <sstream>
#include <string>
Include dependency graph for memory_reporter.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pfc::utils::MemoryUsage
 Memory usage statistics for a single MPI rank. More...
 

Functions

size_t pfc::utils::get_system_memory_bytes () noexcept
 Attempt to read total system memory from /proc/meminfo.
 
std::string pfc::utils::format_bytes (size_t bytes)
 Format bytes as human-readable string (KB, MB, GB, TB)
 
template<typename WorldType >
void pfc::utils::report_memory_usage (const MemoryUsage &usage, const WorldType &world, const Logger &logger, MPI_Comm comm=MPI_COMM_WORLD)
 

Detailed Description

Memory usage reporting utilities for parallel simulations.

This header provides utilities for reporting memory allocation in MPI-parallel phase-field simulations. It helps track and analyze memory usage across:

  • User application data (model fields, operators)
  • FFT library workspace (HeFFTe allocations)
  • System-wide memory statistics

The reporter provides per-rank, total, and per-voxel memory metrics, helping users understand memory scaling and optimize domain decomposition.

Key Features

  • Separate reporting of application vs FFT memory
  • Global memory aggregation via MPI reduction
  • Per-voxel memory calculation for scalability analysis
  • Optional system memory detection (total available RAM)
  • Logging via OpenPFC's core logger

Usage Pattern

// After model initialization
size_t model_mem = model.get_allocated_memory_bytes();
size_t fft_mem = fft.get_allocated_memory_bytes();
pfc::utils::MemoryUsage usage{model_mem, fft_mem};
pfc::utils::report_memory_usage(usage, world, logger, MPI_COMM_WORLD);
Memory usage reporting utilities for parallel simulations.
Memory usage statistics for a single MPI rank.
Definition memory_reporter.hpp:65
Author
OpenPFC Development Team
Date
2025

Function Documentation

◆ format_bytes()

std::string pfc::utils::format_bytes ( size_t  bytes)
inline

Format bytes as human-readable string (KB, MB, GB, TB)

Parameters
bytesMemory size in bytes
Returns
Formatted string (e.g., "1.23 GB")
Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/utils/memory_reporter.hpp.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_system_memory_bytes()

size_t pfc::utils::get_system_memory_bytes ( )
inlinenoexcept

Attempt to read total system memory from /proc/meminfo.

Reads the MemTotal field from /proc/meminfo (Linux systems). Returns 0 if file cannot be read or parsed.

Returns
Total system memory in bytes, or 0 if unavailable
Note
Only works on Linux systems with /proc filesystem
Returns physical RAM, not necessarily all available to MPI
Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/utils/memory_reporter.hpp.
Here is the call graph for this function:
Here is the caller graph for this function: