Debian Codegraph @

src/atlas/parallel/detail/Packer.cc

raw
1 /*
2 * (C) Copyright 2025- ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation nor
8 * does it submit to any jurisdiction.
9 */
10
11 #include "Packer.h"
12
13 #include "pack_index.h"
14 #include "adjoint_unpack_index.h"
15 #include "zero_index.h"
16
17 namespace atlas::parallel::detail {
18
19 template <int ParallelDim, typename DATA_TYPE, int RANK>
20 void HostPacker<ParallelDim,DATA_TYPE,RANK>::pack(const int sendcnt, array::SVector<int> const& sendmap,
21 const array::ArrayView<DATA_TYPE, RANK>& array, DATA_TYPE* send_buffer, int /*send_buffer_size*/) {
22 idx_t ibuf = 0;
23 for (int node_cnt = 0; node_cnt < sendcnt; ++node_cnt) {
24 const idx_t node_idx = sendmap[node_cnt];
25 pack_index<ParallelDim, RANK, 0>::apply(ibuf, node_idx, array, send_buffer);
26 }
27 }
28
29 template <int ParallelDim, typename DATA_TYPE, int RANK>
30 void HostPacker<ParallelDim,DATA_TYPE,RANK>::unpack(const int recvcnt, array::SVector<int> const& recvmap, const DATA_TYPE* recv_buffer,
31 int /*recv_buffer_size*/, array::ArrayView<DATA_TYPE, RANK>& array) {
32 idx_t ibuf = 0;
33 for (int node_cnt = 0; node_cnt < recvcnt; ++node_cnt) {
34 const idx_t node_idx = recvmap[node_cnt];
35 unpack_index<ParallelDim, RANK, 0>::apply(ibuf, node_idx, recv_buffer, array);
36 }
37 }
38
39 template <int ParallelDim, typename DATA_TYPE, int RANK>
40 void HostAdjointPacker<ParallelDim,DATA_TYPE,RANK>::unpack(const int recvcnt, array::SVector<int> const& recvmap, const DATA_TYPE* recv_buffer,
41 int /*recv_buffer_size*/, array::ArrayView<DATA_TYPE, RANK>& array) {
42 idx_t ibuf = 0;
43 for (int node_cnt = 0; node_cnt < recvcnt; ++node_cnt) {
44 const idx_t node_idx = recvmap[node_cnt];
45 adjoint_unpack_index<ParallelDim, RANK, 0>::apply(ibuf, node_idx, recv_buffer, array);
46 }
47 }
48
49 template <int ParallelDim, typename DATA_TYPE, int RANK>
50 void HostZeroer<ParallelDim,DATA_TYPE,RANK>::zero(const int sendcnt, array::SVector<int> const& sendmap, array::ArrayView<DATA_TYPE, RANK>& array,
51 DATA_TYPE* recv_buffer, int recv_buffer_size) {
52 idx_t ibuf = 0;
53 for (int node_cnt = 0; node_cnt < sendcnt; ++node_cnt) {
54 const idx_t node_idx = sendmap[node_cnt];
55 zero_index<ParallelDim, RANK, 0>::apply(ibuf, node_idx, array, recv_buffer);
56 }
57 }
58
59 #define ATLAS_REPEAT_MACRO(n, m, p) ATLAS_REPEAT_MACRO_ ## n(m, p)
60 // expands to m(0,p) m(1,p) ... m(n-1,p)
61
62 #define ATLAS_REPEAT_MACRO_0(m, p)
63 #define ATLAS_REPEAT_MACRO_1(m, p) ATLAS_REPEAT_MACRO_0(m, p) m(0, p)
64 #define ATLAS_REPEAT_MACRO_2(m, p) ATLAS_REPEAT_MACRO_1(m, p) m(1, p)
65 #define ATLAS_REPEAT_MACRO_3(m, p) ATLAS_REPEAT_MACRO_2(m, p) m(2, p)
66 #define ATLAS_REPEAT_MACRO_4(m, p) ATLAS_REPEAT_MACRO_3(m, p) m(3, p)
67 #define ATLAS_REPEAT_MACRO_5(m, p) ATLAS_REPEAT_MACRO_4(m, p) m(4, p)
68 #define ATLAS_REPEAT_MACRO_6(m, p) ATLAS_REPEAT_MACRO_5(m, p) m(5, p)
69
70
71 #define EXPLICIT_TEMPLATE_INSTANTIATION( ParallelDim, RANK ) \
72 template struct HostPacker<ParallelDim, int, RANK>; \
73 template struct HostPacker<ParallelDim, long, RANK>; \
74 template struct HostPacker<ParallelDim, long unsigned, RANK>; \
75 template struct HostPacker<ParallelDim, float, RANK>; \
76 template struct HostPacker<ParallelDim, double, RANK>; \
77 template struct HostAdjointPacker<ParallelDim, int, RANK>; \
78 template struct HostAdjointPacker<ParallelDim, long, RANK>; \
79 template struct HostAdjointPacker<ParallelDim, long unsigned, RANK>; \
80 template struct HostAdjointPacker<ParallelDim, float, RANK>; \
81 template struct HostAdjointPacker<ParallelDim, double, RANK>; \
82 template struct HostZeroer<ParallelDim, int, RANK>; \
83 template struct HostZeroer<ParallelDim, long, RANK>; \
84 template struct HostZeroer<ParallelDim, long unsigned, RANK>; \
85 template struct HostZeroer<ParallelDim, float, RANK>; \
86 template struct HostZeroer<ParallelDim, double, RANK>;
87
88 #define EXPLICIT_TEMPLATE_INSTANTIATION_RANK(RANK) \
89 ATLAS_REPEAT_MACRO(RANK, EXPLICIT_TEMPLATE_INSTANTIATION, RANK)
90
91 EXPLICIT_TEMPLATE_INSTANTIATION_RANK(1)
92 EXPLICIT_TEMPLATE_INSTANTIATION_RANK(2)
93 EXPLICIT_TEMPLATE_INSTANTIATION_RANK(3)
94 EXPLICIT_TEMPLATE_INSTANTIATION_RANK(4)
95 EXPLICIT_TEMPLATE_INSTANTIATION_RANK(5)
96
97 } //namespace atlas::array::detail