DASH  0.3.0
dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType > Class Template Reference

Iterator on local buckets. More...

#include <GlobHeapLocalPtr.h>

Public Types

typedef IndexType index_type
 
typedef std::make_unsigned< index_type >::type size_type
 
typedef std::random_access_iterator_tag iterator_category
 Type definitions required for std::iterator_traits: More...
 
typedef IndexType difference_type
 
typedef ElementType value_type
 
typedef ElementType * pointer
 
typedef ElementType & reference
 
typedef internal::glob_dynamic_mem_bucket_type< size_type, value_type > bucket_type
 

Public Member Functions

template<typename BucketIter >
 GlobHeapLocalPtr (const BucketIter &bucket_first, const BucketIter &bucket_last, index_type position, const BucketIter &bucket_it, index_type bucket_phase)
 
template<typename BucketIter >
 GlobHeapLocalPtr (const BucketIter &bucket_first, const BucketIter &bucket_last, index_type position)
 
 GlobHeapLocalPtr (const self_t &other)
 
self_toperator= (const self_t &rhs)
 
template<typename I_ , typename P_ , typename R_ >
 operator GlobHeapLocalPtr< const value_type, I_, P_, R_ > () const
 Conversion to const iterator. More...
 
 GlobHeapLocalPtr (std::nullptr_t)
 
self_toperator= (std::nullptr_t)
 
bool operator== (std::nullptr_t) const
 
bool operator!= (std::nullptr_t) const
 
reference operator* ()
 Dereference operator. More...
 
reference operator[] (index_type offset)
 Random access operator. More...
 
 operator pointer () const
 Conversion to native pointer. More...
 
self_toperator++ ()
 
self_toperator-- ()
 
self_t operator++ (int)
 
self_t operator-- (int)
 
self_toperator+= (int offset)
 
self_toperator-= (int offset)
 
self_t operator+ (int offset) const
 
self_t operator- (int offset) const
 
index_type operator+ (const self_t &other) const
 
