Xyst test code coverage report
Current view: top level - Inciter - PartsReducer.cpp (source / functions) Hit Total Coverage
Commit: 5689ba12dc66a776d3d75f1ee48cc7d78eaa18dc Lines: 10 10 100.0 %
Date: 2024-11-22 19:02:53 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 18 61.1 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Inciter/PartsReducer.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.,
       7                 :            :              2022-2024 J. Bakosi
       8                 :            :              All rights reserved. See the LICENSE file for details.
       9                 :            :   \brief     Custom Charm++ reducer for merging mesh part assignments across PEs
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include "PartsReducer.hpp"
      14                 :            : #include "Exception.hpp"
      15                 :            : 
      16                 :            : namespace tk {
      17                 :            : 
      18                 :            : std::pair< int, std::unique_ptr<char[]> >
      19         [ +  - ]:         20 : serialize(
      20                 :            :   const std::unordered_map< std::size_t, std::size_t >& d )
      21                 :            : // *****************************************************************************
      22                 :            : // Serialize diagnostics to raw memory stream
      23                 :            : //! \param[in] d Mesh graph to aggregate
      24                 :            : //! \return Pair of the length and the raw stream containing the serialized data
      25                 :            : // *****************************************************************************
      26                 :            : {
      27                 :            :   // Prepare for serializing diagnostics to a raw binary stream, compute size
      28                 :            :   PUP::sizer sizer;
      29                 :            :   sizer | const_cast< std::unordered_map< std::size_t, std::size_t >& >( d );
      30                 :            : 
      31                 :            :   // Create raw character stream to store the serialized vectors
      32                 :            :   std::unique_ptr<char[]> flatData = std::make_unique<char[]>( sizer.size() );
      33                 :            : 
      34                 :            :   // Serialize vector, each message will contain graph
      35                 :            :   PUP::toMem packer( flatData.get() );
      36                 :            :   packer | const_cast< std::unordered_map< std::size_t, std::size_t >& >( d );
      37                 :            : 
      38                 :            :   // Return size of and raw stream
      39                 :         20 :   return { sizer.size(), std::move(flatData) };
      40                 :            : }
      41                 :            : 
      42                 :            : CkReductionMsg*
      43         [ +  - ]:          4 : mergeParts( int nmsg, CkReductionMsg **msgs )
      44                 :            : // *****************************************************************************
      45                 :            : // Charm++ custom reducer for merging mesh graphs during reduction across PEs
      46                 :            : //! \param[in] nmsg Number of messages in msgs
      47                 :            : //! \param[in] msgs Charm++ reduction message containing serialized data
      48                 :            : //! \return Aggregated diagnostics built for further aggregation if needed
      49                 :            : // *****************************************************************************
      50                 :            : {
      51                 :            :   // Will store deserialized mesh graph
      52                 :            :   std::unordered_map< std::size_t, std::size_t > v;
      53                 :            : 
      54                 :            :   // Create PUP deserializer based on message passed in
      55         [ +  - ]:          4 :   PUP::fromMem creator( msgs[0]->getData() );
      56                 :            : 
      57                 :            :   // Deserialize from raw stream
      58                 :            :   // cppcheck-suppress uninitvar
      59                 :            :   creator | v;
      60                 :            : 
      61         [ +  + ]:         14 :   for (int m=1; m<nmsg; ++m) {
      62                 :            :     // Unpack graph
      63                 :            :     std::unordered_map< std::size_t, std::size_t > w;
      64         [ +  - ]:         10 :     PUP::fromMem curCreator( msgs[m]->getData() );
      65                 :            :     // cppcheck-suppress uninitvar
      66                 :            :     curCreator | w;
      67                 :            :     // Aggregate
      68         [ +  + ]:       3839 :     for (const auto& [g,p] : w) {
      69                 :            :       Assert( v.find(g) == end(v), "Conflicting partition assignments" );
      70         [ +  - ]:       3829 :       v[g] = p;
      71                 :            :     }
      72                 :            :   }
      73                 :            : 
      74                 :            :   // Serialize concatenated diagnostics vector to raw stream
      75         [ +  - ]:          4 :   auto stream = tk::serialize( v );
      76                 :            : 
      77                 :            :   // Forward serialized diagnostics
      78         [ +  - ]:          8 :   return CkReductionMsg::buildNew( stream.first, stream.second.get() );
      79                 :            : }
      80                 :            : 
      81                 :            : } // tk::

Generated by: LCOV version 1.16