| 1 |
/* |
| 2 |
* (C) Copyright 2013 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 |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
|
| 17 |
#include "atlas/grid/detail/distribution/DistributionImpl.h" |
| 18 |
#include "atlas/util/vector.h" |
| 19 |
|
| 20 |
|
| 21 |
namespace atlas { |
| 22 |
namespace grid { |
| 23 |
class Partitioner; |
| 24 |
|
| 25 |
namespace detail { |
| 26 |
namespace distribution { |
| 27 |
|
| 28 |
class DistributionArray : public DistributionImpl { |
| 29 |
public: |
| 30 |
using partition_t = atlas::vector<int>; |
| 31 |
|
| 32 |
DistributionArray() = default; |
| 33 |
|
| 34 |
DistributionArray(const Grid&, const eckit::Parametrisation&); |
| 35 |
|
| 36 |
DistributionArray(const Grid&, const Partitioner&); |
| 37 |
|
| 38 |
DistributionArray(int nb_partitions, idx_t npts, int partition[], int part0 = 0); |
| 39 |
|
| 40 |
DistributionArray(int nb_partitions, partition_t&& partition); |
| 41 |
|
| 42 |
virtual ~DistributionArray(); |
| 43 |
|
| 44 |
int partition(const gidx_t gidx) const override { return part_[gidx]; } |
| 45 |
|
| 46 |
const partition_t& partition() const { return part_; } |
| 47 |
|
| 48 |
idx_t nb_partitions() const override { return nb_partitions_; } |
| 49 |
|
| 50 |
operator const partition_t&() const { return part_; } |
| 51 |
|
| 52 |
const int* data() const { return part_.data(); } |
| 53 |
|
| 54 |
const std::vector<idx_t>& nb_pts() const override { return nb_pts_; } |
| 55 |
|
| 56 |
idx_t max_pts() const override { return max_pts_; } |
| 57 |
idx_t min_pts() const override { return min_pts_; } |
| 58 |
|
| 59 |
const std::string& type() const override { return type_; } |
| 60 |
|
| 61 |
void print(std::ostream&) const override; |
| 62 |
|
| 63 |
size_t footprint() const override { return nb_pts_.size() * sizeof(nb_pts_[0]) + part_.size() * sizeof(part_[0]); } |
| 64 |
|
| 65 |
bool functional() const override { return false; } |
| 66 |
|
| 67 |
gidx_t size() const override { return part_.size(); } |
| 68 |
|
| 69 |
void hash(eckit::Hash&) const override; |
| 70 |
|
| 71 |
void partition(gidx_t begin, gidx_t end, int partitions[]) const override { |
| 72 |
size_t i = 0; |
| 73 |
for (gidx_t n = begin; n < end; ++n, ++i) { |
| 74 |
partitions[i] = part_[n]; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
protected: |
| 79 |
idx_t nb_partitions_ = 0; |
| 80 |
|
| 81 |
partition_t part_; |
| 82 |
std::vector<idx_t> nb_pts_; |
| 83 |
idx_t max_pts_; |
| 84 |
idx_t min_pts_; |
| 85 |
std::string type_; |
| 86 |
}; |
| 87 |
|
| 88 |
} // namespace distribution |
| 89 |
} // namespace detail |
| 90 |
} // namespace grid |
| 91 |
} // namespace atlas |