index_type operator- (const self_t &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator< (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator<= (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator> (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator>= (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator== (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
template<typename E_ , typename I_ , typename P_ , typename R_ >
bool operator!= (const GlobHeapLocalPtr< E_, I_, P_, R_ > &other) const
 
constexpr bool is_local () const
 Whether the pointer references an element in local memory space. More...
 
index_type pos () const
 Position of the pointer relative to its referenced memory space. More...
 

Friends

template<typename E_ , typename I_ , typename P_ , typename R_ >
std::ostream & dash::operator<< (std::ostream &os, const dash::GlobHeapLocalPtr< E_, I_, P_, R_ > &it)
 

Detailed Description

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
class dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >

Iterator on local buckets.

Represents local pointer type.

Definition at line 32 of file GlobHeapLocalPtr.h.

Member Typedef Documentation

◆ iterator_category

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
typedef std::random_access_iterator_tag dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::iterator_category

Type definitions required for std::iterator_traits:

Definition at line 58 of file GlobHeapLocalPtr.h.

Member Function Documentation

◆ is_local()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
constexpr bool dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::is_local ( ) const
inline

Whether the pointer references an element in local memory space.

Returns
true

Definition at line 371 of file GlobHeapLocalPtr.h.

372  {
373  return true;
374  }

◆ operator GlobHeapLocalPtr< const value_type, I_, P_, R_ >()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
template<typename I_ , typename P_ , typename R_ >
dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::operator GlobHeapLocalPtr< const value_type, I_, P_, R_ > ( ) const
inline

Conversion to const iterator.

Definition at line 152 of file GlobHeapLocalPtr.h.

153  {
154  if (_is_nullptr) {
155  return GlobHeapLocalPtr<const value_type, I_, P_, R_>(nullptr);
156  }
157  return GlobHeapLocalPtr<const value_type, I_, P_, R_>(
158  _bucket_first,
159  _bucket_last,
160  _idx,
161  _bucket_it,
162  _bucket_phase);
163  }

◆ operator pointer()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::operator pointer ( ) const
inlineexplicit

Conversion to native pointer.

Use with caution: This conversion returns a pointer a that does not iterate over buckets, pointer arithmetics may lead to undefined behaviour.

Definition at line 232 of file GlobHeapLocalPtr.h.

233  {
234  DASH_LOG_TRACE("GlobHeapLocalPtr.pointer()");
235  pointer lptr = nullptr;
236  if (_is_nullptr) {
237  DASH_LOG_TRACE("GlobHeapLocalPtr.pointer", "is nullptr");
238  } else {
239  auto bucket_size = _bucket_it->size;
240  // This iterator type represents a local pointer so no bounds checks
241  // have to be performed in pointer arithmetics.
242  // Moving a pointer to out-of-bounds address is allowed, however
243  // dereferencing it will lead to segfault. This is a prerequisite for
244  // many common pointer arithmetic use cases.
245  // Example:
246  // value = *((globmem.lend() + 2) - 3);
247  // is a valid operation and equivalent to
248  // value = *(globmem.lend() + (2 - 3));
249  // as it creates a temporary pointer to an address beyond _lend (+2)
250  // which is then moved back into valid memory range (-3).
251  if (_bucket_it == _bucket_last) {
252  DASH_LOG_TRACE("GlobHeapLocalPtr.pointer", "position at lend");
253  } else if (_bucket_phase >= bucket_size) {
254  DASH_LOG_TRACE("GlobHeapLocalPtr.pointer",
255  "bucket size:", bucket_size, ",",
256  "bucket phase:", _bucket_phase);
257  DASH_LOG_TRACE("GlobHeapLocalPtr.pointer",
258  "note: iterator position out of bounds (lend?)");
259  }
260  lptr = _bucket_it->lptr + _bucket_phase;
261  }
262  DASH_LOG_TRACE_VAR("GlobHeapLocalPtr.pointer >", lptr);
263  return lptr;
264  }

◆ operator*()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
reference dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::operator* ( )
inline

Dereference operator.

Definition at line 188 of file GlobHeapLocalPtr.h.

189  {
190  DASH_ASSERT(!_is_nullptr);
191  if (_bucket_phase > _bucket_it->size) {
192  DASH_THROW(dash::exception::OutOfRange,
193  "dereferenced position " << _idx << " is out of range: " <<
194  "bucket phase: " << _bucket_phase << ", " <<
195  "bucket size: " << _bucket_it->size);
196  }
197  return _bucket_it->lptr[_bucket_phase];
198  }

◆ operator[]()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
reference dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::operator[] ( index_type  offset)
inline

Random access operator.

Definition at line 203 of file GlobHeapLocalPtr.h.

204  {
205  DASH_ASSERT(!_is_nullptr);
206  if (_bucket_phase + offset < _bucket_it->size) {
207  // element is in bucket currently referenced by this iterator:
208  return _bucket_it->lptr[_bucket_phase + offset];
209  } else {
210  // find bucket containing element at given offset:
211  for (auto b_it = _bucket_it; b_it != _bucket_last; ++b_it) {
212  if (offset >= b_it->size) {
213  offset -= b_it->size;
214  } else if (offset < b_it->size) {
215  return b_it->lptr[offset];
216  }
217  }
218  }
219  DASH_THROW(dash::exception::OutOfRange,
220  "dereferenced position " << _idx + offset << " " <<
221  "is out of range: pointer position: " << _idx << ", " <<
222  "offset: " << offset);
223  }
size_t size()
Return the number of units in the global team.

◆ pos()

template<typename ElementType, typename IndexType, typename PointerType = ElementType *, typename ReferenceType = ElementType &>
index_type dash::GlobHeapLocalPtr< ElementType, IndexType, PointerType, ReferenceType >::pos ( ) const
inline

Position of the pointer relative to its referenced memory space.

Definition at line 379 of file GlobHeapLocalPtr.h.

380  {
381  return _idx;
382  }

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