7#include <dr/detail/ranges_shim.hpp>
13 using value_type =
typename DM::value_type;
14 using difference_type =
typename DM::difference_type;
19 std::pair<std::size_t, std::size_t> col_rng,
20 difference_type
index = 0)
noexcept {
27 value_type &operator*()
const {
29 int offset = dm_->halo_bounds().prev + find_dm_offset(index_) -
30 default_comm().rank() * dm_->segment_size();
33 assert(offset < (
int)dm_->data_size());
34 return *(dm_->data() + offset);
37 dm_row<value_type> operator[](
int n) {
38 std::size_t rowsize = col_rng_.second - col_rng_.first;
40 int offset = dm_->halo_bounds().prev +
41 find_dm_offset((
int)(index_ + n * rowsize)) -
42 default_comm().rank() * dm_->segment_size();
45 assert(offset < (
int)dm_->data_size());
47 signed long idx = default_comm().rank() * dm_->segment_shape()[0];
48 value_type *ptr = dm_->data() + offset;
51 return dm_row<value_type>(idx, ptr, rowsize, segment);
54 value_type &operator[](std::pair<int, int> p) {
55 int offset = dm_->distribution_.halo().prev + find_dm_offset(index_) -
56 default_comm().rank() * dm_->segment_size() +
57 dm_->shape()[1] * p.first + p.second;
60 assert(offset < (
int)dm_->data_size());
61 return *(dm_->data() + offset);
66 return first.index_ == second.index_;
69 return first.index_ != second.index_;
72 return first.index_ == second.index_;
75 return first.index_ != second.index_;
78 return this->index_ <=> other.index_;
82 auto &operator-=(difference_type n) {
86 auto &operator+=(difference_type n) {
92 return index_ - other.index_;
105 auto operator++(
int) {
110 auto operator--(
int) {
116 auto operator+(difference_type n)
const {
119 auto operator-(difference_type n)
const {
128 auto &halo() {
return dm_->halo(); }
129 auto segments() {
return dm_->segments(); }
131 bool is_local() {
return dm_->is_local_cell(find_dm_offset(index_)); }
134 std::size_t find_dm_offset()
const {
return find_dm_offset(index_); }
141 std::size_t find_dm_offset(
int index)
const {
142 int ind_rows, ind_cols;
145 ind_rows =
index / (col_rng_.second - col_rng_.first);
146 ind_cols =
index % (col_rng_.second - col_rng_.first);
150 ind_cols += (col_rng_.second - col_rng_.first);
153 offset += row_rng_.first * dm_->shape()[1] + col_rng_.first;
154 offset += (int)(ind_rows * dm_->shape()[1] + ind_cols);
161 std::pair<int, int> row_rng_ = std::pair<int, int>(0, 0);
162 std::pair<int, int> col_rng_ = std::pair<int, int>(0, 0);
164 std::size_t index_ = 0;
167template <
typename DM>
168class subrange :
public rng::view_interface<subrange<DM>> {
171 using value_type =
typename DM::value_type;
173 subrange(DM &dm, std::pair<std::size_t, std::size_t> row_rng,
174 std::pair<std::size_t, std::size_t> col_rng) {
180 (col_rng.second - col_rng.first) * (row_rng.second - row_rng.first);
184 iterator end()
const {
return begin() + subrng_size_; }
186 auto size() {
return subrng_size_; }
188 auto &halo()
const {
return dm_->halo(); }
189 auto segments()
const {
return dm_->segments(); }
193 std::pair<std::size_t, std::size_t> row_rng_;
194 std::pair<std::size_t, std::size_t> col_rng_;
196 std::size_t subrng_size_ = 0;
Definition: segment.hpp:214
Definition: subrange.hpp:11
Definition: subrange.hpp:168