Quinoa all test code coverage report
Current view: top level - Statistics - PDFReducer.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 13 31 41.9 %
Date: 2024-04-29 14:42:33 Functions: 2 4 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 40 25.0 %

           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                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Custom Charm++ reducer for merging PDFs across PEs
       9                 :            :   \details   Custom Charm++ reducer for merging PDFs across PEs.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include <memory>
      14                 :            : 
      15                 :            : #include "PDFReducer.hpp"
      16                 :            : 
      17                 :            : namespace tk {
      18                 :            : 
      19                 :            : std::pair< int, std::unique_ptr<char[]> >
      20                 :       2326 : serialize( std::size_t meshid, const std::vector< tk::UniPDF >& u )
      21                 :            : // *****************************************************************************
      22                 :            : // Serialize univariate PDFs to raw memory stream
      23                 :            : //! \param[in] meshid Mesh ID
      24                 :            : //! \param[in] u Univariate PDFs
      25                 :            : //! \return Pair of the length and the raw stream containing the serialized PDFs
      26                 :            : // *****************************************************************************
      27                 :            : {
      28                 :            :   // Prepare for serializing PDF to a raw binary stream, compute size
      29                 :       2326 :   PUP::sizer sizer;
      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                 :            :   packer | meshid;
      39                 :            :   packer | const_cast< std::vector< tk::UniPDF >& >( u );
      40                 :            : 
      41                 :            :   // Return size of and raw stream
      42                 :       2326 :   return { sizer.size(), std::move(flatData) };
      43                 :            : }
      44                 :            : 
      45                 :            : CkReductionMsg*
      46         [ +  - ]:        332 : mergeUniPDFs( int nmsg, CkReductionMsg **msgs )
      47                 :            : // *****************************************************************************
      48                 :            : // Charm++ custom reducer for merging a univariate PDFs during reduction across
      49                 :            : // PEs
      50                 :            : //! \param[in] nmsg Number of messages in msgs
      51                 :            : //! \param[in] msgs Charm++ reduction message containing the serialized PDF
      52                 :            : //! \return Aggregated PDF built for further aggregation if needed
      53                 :            : // *****************************************************************************
      54                 :            : {
      55                 :            :   // Will store deserialized univariate PDFs
      56                 :            :   std::size_t meshid;
      57                 :        332 :   std::vector< tk::UniPDF > updf;
      58                 :            : 
      59                 :            :   // Create PUP deserializer based on message passed in
      60         [ +  - ]:        332 :   PUP::fromMem creator( msgs[0]->getData() );
      61                 :            : 
      62                 :            :   // Deserialize PDFs from raw stream
      63                 :            :   creator | meshid;
      64                 :            :   creator | updf;
      65                 :            : 
      66         [ +  + ]:       2131 :   for (int m=1; m<nmsg; ++m) {
      67                 :            :     // Unpack PDF
      68                 :            :     std::size_t mid;
      69                 :       1799 :     std::vector< tk::UniPDF > u;
      70         [ +  - ]:       1799 :     PUP::fromMem curCreator( msgs[m]->getData() );
      71                 :            :     curCreator | mid;
      72                 :            :     curCreator | u;
      73                 :            :     // Merge PDFs
      74                 :       1799 :     meshid = mid;
      75                 :            :     std::size_t i = 0;
      76 [ +  + ][ +  - ]:       7196 :     for (const auto& p : u) updf[i++].addPDF( p );
      77                 :            :   }
      78                 :            : 
      79                 :            :   // Serialize vector of merged PDF to raw stream
      80         [ +  - ]:        332 :   auto stream = tk::serialize( meshid, updf );
      81                 :            : 
      82                 :            :   // Forward serialized PDFs
      83         [ +  - ]:        664 :   return CkReductionMsg::buildNew( stream.first, stream.second.get() );
      84                 :            : }
      85                 :            : 
      86                 :            : std::pair< int, std::unique_ptr<char[]> >
      87                 :          0 : serialize( const std::vector< tk::UniPDF >& u,
      88                 :            :            const std::vector< tk::BiPDF >& b,
      89                 :            :            const std::vector< tk::TriPDF >& t )
      90                 :            : // *****************************************************************************
      91                 :            : // Serialize vectors of PDFs to raw memory stream
      92                 :            : //! \param[in] u Vector of univariate PDFs
      93                 :            : //! \param[in] b Vector of bivariate PDFs
      94                 :            : //! \param[in] t Vector of trivariate PDFs
      95                 :            : //! \return Pair of the length and the raw stream containing the serialized PDFs
      96                 :            : // *****************************************************************************
      97                 :            : {
      98                 :            :   // Prepare for serializing PDFs to a raw binary stream, compute size
      99                 :          0 :   PUP::sizer sizer;
     100                 :            :   sizer | const_cast< std::vector< tk::UniPDF >& >( u );
     101                 :            :   sizer | const_cast< std::vector< tk::BiPDF >& >( b );
     102                 :            :   sizer | const_cast< std::vector< tk::TriPDF >& >( t );
     103                 :            : 
     104                 :            :   // Create raw character stream to store the serialized PDFs
     105                 :            :   std::unique_ptr<char[]> flatData = std::make_unique<char[]>( sizer.size() );
     106                 :            : 
     107                 :            :   // Serialize PDFs, each message will contain a vector of PDFs
     108                 :            :   PUP::toMem packer( flatData.get() );
     109                 :            :   packer | const_cast< std::vector< tk::UniPDF >& >( u );
     110                 :            :   packer | const_cast< std::vector< tk::BiPDF >& >( b );
     111                 :            :   packer | const_cast< std::vector< tk::TriPDF >& >( t );
     112                 :            : 
     113                 :            :   // Return size of and raw stream
     114                 :          0 :   return { sizer.size(), std::move(flatData) };
     115                 :            : }
     116                 :            : 
     117                 :            : CkReductionMsg*
     118         [ -  - ]:          0 : mergePDF( int nmsg, CkReductionMsg **msgs )
     119                 :            : // *****************************************************************************
     120                 :            : // Charm++ custom reducer for merging PDFs during reduction across PEs
     121                 :            : //! \param[in] nmsg Number of messages in msgs
     122                 :            : //! \param[in] msgs Charm++ reduction message containing the serialized PDFs
     123                 :            : //! \return Aggregated PDFs built for further aggregation if needed
     124                 :            : // *****************************************************************************
     125                 :            : {
     126                 :            :   // Will store deserialized uni-, bi-, and tri-variate PDFs
     127                 :          0 :   std::vector< tk::UniPDF > updf;
     128                 :          0 :   std::vector< tk::BiPDF > bpdf;
     129                 :          0 :   std::vector< tk::TriPDF > tpdf;
     130                 :            : 
     131                 :            :   // Create PUP deserializer based on message passed in
     132         [ -  - ]:          0 :   PUP::fromMem creator( msgs[0]->getData() );
     133                 :            : 
     134                 :            :   // Deserialize PDFs from raw stream
     135                 :            :   creator | updf;
     136                 :            :   creator | bpdf;
     137                 :            :   creator | tpdf;
     138                 :            : 
     139         [ -  - ]:          0 :   for (int m=1; m<nmsg; ++m) {
     140                 :            :     // Unpack PDFs
     141                 :          0 :     std::vector< tk::UniPDF > u;
     142                 :          0 :     std::vector< tk::BiPDF > b;
     143                 :          0 :     std::vector< tk::TriPDF > t;
     144         [ -  - ]:          0 :     PUP::fromMem curCreator( msgs[m]->getData() );
     145                 :            :     curCreator | u;
     146                 :            :     curCreator | b;
     147                 :            :     curCreator | t;
     148                 :            :     // Merge PDFs
     149                 :            :     std::size_t i = 0;
     150 [ -  - ][ -  - ]:          0 :     for (const auto& p : u) updf[i++].addPDF( p );
     151                 :            :     i = 0;
     152 [ -  - ][ -  - ]:          0 :     for (const auto& p : b) bpdf[i++].addPDF( p );
     153                 :            :     i = 0;
     154 [ -  - ][ -  - ]:          0 :     for (const auto& p : t) tpdf[i++].addPDF( p );
     155                 :            :   }
     156                 :            : 
     157                 :            :   // Serialize vector of merged PDFs to raw stream
     158         [ -  - ]:          0 :   auto stream = tk::serialize( updf, bpdf, tpdf );
     159                 :            : 
     160                 :            :   // Forward serialized PDFs
     161         [ -  - ]:          0 :   return CkReductionMsg::buildNew( stream.first, stream.second.get() );
     162                 :            : }
     163                 :            : 
     164                 :            : } // tk::

Generated by: LCOV version 1.14