Debian Codegraph @

src/atlas/parallel/detail/adjoint_unpack_index.h

raw
1 /*
2 * (C) British Crown Copyright 2020 Met Office
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 */
7
8 #pragma once
9
10 #include "atlas/array/ArrayView.h"
11 #include "atlas/array/SVector.h"
12
13 namespace atlas::parallel::detail {
14
15 template <int ParallelDim, int Cnt, int CurrentDim>
16 struct adjoint_unpack_index {
17 template <typename DATA_TYPE, int RANK, typename... Idx>
18 ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer,
19 array::ArrayView<DATA_TYPE, RANK>& field, Idx... idxs) {
20 for (idx_t i = 0; i < field.template shape<CurrentDim>(); ++i) {
21 adjoint_unpack_index<ParallelDim, Cnt - 1, CurrentDim + 1>::apply(buf_idx, node_idx, recv_buffer,
22 field, idxs..., i);
23 }
24 }
25 };
26
27
28 template <int ParallelDim>
29 struct adjoint_unpack_index<ParallelDim, 0, ParallelDim> {
30 template <typename DATA_TYPE, int RANK, typename... Idx>
31 ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer,
32 array::ArrayView<DATA_TYPE, RANK>& field, Idx... idxs) {
33 field(idxs...) += recv_buffer[buf_idx++];
34 }
35 };
36
37 template <int ParallelDim, int Cnt>
38 struct adjoint_unpack_index<ParallelDim, Cnt, ParallelDim> {
39 template <typename DATA_TYPE, int RANK, typename... Idx>
40 ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer,
41 array::ArrayView<DATA_TYPE, RANK>& field, Idx... idxs) {
42 adjoint_unpack_index<ParallelDim, Cnt - 1, ParallelDim + 1>::apply(buf_idx, node_idx, recv_buffer, field,
43 idxs..., node_idx);
44 }
45 };
46
47 template <int ParallelDim, int CurrentDim>
48 struct adjoint_unpack_index<ParallelDim, 0, CurrentDim> {
49 template <typename DATA_TYPE, int RANK, typename... Idx>
50 ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer,
51 array::ArrayView<DATA_TYPE, RANK>& field, Idx... idxs) {
52 field(idxs...) += recv_buffer[buf_idx++];
53 }
54 };
55
56 } // namespace atlas::parallel::detail