DASH  0.3.0
dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType > Class Template Reference

Iterator on Partitioned Global Address Space. More...

#include <GlobIter.h>

Public Types

using iterator_category = std::random_access_iterator_tag
 Iterator Traits. More...
 
using value_type = ElementType
 
using difference_type = typename PatternType::index_type
 
using size_type = typename PatternType::size_type
 
using pointer = PointerType
 
using reference = ReferenceType
 
typedef ReferenceType::const_type const_reference
 
typedef PointerType::const_type const_pointer
 
typedef pointer::local_type local_type
 
typedef pointer::const_local_type const_local_type
 
typedef PatternType pattern_type
 
typedef std::make_signed< typename PatternType::index_type >::type index_type
 
typedef std::integral_constant< bool, false > has_view
 

Public Member Functions

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 given pattern. More...
 
template<class ElementType_ , class PointerType_ , class ReferenceType_ , typename = typename std::enable_if< std::is_assignable< typename dash::remove_atomic<ElementType_>::type, typename dash::remove_atomic<value_type>::type>::value> ::type>
DASH_CONSTEXPR GlobIter (const GlobIter< ElementType_, PatternType, GlobMemType, PointerType_, ReferenceType_ > &other) DASH_NOEXCEPT
 
DASH_CONSTEXPR operator const_pointer () const noexcept
 <fuchsto> TODO: Conversion from iterator to pointer looks dubios More...
 
DASH_CONSTEXPR operator pointer () DASH_NOEXCEPT
 <fuchsto> TODO: Conversion from iterator to pointer looks dubios More...
 
DASH_CONSTEXPR dart_gptr_t dart_gptr () const DASH_NOEXCEPT
 Explicit conversion to dart_gptr_t. More...
 
DASH_CONSTEXPR reference operator* () noexcept
 Dereference operator. More...
 
DASH_CONSTEXPR const_reference operator* () const noexcept
 Dereference operator. More...
 
DASH_CONSTEXPR reference operator[] (index_type g_index) noexcept
 Subscript operator, returns global reference to element at given global index. More...
 
DASH_CONSTEXPR const_reference operator[] (index_type g_index) const noexcept
 Subscript operator, returns global reference to element at given global index. More...
 
DASH_CONSTEXPR bool is_local () const noexcept
 Checks whether the element referenced by this global iterator is in the calling unit's local memory. More...
 
DASH_CONSTEXPR local_type local () const
 Convert global iterator to native pointer. More...
 
DASH_CONSTEXPR auto lpos () const
 Unit and local offset at the iterator's position. More...
 
DASH_CONSTEXPR const self_tglobal () const DASH_NOEXCEPT
 Map iterator to global index domain. More...
 
DASH_CONSTEXPR index_type pos () const DASH_NOEXCEPT
 Position of the iterator in global index space. More...
 
DASH_CONSTEXPR index_type gpos () const DASH_NOEXCEPT
 Position of the iterator in global index range. More...
 
DASH_CONSTEXPR const GlobMemType & globmem () const DASH_NOEXCEPT
 The instance of GlobStaticMem used by this iterator to resolve addresses in global memory. More...
 
GlobMemType & globmem ()
 The instance of GlobStaticMem used by this iterator to resolve addresses in global memory. More...
 
DASH_CONSTEXPR self_toperator++ () DASH_NOEXCEPT
 Prefix increment operator. More...
 
DASH_CONSTEXPR self_t operator++ (int) DASH_NOEXCEPT
 Postfix increment operator. More...
 
DASH_CONSTEXPR self_toperator-- () DASH_NOEXCEPT
 Prefix decrement operator. More...
 
DASH_CONSTEXPR self_t operator-- (int) DASH_NOEXCEPT
 Postfix decrement operator. More...
 
DASH_CONSTEXPR self_toperator+= (index_type n) DASH_NOEXCEPT
 
DASH_CONSTEXPR self_toperator-= (index_type n) DASH_NOEXCEPT
 
DASH_CONSTEXPR self_t operator+ (index_type n) const DASH_NOEXCEPT
 
DASH_CONSTEXPR self_t operator- (index_type n) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator< (const GlobIterT &other) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator<= (const GlobIterT &other) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator> (const GlobIterT &other) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator>= (const GlobIterT &other) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator== (const GlobIterT &other) const DASH_NOEXCEPT
 
template<class GlobIterT >
DASH_CONSTEXPR bool operator!= (const GlobIterT &other) const DASH_NOEXCEPT
 
DASH_CONSTEXPR const PatternType & pattern () const DASH_NOEXCEPT
 
DASH_CONSTEXPR dash::Teamteam () const DASH_NOEXCEPT
 

Static Public Member Functions

static constexpr dim_t ndim ()
 The number of dimensions of the iterator's underlying pattern. More...
 

Friends

template<typename T_ , class P_ , class GM_ , class Ptr_ , class Ref_ >
std::ostream & operator<< (std::ostream &os, const GlobIter< T_, P_, GM_, Ptr_, Ref_ > &it)
 

Detailed Description

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
class dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >

Iterator on Partitioned Global Address Space.

