LCOV - code coverage report
Current view: top level - include/kokkos/reporters - KokkosElementStatistics.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 24 24 100.0 %
Date: 2026-05-29 20:35:17 Functions: 3 3 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             : #pragma once
      11             : 
      12             : #include "KokkosElementReporter.h"
      13             : 
      14             : class KokkosElementStatistics : public Moose::Kokkos::ElementReporter
      15             : {
      16             : public:
      17             :   static InputParameters validParams();
      18             : 
      19             :   KokkosElementStatistics(const InputParameters & parameters);
      20             : 
      21             :   template <typename Derived>
      22             :   KOKKOS_FUNCTION void reduce(Datum & datum, Real * result) const;
      23             : 
      24             :   template <typename Derived>
      25             :   KOKKOS_FUNCTION void join(Real * result, const Real * source) const;
      26             :   template <typename Derived>
      27             :   KOKKOS_FUNCTION void init(Real * result) const;
      28             : 
      29             : protected:
      30             :   virtual void initialize() override;
      31             :   virtual void finalize() override;
      32             : 
      33             : private:
      34             :   const std::string _base_name;
      35             :   Real & _max;
      36             :   Real & _min;
      37             :   Real & _average;
      38             :   Real & _integral;
      39             :   unsigned int & _number_elements;
      40             : };
      41             : 
      42             : template <typename Derived>
      43             : KOKKOS_FUNCTION void
      44         600 : KokkosElementStatistics::reduce(Datum & datum, Real * result) const
      45             : {
      46             :   // Get value to to update statistics
      47         600 :   auto [value, volume] = static_cast<const Derived *>(this)->computeValue(datum);
      48             : 
      49         600 :   if (result[0] < value)
      50          80 :     result[0] = value;
      51             : 
      52         600 :   if (result[1] > value)
      53          13 :     result[1] = value;
      54             : 
      55         600 :   result[2] += value * volume;
      56             : 
      57             :   // Update the total and the number to get the average when "finalizing"
      58         600 :   result[3] += value;
      59         600 :   result[4]++;
      60         600 : }
      61             : 
      62             : template <typename Derived>
      63             : KOKKOS_FUNCTION void
      64           1 : KokkosElementStatistics::join(Real * result, const Real * source) const
      65             : {
      66           1 :   result[0] = Kokkos::max(result[0], source[0]);
      67           1 :   result[1] = Kokkos::min(result[1], source[1]);
      68           1 :   result[2] += source[2];
      69           1 :   result[3] += source[3];
      70           1 :   result[4] += source[4];
      71           1 : }
      72             : 
      73             : template <typename Derived>
      74             : KOKKOS_FUNCTION void
      75           9 : KokkosElementStatistics::init(Real * result) const
      76             : {
      77           9 :   result[0] = Kokkos::Experimental::finite_min_v<Real>;
      78           9 :   result[1] = Kokkos::Experimental::finite_max_v<Real>;
      79           9 :   result[2] = 0;
      80           9 :   result[3] = 0;
      81           9 :   result[4] = 0;
      82           9 : }

Generated by: LCOV version 1.14