1 #ifndef DASH__VIEW__VIEW_MOD_H__INCLUDED 2 #define DASH__VIEW__VIEW_MOD_H__INCLUDED 4 #include <dash/Types.h> 5 #include <dash/Range.h> 6 #include <dash/Iterator.h> 8 #include <dash/util/UniversalMember.h> 9 #include <dash/util/ArrayExpr.h> 11 #include <dash/view/IndexSet.h> 12 #include <dash/view/ViewTraits.h> 13 #include <dash/view/ViewIterator.h> 14 #include <dash/view/ViewOrigin.h> 16 #include <dash/view/Local.h> 17 #include <dash/view/Global.h> 18 #include <dash/view/Origin.h> 19 #include <dash/view/Domain.h> 20 #include <dash/view/Apply.h> 125 typename std::decay<DomainType>::type>::rank::value >
131 typename std::decay<DomainType>::type>::rank::value >
138 typename std::decay<DomainType>::type>::rank::value >
144 typename std::decay<DomainType>::type>::rank::value >
163 typedef DomainType domain_type;
165 typedef typename std::conditional<
182 typedef typename std::conditional<
186 typename view_traits<domain_type>::origin_type
188 typename view_traits<domain_type>::origin_type
195 typename std::add_lvalue_reference<origin_type>::type
202 typename std::add_lvalue_reference<const origin_type>::type
204 const_origin_iterator;
209 typename std::add_lvalue_reference<origin_type>::type
216 typename std::add_lvalue_reference<const origin_type>::type
222 typedef typename origin_type::value_type value_type;
224 typedef std::integral_constant<dim_t, NDim> rank;
226 static constexpr
dim_t ndim() {
return NDim; }
229 domain_member_type _domain;
231 ViewModType & derived() {
232 return static_cast<ViewModType &
>(*this);
234 constexpr
const ViewModType & derived()
const {
235 return static_cast<const ViewModType &
>(*this);
241 constexpr
explicit ViewModBase(domain_type && domain)
242 : _domain(std::forward<domain_type>(domain))
248 constexpr
explicit ViewModBase(
const domain_type & domain)
252 constexpr ViewModBase() =
delete;
253 ~ViewModBase() =
default;
256 constexpr ViewModBase(
const self_t &) =
default;
257 constexpr ViewModBase(self_t &&) =
default;
258 self_t & operator=(
const self_t &) =
default;
259 self_t & operator=(self_t &&) =
default;
261 constexpr
const domain_type & domain()
const & {
265 constexpr domain_type domain()
const && {
269 constexpr
bool operator==(
const ViewModType & rhs)
const {
270 return &derived() == &rhs;
273 constexpr
bool operator!=(
const ViewModType & rhs)
const {
274 return !(derived() == rhs);
277 constexpr
bool is_local()
const {
283 constexpr
const std::array<size_type, NDim> extents()
const {
284 return domain().extents();
287 template <dim_t ShapeDim>
288 constexpr size_type extent()
const {
289 return domain().template extent<ShapeDim>();
292 constexpr size_type extent(
dim_t shape_dim)
const {
293 return domain().extent(shape_dim);
298 constexpr
const std::array<index_type, NDim> offsets()
const {
299 return domain().offsets();
302 template <dim_t ShapeDim>
303 constexpr index_type offset()
const {
304 return domain().template offset<ShapeDim>();
307 constexpr index_type offset(
dim_t shape_dim)
const {
308 return domain().offset(shape_dim);
313 constexpr index_type size()
const {
327 typedef DomainType domain_type;
328 typedef typename view_traits<domain_type>::origin_type origin_type;
330 typedef typename domain_type::local_type image_type;
332 typedef domain_type global_type;
336 typedef dash::IndexSetLocal<DomainType> index_set_type;
338 typedef std::integral_constant<bool, false> is_projection;
339 typedef std::integral_constant<bool, true> is_view;
340 typedef std::integral_constant<bool, false> is_origin;
341 typedef std::integral_constant<bool, true> is_local;
343 typedef std::integral_constant<dim_t, DomainType::rank::value> rank;
351 ViewLocalMod<DomainType, NDim>,
355 typedef DomainType domain_type;
356 typedef typename view_traits<DomainType>::origin_type origin_type;
357 typedef typename domain_type::local_type image_type;
365 typedef dash::IndexSetLocal<DomainType> index_set_type;
367 typedef typename domain_type::global_type global_type;
369 typedef std::integral_constant<bool, true> is_local;
376 typename std::add_lvalue_reference<domain_type>::type >()
385 typename std::add_lvalue_reference<const domain_type>::type >()
394 typename std::add_lvalue_reference<domain_type>::type >()
403 typename std::add_lvalue_reference<const domain_type>::type >()
408 index_set_type _index_set;
414 self_t & operator=(self_t &&) =
default;
415 self_t & operator=(
const self_t &) =
default;
421 domain_type && domain)
422 : base_t(
std::forward<domain_type>(
domain))
423 , _index_set(this->
domain())
430 const DomainType & domain)
435 constexpr
bool operator==(
const self_t & rhs)
const {
436 return (
this == &rhs ||
437 ( base_t::operator==(rhs) &&
438 _index_set == rhs._index_set ) );
441 constexpr
bool operator!=(
const self_t & rhs)
const {
442 return not (*
this == rhs);
447 constexpr
const std::array<size_type, NDim> extents()
const {
448 return _index_set.extents();
451 template <dim_t ShapeDim>
452 constexpr size_type
extent()
const {
453 return _index_set.template extent<ShapeDim>();
456 constexpr size_type
extent(
dim_t shape_dim)
const {
457 return _index_set.extent(shape_dim);
462 constexpr
const std::array<index_type, NDim> offsets()
const {
463 return _index_set.offsets();
468 constexpr size_type
size(
dim_t sub_dim = 0)
const {
469 return index_set().size(sub_dim);
474 constexpr const_iterator
begin()
const {
489 constexpr const_iterator
end()
const {
493 + _index_set[_index_set.size() - 1] + 1;
501 + _index_set[_index_set.size() - 1] + 1;
504 constexpr const_reference operator[](
int offset)
const {
508 + _index_set[offset]);
511 reference operator[](
int offset) {
516 + _index_set[offset]);
519 constexpr
const local_type &
local()
const {
523 local_type &
local() {
527 constexpr
const global_type &
global()
const {
531 constexpr
const index_set_type & index_set()
const {
546 typedef DomainType domain_type;
547 typedef typename view_traits<domain_type>::origin_type origin_type;
553 typedef ViewSubMod<DomainType, SubDim, NDim>
global_type;
555 typedef typename DomainType::index_type index_type;
556 typedef typename DomainType::size_type size_type;
557 typedef dash::IndexSetSub<DomainType, SubDim> index_set_type;
559 typedef std::integral_constant<bool, false> is_projection;
560 typedef std::integral_constant<bool, true> is_view;
561 typedef std::integral_constant<bool, false> is_origin;
562 typedef std::integral_constant<bool,
565 typedef std::integral_constant<dim_t, DomainType::rank::value> rank;
575 ViewSubMod<DomainType, SubDim, NDim>,
580 typedef DomainType domain_type;
585 domain_type, NDim >
base_t;
587 typedef typename base_t::origin_type origin_type;
595 typedef std::integral_constant<bool, false> is_local;
597 typedef dash::IndexSetSub<domain_type, SubDim> index_set_type;
600 typename base_t::origin_iterator, index_set_type >
603 typename base_t::const_origin_iterator, index_set_type >
606 using reference =
typename base_t::reference;
607 using const_reference =
typename base_t::const_reference;
610 index_set_type _index_set;
615 constexpr
ViewSubMod(
const self_t &) =
default;
617 self_t & operator=(self_t &&) =
default;
618 self_t & operator=(
const self_t &) =
default;
624 : base_t(std::forward<domain_type>(
domain))
625 , _index_set(this->
domain(), begin, end)
628 constexpr ViewSubMod(
629 const domain_type &
domain,
633 , _index_set(domain, begin, end)
638 constexpr std::array<size_type, NDim> extents()
const {
639 return _index_set.extents();
642 template <dim_t ExtDim>
643 constexpr size_type
extent()
const {
644 return _index_set.template extent<ExtDim>();
647 constexpr size_type
extent(
dim_t shape_dim)
const {
648 return _index_set.extent(shape_dim);
653 template <dim_t ExtDim>
654 constexpr index_type offset()
const {
655 return _index_set.template offset<ExtDim>();
658 constexpr std::array<index_type, NDim> offsets()
const {
659 return _index_set.offsets();
662 constexpr index_type offset(
dim_t shape_dim)
const {
663 return _index_set.offset(shape_dim);
668 constexpr size_type
size(
dim_t sub_dim = 0)
const {
669 return _index_set.size(sub_dim);
674 constexpr const_iterator
begin()
const {
675 return const_iterator(
682 const_cast<origin_type &>(
688 constexpr const_iterator
end()
const {
689 return const_iterator(
691 _index_set, _index_set.size());
696 const_cast<origin_type &>(
699 _index_set, _index_set.size());
702 constexpr const_reference operator[](
int offset)
const {
704 _index_set, offset));
707 reference operator[](
int offset) {
708 return *(iterator(const_cast<origin_type &>(
711 _index_set, offset));
714 constexpr
const index_set_type & index_set()
const {
718 constexpr local_type
local()
const {
719 return local_type(*
this);
726 #include <dash/view/ViewMod1D.h> 728 #endif // DASH__VIEW__VIEW_MOD_H__INCLUDED constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
size_t size()
Return the number of units in the global team.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
constexpr auto local(ViewType &v) -> typename std::enable_if<(std::is_pointer< typename ViewType::iterator >::value||(dash::view_traits< ViewValueT >::is_local::value)), ViewType &>::type
This class is a simple memory pool which holds allocates elements of size ValueType.
constexpr ViewLocalMod(const DomainType &domain)
Constructor, creates a view on a given domain.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
dash::view_traits< ViewT >::origin_type origin(ViewT &view)
constexpr std::enable_if< dash::view_traits< ViewType >::is_view::value &&dash::view_traits< ViewType >::is_local::value, const typename ViewType::global_type & >::type global(const ViewType &v)
constexpr DimensionalType::extent_type extent(const DimensionalType &d)
constexpr ViewLocalMod(domain_type &&domain)
Constructor, creates a view on a given domain.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
constexpr auto domain(ViewT &&view) -> typename std::enable_if< dash::detail::has_type_domain_type< ViewValueT >::value, decltype(std::forward< ViewT >(view).domain()) >::type