LCOV - code coverage report
Current view: top level - src/postprocessors - MemoryUsageReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 17 20 85.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14         548 : MemoryUsageReporter::MemoryUsageReporter(const MooseObject * moose_object)
      15         548 :   : _mur_communicator(moose_object->comm()),
      16         548 :     _my_rank(_mur_communicator.rank()),
      17         548 :     _nrank(_mur_communicator.size()),
      18         548 :     _hardware_id(moose_object->getMooseApp().rankMap().rankHardwareIds())
      19             : {
      20             :   // get total available ram
      21         548 :   _memory_total = MemoryUtils::getTotalRAM();
      22         548 :   if (!_memory_total)
      23           0 :     mooseWarning("Unable to query hardware memory size in ", moose_object->name());
      24             : 
      25             :   // gather all per node memory to processor zero
      26         548 :   std::vector<unsigned long long> memory_totals(_nrank);
      27         548 :   _mur_communicator.gather(0, _memory_total, memory_totals);
      28             : 
      29             :   // validate and store per node memory
      30         548 :   if (_my_rank == 0)
      31             :   {
      32         808 :     for (std::size_t i = 0; i < _nrank; ++i)
      33             :     {
      34         548 :       auto id = _hardware_id[i];
      35         548 :       if (id == _hardware_memory_total.size())
      36             :       {
      37         260 :         _hardware_memory_total.resize(id + 1);
      38         260 :         _hardware_memory_total[id] = memory_totals[i];
      39             :       }
      40         288 :       else if (_hardware_memory_total[id] != memory_totals[i])
      41           0 :         mooseWarning("Inconsistent total memory reported by ranks on the same hardware node in ",
      42           0 :                      moose_object->name());
      43             :     }
      44             :   }
      45         548 : }

Generated by: LCOV version 1.14