1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_DISTRIBUTION_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_DISTRIBUTION_H
15template <
typename Ind =
size_t>
29 swap(l.m_chunk_borders, r.m_chunk_borders);
64 std::pair<index_type, index_type>
range(
int chunk)
const {
80 std::logical_and<>(), std::equal_to<>());
98template <
typename Ind>
100 assert(n_chunks > 0);
101 auto chunk_borders = std::vector<Ind>{0};
102 chunk_borders.reserve(n_chunks + 1);
103 auto block = dimension / n_chunks;
104 auto n_extra = dimension % n_chunks;
105 std::fill_n(std::back_inserter(chunk_borders), n_extra, block + 1);
106 std::fill_n(std::back_inserter(chunk_borders), n_chunks - n_extra, block);
107 std::partial_sum(
begin(chunk_borders),
end(chunk_borders),
begin(chunk_borders));
108 return {chunk_borders};
Specifies distribution of a contiguous array into non-overlapping chunks.
Definition: Distribution.h:16
const std::vector< index_type > & chunk_borders() const
Definition: Distribution.h:74
friend void swap(Distribution< index_type > &l, Distribution< index_type > &r)
Definition: Distribution.h:27
std::pair< index_type, index_type > border() const
Definition: Distribution.h:69
std::pair< int, int > cover(index_type lo, index_type hi) const
Maps first and last index in the array to a pair of chunks encapsulating the corresponding range.
Definition: Distribution.h:46
size_t size() const
Number of chunks in the distribution.
Definition: Distribution.h:72
bool compatible(const Distribution< Ind > &other) const
Checks that other distribution is the same.
Definition: Distribution.h:77
Ind index_type
Definition: Distribution.h:18
Distribution(Distribution< Ind > &&) noexcept=default
Distribution(const Distribution< Ind > &)=default
Distribution(const std::vector< index_type > &indices)
Construct a contiguous distribution list using vector of start indices.
Definition: Distribution.h:36
int cover(index_type ind) const
Definition: Distribution.h:55
std::pair< index_type, index_type > range(int chunk) const
Returns [fist, end) indices for section of array assigned to chunk.
Definition: Distribution.h:64
std::vector< index_type > m_chunk_borders
list of starting indices for each chunk with past the end index as last element. e....
Definition: Distribution.h:88
auto begin(Span< T > &x)
Definition: Span.h:84
auto end(Span< T > &x)
Definition: Span.h:94
Definition: ArrayHandler.h:23
Distribution< Ind > make_distribution_spread_remainder(size_t dimension, int n_chunks)
Creates a distribution with first (dimension % n_chunks) chunks larger by 1 element.
Definition: Distribution.h:99