5#include <dr/detail/matrix_entry.hpp>
6#include <dr/mp/containers/matrix_formats/csr_eq_distribution.hpp>
7#include <dr/views/csr_matrix_view.hpp>
12 { t.fence() } -> std::same_as<void>;
13 { t.segments() } -> rng::random_access_range;
14 { t.shape().first } -> std::convertible_to<std::size_t>;
15 { t.shape().second } -> std::convertible_to<std::size_t>;
16 { t.nnz() } -> std::same_as<std::size_t>;
17 { t.get_segment_from_offset(
int()) } -> std::same_as<std::size_t>;
18 { t.get_id_in_segment(
int()) } -> std::same_as<std::size_t>;
25 requires(T t, std::vector<typename T::elem_type> res, T::elem_type *input) {
26 t.local_gemv_and_collect(
int(), res, input, 1);
29template <
typename T,
typename I,
class BackendT =
MpiBackend,
39 using size_type = std::size_t;
40 using difference_type = std::ptrdiff_t;
41 using backend_type = BackendT;
45 using iterator_category = std::random_access_iterator_tag;
47 using difference_type =
typename distributed_sparse_matrix::difference_type;
51 : parent_(parent), offset_(offset) {}
53 auto operator+(difference_type n)
const {
54 return iterator(parent_, offset_ + n);
56 friend auto operator+(difference_type n,
const iterator &other) {
59 auto operator-(difference_type n)
const {
60 return iterator(parent_, offset_ - n);
62 auto operator-(
iterator other)
const {
return offset_ - other.offset_; }
64 auto &operator+=(difference_type n) {
68 auto &operator-=(difference_type n) {
76 auto operator++(
int) {
85 auto operator--(
int) {
91 bool operator==(
iterator other)
const {
92 if (parent_ ==
nullptr || other.parent_ ==
nullptr) {
95 return offset_ == other.offset_;
98 auto operator<=>(
iterator other)
const {
99 assert(parent_ == other.parent_);
100 return offset_ <=> other.offset_;
103 auto operator*()
const {
104 auto segment_id = parent_->distribution_.get_segment_from_offset(offset_);
105 auto id_in_segment = parent_->distribution_.get_id_in_segment(offset_);
106 return parent_->segments()[segment_id][id_in_segment];
108 auto operator[](difference_type n)
const {
return *(*
this + n); }
111 auto segment_id = parent_->distribution_.get_segment_from_offset(offset_);
112 auto id_in_segment = parent_->distribution_.get_id_in_segment(offset_);
113 return (parent_->segments()[segment_id].begin() + id_in_segment).local();
117 return dr::__detail::drop_segments(parent_->segments(), offset_);
122 difference_type offset_;
132 std::size_t root = 0,
134 : distribution_(csr_view, dist, root) {}
139 auto end()
const {
return begin() + distribution_.nnz(); }
142 auto size()
const {
return distribution_.nnz(); }
144 auto shape()
const {
return distribution_.shape(); }
146 auto operator[](difference_type n)
const {
return *(begin() + n); }
149 auto segments()
const {
return distribution_.segments(); }
151 void fence() { distribution_.fence(); }
153 template <
typename C>
154 requires(vector_multiplicable<MatrixDistrT>)
155 auto local_gemv_and_collect(std::size_t root, C &res, T *vals,
156 std::size_t val_width)
const {
157 distribution_.local_gemv_and_collect(root, res, vals, val_width);
161 MatrixDistrT distribution_;
Definition: matrix_entry.hpp:20
Definition: distributed_vector.hpp:14
Definition: csr_eq_distribution.hpp:13
Definition: distributed_sparse_matrix.hpp:43
Definition: distributed_sparse_matrix.hpp:32
auto size() const
Returns size.
Definition: distributed_sparse_matrix.hpp:142
auto end() const
Returns iterator to end.
Definition: distributed_sparse_matrix.hpp:139
distributed_sparse_matrix(dr::views::csr_matrix_view< T, I > csr_view, std::size_t root=0, distribution dist=distribution())
Constructor.
Definition: distributed_sparse_matrix.hpp:131
auto operator[](difference_type n) const
Returns reference using index.
Definition: distributed_sparse_matrix.hpp:146
auto begin() const
Returns iterator to beginning.
Definition: distributed_sparse_matrix.hpp:137
Definition: csr_matrix_view.hpp:126
Definition: distributed_sparse_matrix.hpp:11
Definition: distributed_sparse_matrix.hpp:24
Definition: distribution.hpp:11