Xyst test code coverage report
Current view: top level - Inciter - PartsReducer.cpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 100.0 % 10 10
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/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-2025 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         [ +  - ]:          23 : serialize(
      20                 :             :   const std::unordered_map< std::size_t, std::size_t >& d )
      21                 :             : // *****************************************************************************
      22                 :             : // Serialize parts 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 parts 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 parts
      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                 :          23 :   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 parts 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         [ +  + ]:        2133 :     for (const auto& [g,p] : w) {
      69                 :             :       Assert( v.find(g) == end(v), "Conflicting partition assignments" );
      70         [ +  - ]:        2123 :       v[g] = p;
      71                 :             :     }
      72                 :             :   }
      73                 :             : 
      74                 :             :   // Serialize concatenated parts to raw stream
      75         [ +  - ]:           4 :   auto stream = tk::serialize( v );
      76                 :             : 
      77                 :             :   // Forward serialized parts
      78         [ +  - ]:           8 :   return CkReductionMsg::buildNew( stream.first, stream.second.get() );
      79                 :             : }
      80                 :             : 
      81                 :             : } // tk::
        

Generated by: LCOV version 2.0-1