/* * (C) Copyright 2013 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. */ #pragma once #include "atlas/array/LocalView.h" #include "atlas/parallel/mpi/mpi.h" namespace atlas { namespace mpi { /// @brief Buffer /// /// Class that keeps allocation of a MPI buffer including /// counts and displacements, but with added index operator[] /// that returns an array::ArrayView of the part /// of the buffer for a processor index. template struct Buffer; // ---------------------------------------------------------------------------------- template struct Buffer : eckit::mpi::Buffer {}; template class BufferView { public: BufferView(DATA_TYPE* data, size_t size): data_(data), size_(size) {} size_t size() const { return size_; } const DATA_TYPE& operator()(const size_t i) const { return data_[i]; } const DATA_TYPE& operator[](const size_t i) const { return data_[i]; } private: DATA_TYPE* data_; size_t size_; }; template struct Buffer : public eckit::mpi::Buffer { Buffer(size_t size): eckit::mpi::Buffer(size) {} // array::make_shape( // eckit::mpi::Buffer::counts[p] // ) ); // } BufferView operator[](int p) { return BufferView( eckit::mpi::Buffer::buffer.data() + eckit::mpi::Buffer::displs[p], eckit::mpi::Buffer::counts[p]); } }; // ---------------------------------------------------------------------------------- } // namespace mpi } // namespace atlas