/* * (C) British Crown Copyright 2020 Met Office * * 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. */ #pragma once #include "atlas/array/ArrayView.h" #include "atlas/array/SVector.h" namespace atlas::parallel::detail { template struct adjoint_unpack_index { template ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer, array::ArrayView& field, Idx... idxs) { for (idx_t i = 0; i < field.template shape(); ++i) { adjoint_unpack_index::apply(buf_idx, node_idx, recv_buffer, field, idxs..., i); } } }; template struct adjoint_unpack_index { template ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer, array::ArrayView& field, Idx... idxs) { field(idxs...) += recv_buffer[buf_idx++]; } }; template struct adjoint_unpack_index { template ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer, array::ArrayView& field, Idx... idxs) { adjoint_unpack_index::apply(buf_idx, node_idx, recv_buffer, field, idxs..., node_idx); } }; template struct adjoint_unpack_index { template ATLAS_HOST_DEVICE static void apply(idx_t& buf_idx, const idx_t node_idx, const DATA_TYPE* recv_buffer, array::ArrayView& field, Idx... idxs) { field(idxs...) += recv_buffer[buf_idx++]; } }; } // namespace atlas::parallel::detail