| 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 <vector> |
| 14 |
|
| 15 |
#include "atlas/grid/detail/distribution/DistributionImpl.h" |
| 16 |
#include "atlas/library/config.h" |
| 17 |
#include "atlas/util/Config.h" |
| 18 |
#include "atlas/util/ObjectHandle.h" |
| 19 |
#include "atlas/util/vector.h" |
| 20 |
|
| 21 |
namespace atlas { |
| 22 |
class Grid; |
| 23 |
namespace grid { |
| 24 |
class Partitioner; |
| 25 |
} // namespace grid |
| 26 |
} // namespace atlas |
| 27 |
|
| 28 |
namespace atlas { |
| 29 |
namespace grid { |
| 30 |
|
| 31 |
class Distribution : DOXYGEN_HIDE(public util::ObjectHandle<DistributionImpl>) { |
| 32 |
friend class Partitioner; |
| 33 |
|
| 34 |
public: |
| 35 |
using Config = DistributionImpl::Config; |
| 36 |
using partition_t = atlas::vector<int>; |
| 37 |
|
| 38 |
using Handle::Handle; |
| 39 |
Distribution() = default; |
| 40 |
|
| 41 |
/// @brief Create a serial distribution |
| 42 |
Distribution(const Grid&); |
| 43 |
|
| 44 |
/// @brief Create a distribution specified by a configuration |
| 45 |
Distribution(const Grid&, const Config&); |
| 46 |
|
| 47 |
/// @brief Create a distribution using a given partitioner |
| 48 |
Distribution(const Grid&, const Partitioner&); |
| 49 |
|
| 50 |
/// @brief Create a distribution by given array, and make internal copy |
| 51 |
Distribution(int nb_partitions, idx_t npts, int partition[], int part0 = 0); |
| 52 |
|
| 53 |
/// @brief Create a distribution by given array, and take ownership (move) |
| 54 |
Distribution(int nb_partitions, partition_t&& partition); |
| 55 |
|
| 56 |
~Distribution(); |
| 57 |
|
| 58 |
ATLAS_ALWAYS_INLINE int partition(gidx_t index) const { return get()->partition(index); } |
| 59 |
|
| 60 |
template <typename PartitionContainer> |
| 61 |
void partition(gidx_t begin, gidx_t end, PartitionContainer& partitions) const { |
| 62 |
ATLAS_ASSERT(end - begin <= partitions.size()); |
| 63 |
return get()->partition(begin, end, partitions.data()); |
| 64 |
} |
| 65 |
|
| 66 |
size_t footprint() const { return get()->footprint(); } |
| 67 |
|
| 68 |
ATLAS_ALWAYS_INLINE idx_t nb_partitions() const { return get()->nb_partitions(); } |
| 69 |
|
| 70 |
ATLAS_ALWAYS_INLINE gidx_t size() const { return get()->size(); } |
| 71 |
|
| 72 |
const std::vector<idx_t>& nb_pts() const; |
| 73 |
|
| 74 |
idx_t max_pts() const; |
| 75 |
|
| 76 |
idx_t min_pts() const; |
| 77 |
|
| 78 |
const std::string& type() const; |
| 79 |
|
| 80 |
friend std::ostream& operator<<(std::ostream& os, const Distribution& distribution); |
| 81 |
|
| 82 |
std::string hash() const; |
| 83 |
|
| 84 |
void hash(eckit::Hash&) const; |
| 85 |
}; |
| 86 |
|
| 87 |
} // namespace grid |
| 88 |
} // namespace atlas |