Implemented concept:
Global Iterator Concept

Definition at line 45 of file GlobIter.h.

Member Typedef Documentation

◆ iterator_category

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
using dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::iterator_category = std::random_access_iterator_tag

Iterator Traits.

Definition at line 48 of file GlobIter.h.

Constructor & Destructor Documentation

◆ GlobIter()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::GlobIter ( GlobMemType *  gmem,
PatternType const &  pat,
index_type  position = 0 
)
inline

Constructor, creates a global iterator on global memory following the element order specified by the given pattern.

Definition at line 119 of file GlobIter.h.

123  : _globmem(gmem),
124  _pattern(&pat),
125  _idx(position),
126  _max_idx(index_type(pat.size()) - 1)
127  {
128  }

Member Function Documentation

◆ dart_gptr()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR dart_gptr_t dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::dart_gptr ( ) const
inline

Explicit conversion to dart_gptr_t.

Returns
A DART global pointer to the element at the iterator's position

Definition at line 193 of file GlobIter.h.

Referenced by dash::GlobIter< value_type, Pattern_t, GlobMem_t >::operator const_pointer(), dash::GlobIter< value_type, Pattern_t, GlobMem_t >::operator pointer(), and dash::GlobIter< value_type, Pattern_t, GlobMem_t >::operator*().

194  {
195  if (_globmem == nullptr) {
196  return DART_GPTR_NULL;
197  }
198  else if (_idx > _max_idx) {
199  // Global iterator pointing past the range indexed by the pattern
200  // which is the case for .end() iterators.
201  return static_cast<dart_gptr_t>(_globmem->end());
202  }
203 
204  DASH_LOG_TRACE_VAR("GlobIter.dart_gptr()", _idx);
205  typedef typename pattern_type::local_index_t local_pos_t;
206 
207  // Global index to local index and unit:
208  local_pos_t local_pos = _pattern->local(_idx);
209  DASH_LOG_TRACE(
210  "GlobIter.dart_gptr",
211  "unit:",
212  local_pos.unit,
213  "local index:",
214  local_pos.index);
215  auto const dart_pointer = _get_pointer_at(local_pos);
216  DASH_ASSERT_MSG(
217  !DART_GPTR_ISNULL(dart_pointer), "dart pointer must not be null");
218  return dart_pointer;
219  }
#define DART_GPTR_NULL
A NULL global pointer.
Definition: dart_globmem.h:105
DART Global pointer type.
Definition: dart_globmem.h:77
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
Definition: dart_globmem.h:118

◆ global()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR const self_t& dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::global ( ) const
inline

Map iterator to global index domain.

Definition at line 328 of file GlobIter.h.

329  {
330  return *this;
331  }

