/* * (C) Copyright 2025- ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation nor * does it submit to any jurisdiction. */ #include "Packer.h" #include "pack_index.h" #include "adjoint_unpack_index.h" #include "zero_index.h" namespace atlas::parallel::detail { template void HostPacker::pack(const int sendcnt, array::SVector const& sendmap, const array::ArrayView& array, DATA_TYPE* send_buffer, int /*send_buffer_size*/) { idx_t ibuf = 0; for (int node_cnt = 0; node_cnt < sendcnt; ++node_cnt) { const idx_t node_idx = sendmap[node_cnt]; pack_index::apply(ibuf, node_idx, array, send_buffer); } } template void HostPacker::unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int /*recv_buffer_size*/, array::ArrayView& array) { idx_t ibuf = 0; for (int node_cnt = 0; node_cnt < recvcnt; ++node_cnt) { const idx_t node_idx = recvmap[node_cnt]; unpack_index::apply(ibuf, node_idx, recv_buffer, array); } } template void HostAdjointPacker::unpack(const int recvcnt, array::SVector const& recvmap, const DATA_TYPE* recv_buffer, int /*recv_buffer_size*/, array::ArrayView& array) { idx_t ibuf = 0; for (int node_cnt = 0; node_cnt < recvcnt; ++node_cnt) { const idx_t node_idx = recvmap[node_cnt]; adjoint_unpack_index::apply(ibuf, node_idx, recv_buffer, array); } } template void HostZeroer::zero(const int sendcnt, array::SVector const& sendmap, array::ArrayView& array, DATA_TYPE* recv_buffer, int recv_buffer_size) { idx_t ibuf = 0; for (int node_cnt = 0; node_cnt < sendcnt; ++node_cnt) { const idx_t node_idx = sendmap[node_cnt]; zero_index::apply(ibuf, node_idx, array, recv_buffer); } } #define ATLAS_REPEAT_MACRO(n, m, p) ATLAS_REPEAT_MACRO_ ## n(m, p) // expands to m(0,p) m(1,p) ... m(n-1,p) #define ATLAS_REPEAT_MACRO_0(m, p) #define ATLAS_REPEAT_MACRO_1(m, p) ATLAS_REPEAT_MACRO_0(m, p) m(0, p) #define ATLAS_REPEAT_MACRO_2(m, p) ATLAS_REPEAT_MACRO_1(m, p) m(1, p) #define ATLAS_REPEAT_MACRO_3(m, p) ATLAS_REPEAT_MACRO_2(m, p) m(2, p) #define ATLAS_REPEAT_MACRO_4(m, p) ATLAS_REPEAT_MACRO_3(m, p) m(3, p) #define ATLAS_REPEAT_MACRO_5(m, p) ATLAS_REPEAT_MACRO_4(m, p) m(4, p) #define ATLAS_REPEAT_MACRO_6(m, p) ATLAS_REPEAT_MACRO_5(m, p) m(5, p) #define EXPLICIT_TEMPLATE_INSTANTIATION( ParallelDim, RANK ) \ template struct HostPacker; \ template struct HostPacker; \ template struct HostPacker; \ template struct HostPacker; \ template struct HostPacker; \ template struct HostAdjointPacker; \ template struct HostAdjointPacker; \ template struct HostAdjointPacker; \ template struct HostAdjointPacker; \ template struct HostAdjointPacker; \ template struct HostZeroer; \ template struct HostZeroer; \ template struct HostZeroer; \ template struct HostZeroer; \ template struct HostZeroer; #define EXPLICIT_TEMPLATE_INSTANTIATION_RANK(RANK) \ ATLAS_REPEAT_MACRO(RANK, EXPLICIT_TEMPLATE_INSTANTIATION, RANK) EXPLICIT_TEMPLATE_INSTANTIATION_RANK(1) EXPLICIT_TEMPLATE_INSTANTIATION_RANK(2) EXPLICIT_TEMPLATE_INSTANTIATION_RANK(3) EXPLICIT_TEMPLATE_INSTANTIATION_RANK(4) EXPLICIT_TEMPLATE_INSTANTIATION_RANK(5) } //namespace atlas::array::detail