SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Actions/MemoryMonitor - ProcessArray.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 33.3 % 3 1
Test Date: 2026-10-22 17:29:42
Legend: Lines:     hit not hit

            Line data    Source code
       1            0 : // Distributed under the MIT License.
       2              : // See LICENSE.txt for details.
       3              : 
       4              : #pragma once
       5              : 
       6              : #include <string>
       7              : #include <tuple>
       8              : #include <vector>
       9              : 
      10              : #include "DataStructures/DataBox/DataBox.hpp"
      11              : #include "IO/Observer/ObserverComponent.hpp"
      12              : #include "IO/Observer/ReductionActions.hpp"
      13              : #include "Parallel/GlobalCache.hpp"
      14              : #include "Parallel/Invoke.hpp"
      15              : #include "Utilities/GetOutput.hpp"
      16              : #include "Utilities/Numeric.hpp"
      17              : 
      18              : namespace mem_monitor {
      19              : /*!
      20              :  * \brief Simple action meant to be used as a callback for
      21              :  * Parallel::contribute_to_reduction that writes the size of an Array parallel
      22              :  * component to disk.
      23              :  *
      24              :  * \details The columns in the dat file when running on 3 nodes will be
      25              :  *
      26              :  * - %Time
      27              :  * - Size on node 0 (MB)
      28              :  * - Size on node 1 (MB)
      29              :  * - Size on node 2 (MB)
      30              :  * - Average size per node (MB)
      31              :  *
      32              :  * The dat file will be placed in the `/MemoryMonitors/` group in the reduction
      33              :  * file. The name of the dat file is the `pretty_type::name` of the component.
      34              :  */
      35              : template <typename ArrayComponent>
      36            1 : struct ProcessArray {
      37              :   template <typename ParallelComponent, typename DbTags, typename Metavariables,
      38              :             typename ArrayIndex>
      39            0 :   static void apply(db::DataBox<DbTags>& /*box*/,
      40              :                     Parallel::GlobalCache<Metavariables>& cache,
      41              :                     const ArrayIndex& /*array_index*/, const double time,
      42              :                     const std::vector<double>& size_per_node) {
      43              :     auto& observer_writer_proxy = Parallel::get_parallel_component<
      44              :         observers::ObserverWriter<Metavariables>>(cache);
      45              : 
      46              :     std::vector<std::string> legend{{"Time"}};
      47              :     for (size_t i = 0; i < size_per_node.size(); i++) {
      48              :       legend.emplace_back("Size on node " + get_output(i) + " (MB)");
      49              :     }
      50              :     legend.emplace_back("Average size per node (MB)");
      51              : 
      52              :     const double avg_size = alg::accumulate(size_per_node, 0.0) /
      53              :                             static_cast<double>(size_per_node.size());
      54              : 
      55              :     Parallel::threaded_action<
      56              :         observers::ThreadedActions::WriteReductionDataRow>(
      57              :         // Node 0 is always the writer
      58              :         observer_writer_proxy[0], subfile_name<ArrayComponent>(), legend,
      59              :         std::make_tuple(time, size_per_node, avg_size));
      60              :   }
      61              : };
      62              : }  // namespace mem_monitor
        

Generated by: LCOV version 2.0-1