◆ globmem() [1/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR const GlobMemType& dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::globmem ( ) const
inline

The instance of GlobStaticMem used by this iterator to resolve addresses in global memory.

Definition at line 353 of file GlobIter.h.

354  {
355  return *_globmem;
356  }

◆ globmem() [2/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
GlobMemType& dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::globmem ( )
inline

The instance of GlobStaticMem used by this iterator to resolve addresses in global memory.

Definition at line 362 of file GlobIter.h.

363  {
364  return *_globmem;
365  }

◆ gpos()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR index_type dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::gpos ( ) const
inline

Position of the iterator in global index range.

Definition at line 344 of file GlobIter.h.

345  {
346  return _idx;
347  }

◆ is_local()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR bool dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::is_local ( ) const
inlinenoexcept

Checks whether the element referenced by this global iterator is in the calling unit's local memory.

Definition at line 271 of file GlobIter.h.

272  {
273  return (_globmem->team().myid() == lpos().unit);
274  }
DASH_CONSTEXPR auto lpos() const
Unit and local offset at the iterator&#39;s position.
Definition: GlobIter.h:297

◆ local()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR local_type dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::local ( ) const
inline

Convert global iterator to native pointer.

Definition at line 279 of file GlobIter.h.

Referenced by dash::equal().

280  {
281  auto local_pos = lpos();
282 
283  if (local_pos.unit != _pattern->team().myid()) {
284  return nullptr;
285  }
286 
287  auto* lbegin = dash::local_begin(
288  static_cast<pointer>(_globmem->begin()), _pattern->team().myid());
289  DASH_ASSERT(lbegin);
290 
291  return std::next(lbegin, local_pos.index);
292  }
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.
Definition: GlobPtr.h:593
DASH_CONSTEXPR auto lpos() const
Unit and local offset at the iterator&#39;s position.
Definition: GlobIter.h:297

◆ lpos()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR auto dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::lpos ( ) const
inline

Unit and local offset at the iterator's position.

Definition at line 297 of file GlobIter.h.

Referenced by dash::GlobIter< value_type, Pattern_t, GlobMem_t >::is_local(), and dash::GlobIter< value_type, Pattern_t, GlobMem_t >::local().

298  {
299  DASH_LOG_TRACE_VAR("GlobIter.lpos()", _idx);
300 
301  index_type idx = _idx;
302  index_type offset = 0;
303 
304  // Convert iterator position (_idx) to local index and unit.
305  if (idx > _max_idx) {
306  idx = _max_idx;
307  offset = _idx - _max_idx;
308  DASH_ASSERT_EQ(offset, 1, "invalid index");
309  }
310  // Global index to local index and unit:
311  auto local_pos = _pattern->local(idx);
312  // Add the offset
313  local_pos.index += offset;
314 
315  DASH_LOG_TRACE(
316  "GlobIter.lpos >",
317  "unit:",
318  local_pos.unit,
319  "local index:",
320  local_pos.index);
321 
322  return local_pos;
323  }

◆ ndim()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
static constexpr dim_t dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::ndim ( )
inlinestatic

The number of dimensions of the iterator's underlying pattern.

Definition at line 158 of file GlobIter.h.

159  {
160  return NumDimensions;
161  }

◆ operator const_pointer()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator const_pointer ( ) const
inlineexplicitnoexcept

<fuchsto> TODO: Conversion from iterator to pointer looks dubios

Type conversion operator to GlobPtr.

Returns
A global reference to the element at the iterator's position

Definition at line 170 of file GlobIter.h.

171  {
172  return const_pointer(this->dart_gptr());
173  }
DASH_CONSTEXPR dart_gptr_t dart_gptr() const DASH_NOEXCEPT
Explicit conversion to dart_gptr_t.
Definition: GlobIter.h:193

◆ operator pointer()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator pointer ( )
inlineexplicit

<fuchsto> TODO: Conversion from iterator to pointer looks dubios

Type conversion operator to GlobPtr.

Returns
A global reference to the element at the iterator's position

Definition at line 182 of file GlobIter.h.

183  {
184  return pointer(this->dart_gptr());
185  }
DASH_CONSTEXPR dart_gptr_t dart_gptr() const DASH_NOEXCEPT
Explicit conversion to dart_gptr_t.
Definition: GlobIter.h:193

◆ operator*() [1/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR reference dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator* ( )
inlinenoexcept

Dereference operator.

Returns
A global reference to the element at the iterator's position.

Definition at line 226 of file GlobIter.h.

227  {
228  return reference{this->dart_gptr()};
229  }
DASH_CONSTEXPR dart_gptr_t dart_gptr() const DASH_NOEXCEPT
Explicit conversion to dart_gptr_t.
Definition: GlobIter.h:193

◆ operator*() [2/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR const_reference dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator* ( ) const
inlinenoexcept

Dereference operator.

Returns
A global reference to the element at the iterator's position.

Definition at line 236 of file GlobIter.h.

237  {
238  return const_reference{this->dart_gptr()};
239  }
DASH_CONSTEXPR dart_gptr_t dart_gptr() const DASH_NOEXCEPT
Explicit conversion to dart_gptr_t.
Definition: GlobIter.h:193

◆ operator++() [1/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR self_t& dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator++ ( )
inline

Prefix increment operator.

Definition at line 370 of file GlobIter.h.

371  {
372  ++_idx;
373  return *this;
374  }

◆ operator++() [2/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR self_t dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator++ ( int  )
inline

Postfix increment operator.

Definition at line 379 of file GlobIter.h.

380  {
381  self_t result = *this;
382  ++_idx;
383  return result;
384  }

◆ operator--() [1/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR self_t& dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator-- ( )
inline

Prefix decrement operator.

Definition at line 389 of file GlobIter.h.

390  {
391  --_idx;
392  return *this;
393  }

◆ operator--() [2/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR self_t dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator-- ( int  )
inline

Postfix decrement operator.

Definition at line 398 of file GlobIter.h.

399  {
400  self_t result = *this;
401  --_idx;
402  return result;
403  }

◆ operator[]() [1/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR reference dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator[] ( index_type  g_index)
inlinenoexcept

Subscript operator, returns global reference to element at given global index.

Parameters
g_indexThe global position of the element

Definition at line 245 of file GlobIter.h.

248  {
249  auto p = *this;
250  p += g_index;
251  return reference(p.dart_gptr());
252  }

◆ operator[]() [2/2]

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR const_reference dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::operator[] ( index_type  g_index) const
inlinenoexcept

Subscript operator, returns global reference to element at given global index.

Parameters
g_indexThe global position of the element

Definition at line 258 of file GlobIter.h.

261  {
262  auto p = *this;
263  p += g_index;
264  return const_reference(p.dart_gptr());
265  }

◆ pos()

template<typename ElementType, class PatternType, class GlobMemType, class PointerType = typename GlobMemType::void_pointer::template rebind<ElementType>, class ReferenceType = GlobRef<ElementType>>
DASH_CONSTEXPR index_type dash::GlobIter< ElementType, PatternType, GlobMemType, PointerType, ReferenceType >::pos ( ) const
inline

Position of the iterator in global index space.

Definition at line 336 of file GlobIter.h.

Referenced by dash::find(), dash::find_if(), dash::GlobIter< value_type, Pattern_t, GlobMem_t >::operator--(), and dash::Array< signal_t >::operator=().

337  {
338  return _idx;
339  }

The documentation for this class was generated from the following file: