| 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 zero_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, array::ArrayView<DATA_TYPE, RANK>& field, |
| 19 |
DATA_TYPE* recv_buffer, Idx... idxs) { |
| 20 |
for (idx_t i = 0; i < field.template shape<CurrentDim>(); ++i) { |
| 21 |
zero_index<ParallelDim, Cnt - 1, CurrentDim + 1>::apply(buf_idx, node_idx, field, recv_buffer, |
| 22 |
idxs..., i); |
| 23 |
} |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
template <int ParallelDim> |
| 28 |
struct zero_index<ParallelDim, 0, ParallelDim> { |
| 29 |
template <typename DATA_TYPE, int RANK, typename... Idx> |
| 30 |
ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, array::ArrayView<DATA_TYPE, RANK>& field, |
| 31 |
DATA_TYPE* recv_buffer, Idx... idxs) { |
| 32 |
field(idxs...) = 0; |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
template <int ParallelDim, int Cnt> |
| 37 |
struct zero_index<ParallelDim, Cnt, ParallelDim> { |
| 38 |
template <typename DATA_TYPE, int RANK, typename... Idx> |
| 39 |
ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, array::ArrayView<DATA_TYPE, RANK>& field, |
| 40 |
DATA_TYPE* recv_buffer, Idx... idxs) { |
| 41 |
zero_index<ParallelDim, Cnt - 1, ParallelDim + 1>::apply(buf_idx, node_idx, field, recv_buffer, idxs..., |
| 42 |
node_idx); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
template <int ParallelDim, int CurrentDim> |
| 47 |
struct zero_index<ParallelDim, 0, CurrentDim> { |
| 48 |
template <typename DATA_TYPE, int RANK, typename... Idx> |
| 49 |
ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, array::ArrayView<DATA_TYPE, RANK>& field, |
| 50 |
DATA_TYPE* recv_buffer, Idx... idxs) { |
| 51 |
field(idxs...) = 0; |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
} // namespace atlas::parallel::detail |