1 #ifndef DASH__GLOB_ITER_H__INCLUDED 2 #define DASH__GLOB_ITER_H__INCLUDED 4 #include <dash/GlobPtr.h> 5 #include <dash/GlobRef.h> 6 #include <dash/Pattern.h> 43 typename GlobMemType::void_pointer::template rebind<ElementType>,
44 class ReferenceType = GlobRef<ElementType> >
49 using value_type = ElementType;
50 using difference_type =
typename PatternType::index_type;
51 using size_type =
typename PatternType::size_type;
52 using pointer = PointerType;
55 typedef typename ReferenceType::const_type const_reference;
57 typedef typename PointerType::const_type const_pointer;
59 typedef typename pointer::local_type local_type;
61 typedef typename pointer::const_local_type const_local_type;
64 typedef typename std::make_signed<typename PatternType::index_type>::type index_type;
83 typedef typename std::remove_const<ElementType>::type nonconst_value_type;
86 typedef std::integral_constant<bool, false> has_view;
90 template <
typename T_,
class P_,
class GM_,
class Ptr_,
class Ref_>
91 friend std::ostream& operator<<(
95 template <
typename T_,
class P_,
class GM_,
class Ptr_,
class Ref_>
100 static const MemArrange Arrangement = PatternType::memory_order();
104 GlobMemType* _globmem =
nullptr;
106 PatternType
const* _pattern =
nullptr;
110 index_type _max_idx = 0;
113 DASH_CONSTEXPR
GlobIter() =
default;
121 PatternType
const& pat,
122 index_type position = 0) DASH_NOEXCEPT
126 _max_idx(index_type(pat.
size()) - 1)
133 class ReferenceType_,
134 typename =
typename std::enable_if<
138 typename dash::remove_atomic<ElementType_>::type,
139 typename dash::remove_atomic<value_type>::type>::value>
147 ReferenceType_>& other) DASH_NOEXCEPT
148 : _globmem(other._globmem),
149 _pattern(other._pattern),
151 _max_idx(other._max_idx)
160 return NumDimensions;
170 DASH_CONSTEXPR
explicit operator const_pointer() const noexcept
182 DASH_CONSTEXPR
explicit operator pointer() DASH_NOEXCEPT
195 if (_globmem ==
nullptr) {
198 else if (_idx > _max_idx) {
204 DASH_LOG_TRACE_VAR(
"GlobIter.dart_gptr()", _idx);
208 local_pos_t local_pos = _pattern->local(_idx);
210 "GlobIter.dart_gptr",
215 auto const dart_pointer = _get_pointer_at(local_pos);
236 DASH_CONSTEXPR const_reference
operator*() const noexcept
238 return const_reference{this->
dart_gptr()};
247 index_type g_index) noexcept
260 index_type g_index)
const noexcept
264 return const_reference(p.dart_gptr());
273 return (_globmem->team().myid() ==
lpos().unit);
279 DASH_CONSTEXPR local_type
local()
const 281 auto local_pos =
lpos();
283 if (local_pos.unit != _pattern->team().myid()) {
288 static_cast<pointer>(_globmem->begin()), _pattern->team().myid());
291 return std::next(lbegin, local_pos.index);
297 DASH_CONSTEXPR
auto lpos()
const 299 DASH_LOG_TRACE_VAR(
"GlobIter.lpos()", _idx);
301 index_type idx = _idx;
302 index_type offset = 0;
305 if (idx > _max_idx) {
307 offset = _idx - _max_idx;
308 DASH_ASSERT_EQ(offset, 1,
"invalid index");
311 auto local_pos = _pattern->local(idx);
313 local_pos.index += offset;
328 DASH_CONSTEXPR
const self_t&
global() const DASH_NOEXCEPT
336 DASH_CONSTEXPR index_type
pos() const DASH_NOEXCEPT
344 DASH_CONSTEXPR index_type
gpos() const DASH_NOEXCEPT
353 DASH_CONSTEXPR
const GlobMemType&
globmem() const DASH_NOEXCEPT
381 self_t result = *
this;
400 self_t result = *
this;
405 DASH_CONSTEXPR self_t& operator+=(index_type n) DASH_NOEXCEPT
411 DASH_CONSTEXPR self_t& operator-=(index_type n) DASH_NOEXCEPT
417 DASH_CONSTEXPR self_t operator+(index_type n)
const DASH_NOEXCEPT
419 return self_t(_globmem, *_pattern, _idx + static_cast<index_type>(n));
422 DASH_CONSTEXPR self_t operator-(index_type n)
const DASH_NOEXCEPT
424 return self_t(_globmem, *_pattern, _idx - static_cast<index_type>(n));
427 template <
class GlobIterT>
428 DASH_CONSTEXPR
bool operator<(
const GlobIterT& other)
const DASH_NOEXCEPT
430 return (_idx < other._idx);
433 template <
class GlobIterT>
434 DASH_CONSTEXPR
bool operator<=(
const GlobIterT& other)
const DASH_NOEXCEPT
436 return (_idx <= other._idx);
439 template <
class GlobIterT>
440 DASH_CONSTEXPR
bool operator>(
const GlobIterT& other)
const DASH_NOEXCEPT
442 return (_idx > other._idx);
445 template <
class GlobIterT>
446 DASH_CONSTEXPR
bool operator>=(
const GlobIterT& other)
const DASH_NOEXCEPT
448 return (_idx >= other._idx);
451 template <
class GlobIterT>
452 DASH_CONSTEXPR
bool operator==(
const GlobIterT& other)
const DASH_NOEXCEPT
454 return _idx == other._idx;
457 template <
class GlobIterT>
458 DASH_CONSTEXPR
bool operator!=(
const GlobIterT& other)
const DASH_NOEXCEPT
460 return _idx != other._idx;
463 DASH_CONSTEXPR
const PatternType& pattern()
const DASH_NOEXCEPT
468 DASH_CONSTEXPR
dash::Team& team()
const DASH_NOEXCEPT
470 return _pattern->team();
477 auto dart_pointer =
static_cast<dart_gptr_t>(_globmem->begin());
479 DASH_ASSERT(pos.index >= 0);
481 dart_pointer.unitid = pos.unit;
483 dart_pointer.addr_or_offs.offset += pos.index *
sizeof(value_type);
491 typename ElementType,
496 std::ostream& operator<<(
501 std::ostringstream ss;
503 ss <<
"dash::GlobIter<" <<
typeid(ElementType).name() <<
">(" 504 <<
"idx:" << it._idx <<
", " 505 <<
"gptr:" << ptr <<
")";
506 return operator<<(os, ss.str());
510 #endif // DASH__GLOB_ITER_H__INCLUDED DASH_CONSTEXPR self_t & operator++() DASH_NOEXCEPT
Prefix increment operator.
DASH_CONSTEXPR dart_gptr_t dart_gptr() const DASH_NOEXCEPT
Explicit conversion to dart_gptr_t.
static constexpr dim_t ndim()
The number of dimensions of the iterator's underlying pattern.
DASH_CONSTEXPR std::enable_if< std::is_same< typename dash::memory_space_traits< MemSpaceT >::memory_space_layout_tag, memory_space_contiguous >::value, T >::type * local_begin(GlobPtr< T, MemSpaceT > global_begin, dash::team_unit_t unit)
Returns the begin of the local memory portion within a global memory segment.
DASH_CONSTEXPR const_reference operator[](index_type g_index) const noexcept
Subscript operator, returns global reference to element at given global index.
Defines how a list of global indices is mapped to single units within a Team.
size_t size()
Return the number of units in the global team.
DASH_CONSTEXPR reference operator[](index_type g_index) noexcept
Subscript operator, returns global reference to element at given global index.
This class is a simple memory pool which holds allocates elements of size ValueType.
std::random_access_iterator_tag iterator_category
Iterator Traits.
dash::BlockPattern< NumDimensions, Arrangement, IndexType > Pattern
Template alias for dash::Pattern with the same default template arguments.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
DASH_CONSTEXPR local_type local() const
Convert global iterator to native pointer.
DASH_CONSTEXPR const_reference operator*() const noexcept
Dereference operator.
Global memory with address space of static size.
DASH_CONSTEXPR index_type gpos() const DASH_NOEXCEPT
Position of the iterator in global index range.
GlobMemType & globmem()
The instance of GlobStaticMem used by this iterator to resolve addresses in global memory...
Iterator on Partitioned Global Address Space.
#define DART_GPTR_NULL
A NULL global pointer.
A Team instance specifies a subset of all available units.
DASH_CONSTEXPR index_type pos() const DASH_NOEXCEPT
Position of the iterator in global index space.
constexpr dim_t ndim(const DimensionalType &d)
DASH_CONSTEXPR const GlobMemType & globmem() const DASH_NOEXCEPT
The instance of GlobStaticMem used by this iterator to resolve addresses in global memory...
DART Global pointer type.
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
DASH_CONSTEXPR const self_t & global() const DASH_NOEXCEPT
Map iterator to global index domain.
DASH_CONSTEXPR auto lpos() const
Unit and local offset at the iterator's position.
Pointer in global memory space with random access arithmetics.
DASH_CONSTEXPR self_t & operator--() DASH_NOEXCEPT
Prefix decrement operator.
DASH_CONSTEXPR bool is_local() const noexcept
Checks whether the element referenced by this global iterator is in the calling unit's local memory...
DASH_CONSTEXPR GlobIter(GlobMemType *gmem, PatternType const &pat, index_type position=0) DASH_NOEXCEPT
Constructor, creates a global iterator on global memory following the element order specified by the ...
DASH_CONSTEXPR self_t operator--(int) DASH_NOEXCEPT
Postfix decrement operator.
DASH_CONSTEXPR self_t operator++(int) DASH_NOEXCEPT
Postfix increment operator.
DASH_CONSTEXPR reference operator*() noexcept
Dereference operator.