LCOV - code coverage report
Current view: top level - src/Communicate - Archive.h (source / functions) Coverage Total Hit
Test: report.info Lines: 42.9 % 7 3
Test Date: 2025-05-21 12:58:26 Functions: 42.9 % 7 3

            Line data    Source code
       1              : //
       2              : // Class Archive
       3              : //   Class to (de-)serialize in MPI communication.
       4              : //
       5              : //   When data is exchanged between MPI ranks, it is stored in one dimensional
       6              : //   arrays. These have the type detail::Archive, which are wrappers around
       7              : //   one dimensional Kokkos views of type char. The data is then transferred using
       8              : //   MPI send/recv calls. Note that the archive type differs from other buffers in
       9              : //   that they have type char and thus contain raw bytes, unlike other typed buffers
      10              : //   such as detail::FieldBufferData used by HaloCells.
      11              : //
      12              : #ifndef IPPL_ARCHIVE_H
      13              : #define IPPL_ARCHIVE_H
      14              : 
      15              : #include "Types/IpplTypes.h"
      16              : #include "Types/ViewTypes.h"
      17              : 
      18              : #include "Types/Vector.h"
      19              : 
      20              : namespace ippl {
      21              :     namespace detail {
      22              :         /*!
      23              :          * @file Archive.h
      24              :          * Serialize and desesrialize particle attributes.
      25              :          * @tparam Properties variadic template for Kokkos::View
      26              :          */
      27              : 
      28              :         template <class... Properties>
      29              :         class Archive {
      30              :         public:
      31              :             using buffer_type  = typename ViewType<char, 1, Properties...>::view_type;
      32              :             using pointer_type = typename buffer_type::pointer_type;
      33              : 
      34              :             Archive(size_type size = 0);
      35              : 
      36              :             /*!
      37              :              * Serialize.
      38              :              * @param view to take data from.
      39              :              */
      40              :             template <typename T, class... ViewArgs>
      41              :             void serialize(const Kokkos::View<T*, ViewArgs...>& view, size_type nsends);
      42              : 
      43              :             /*!
      44              :              * Serialize vector attributes
      45              :              *
      46              :              *\remark We need a specialized function for vectors since the vector is
      47              :              * not a trivially copyable class. Hence, we cannot use std::memcpy directly.
      48              :              *
      49              :              * @param view to take data from.
      50              :              */
      51              :             template <typename T, unsigned Dim, class... ViewArgs>
      52              :             void serialize(const Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view,
      53              :                            size_type nsends);
      54              : 
      55              :             /*!
      56              :              * Deserialize.
      57              :              * @param view to put data to
      58              :              */
      59              :             template <typename T, class... ViewArgs>
      60              :             void deserialize(Kokkos::View<T*, ViewArgs...>& view, size_type nrecvs);
      61              : 
      62              :             /*!
      63              :              * Deserialize vector attributes
      64              :              *
      65              :              * \remark We need a specialized function for vectors since the vector is
      66              :              * not a trivially copyable class. Hence, we cannot use std::memcpy directly.
      67              :              *
      68              :              * @param view to put data to
      69              :              */
      70              :             template <typename T, unsigned Dim, class... ViewArgs>
      71              :             void deserialize(Kokkos::View<Vector<T, Dim>*, ViewArgs...>& view, size_type nrecvs);
      72              : 
      73              :             /*!
      74              :              * @returns a pointer to the data of the buffer
      75              :              */
      76            0 :             pointer_type getBuffer() { return buffer_m.data(); }
      77              : 
      78              :             /*!
      79              :              * @returns the size of the buffer
      80              :              */
      81            0 :             size_type getSize() const { return writepos_m; }
      82              : 
      83          407 :             size_type getBufferSize() const { return buffer_m.size(); }
      84              : 
      85              :             void resizeBuffer(size_type size) { Kokkos::resize(buffer_m, size); }
      86              : 
      87            2 :             void reallocBuffer(size_type size) { Kokkos::realloc(buffer_m, size); }
      88              : 
      89            0 :             void resetWritePos() { writepos_m = 0; }
      90            0 :             void resetReadPos() { readpos_m = 0; }
      91              : 
      92           26 :             ~Archive() = default;
      93              : 
      94              :         private:
      95              :             //! write position for serialization
      96              :             size_type writepos_m;
      97              :             //! read position for deserialization
      98              :             size_type readpos_m;
      99              :             //! serialized data
     100              :             buffer_type buffer_m;
     101              :         };
     102              :     }  // namespace detail
     103              : }  // namespace ippl
     104              : 
     105              : #include "Archive.hpp"
     106              : 
     107              : #endif
        

Generated by: LCOV version 2.0-1