Xyst test code coverage report
Current view: top level - Statistics - PDFReducer.cpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 100.0 % 12 12
Test Date: 2025-08-13 22:18:46 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 61.1 % 18 11

             Branch data     Line data    Source code
       1                 :             : // *****************************************************************************
       2                 :             : /*!
       3                 :             :   \file      src/Statistics/PDFReducer.cpp
       4                 :             :   \copyright 2012-2015 J. Bakosi,
       5                 :             :              2016-2018 Los Alamos National Security, LLC.,
       6                 :             :              2019-2021 Triad National Security, LLC.,
       7                 :             :              2022-2025 J. Bakosi
       8                 :             :              All rights reserved. See the LICENSE file for details.
       9                 :             :   \brief     Custom Charm++ reducer for merging PDFs across PEs
      10                 :             :   \details   Custom Charm++ reducer for merging PDFs across PEs.
      11                 :             : */
      12                 :             : // *****************************************************************************
      13                 :             : 
      14                 :             : #include "PDFReducer.hpp"
      15                 :             : 
      16                 :             : namespace tk {
      17                 :             : 
      18                 :             : std::pair< int, std::unique_ptr<char[]> >
      19         [ +  - ]:        3060 : serialize( std::size_t meshid, const std::vector< tk::UniPDF >& u )
      20                 :             : // *****************************************************************************
      21                 :             : // Serialize univariate PDFs to raw memory stream
      22                 :             : //! \param[in] meshid Mesh ID
      23                 :             : //! \param[in] u Univariate PDFs
      24                 :             : //! \return Pair of the length and the raw stream containing the serialized PDFs
      25                 :             : // *****************************************************************************
      26                 :             : {
      27                 :             :   // Prepare for serializing PDF to a raw binary stream, compute size
      28                 :             :   PUP::sizer sizer;
      29                 :             :   // cppcheck-suppress uninitvar
      30                 :             :   sizer | meshid;
      31                 :             :   sizer | const_cast< std::vector< tk::UniPDF >& >( u );
      32                 :             : 
      33                 :             :   // Create raw character stream to store the serialized PDF
      34                 :             :   std::unique_ptr<char[]> flatData = std::make_unique<char[]>( sizer.size() );
      35                 :             : 
      36                 :             :   // Serialize PDF, the message will contain a univariate PDF
      37                 :             :   PUP::toMem packer( flatData.get() );
      38                 :             :   // cppcheck-suppress uninitvar
      39                 :             :   packer | meshid;
      40                 :             :   packer | const_cast< std::vector< tk::UniPDF >& >( u );
      41                 :             : 
      42                 :             :   // Return size of and raw stream
      43                 :        3060 :   return { sizer.size(), std::move(flatData) };
      44                 :             : }
      45                 :             : 
      46                 :             : CkReductionMsg*
      47         [ +  - ]:         484 : mergeUniPDFs( int nmsg, CkReductionMsg **msgs )
      48                 :             : // *****************************************************************************
      49                 :             : // Charm++ custom reducer for merging a univariate PDFs during reduction across
      50                 :             : // PEs
      51                 :             : //! \param[in] nmsg Number of messages in msgs
      52                 :             : //! \param[in] msgs Charm++ reduction message containing the serialized PDF
      53                 :             : //! \return Aggregated PDF built for further aggregation if needed
      54                 :             : // *****************************************************************************
      55                 :             : {
      56                 :             :   // Will store deserialized univariate PDFs
      57                 :             :   std::size_t meshid;
      58                 :             :   std::vector< tk::UniPDF > updf;
      59                 :             : 
      60                 :             :   // Create PUP deserializer based on message passed in
      61         [ +  - ]:         484 :   PUP::fromMem creator( msgs[0]->getData() );
      62                 :             : 
      63                 :             :   // Deserialize PDFs from raw stream
      64                 :             :   // cppcheck-suppress uninitvar
      65                 :             :   creator | meshid;
      66                 :             :   creator | updf;
      67                 :             : 
      68         [ +  + ]:        2805 :   for (int m=1; m<nmsg; ++m) {
      69                 :             :     // Unpack PDF
      70                 :             :     std::size_t mid;
      71                 :             :     std::vector< tk::UniPDF > u;
      72         [ +  - ]:        2321 :     PUP::fromMem curCreator( msgs[m]->getData() );
      73                 :             :     // cppcheck-suppress uninitvar
      74                 :             :     curCreator | mid;
      75                 :             :     curCreator | u;
      76                 :             :     // Merge PDFs
      77                 :             :     // cppcheck-suppress uninitvar
      78                 :        2321 :     meshid = mid;
      79                 :             :     std::size_t i = 0;
      80                 :             :     // cppcheck-suppress knownEmptyContainer
      81                 :             :     // cppcheck-suppress containerOutOfBounds
      82 [ +  - ][ +  + ]:        9284 :     for (const auto& p : u) updf[i++].addPDF( p );
      83                 :        2321 :   }
      84                 :             : 
      85                 :             :   // Serialize vector of merged PDF to raw stream
      86                 :             :   // cppcheck-suppress uninitvar
      87         [ +  - ]:         484 :   auto stream = tk::serialize( meshid, updf );
      88                 :             : 
      89                 :             :   // Forward serialized PDFs
      90         [ +  - ]:         968 :   return CkReductionMsg::buildNew( stream.first, stream.second.get() );
      91                 :         484 : }
      92                 :             : 
      93                 :             : } // tk::
        

Generated by: LCOV version 2.0-1