DASH  0.3.0
dash::GlobPtr< ElementType, GlobMemT > Class Template Reference

Pointer in global memory space with random access arithmetics. More...

#include <GlobPtr.h>

Public Types

typedef ElementType value_type
 
typedef GlobPtr< const ElementType, GlobMemT > const_type
 
typedef GlobMemT::index_type index_type
 
typedef GlobMemT::size_type size_type
 
typedef index_type gptrdiff_t
 
typedef local_pointer_traits::template rebind< value_type > local_type
 
typedef local_pointer_traits::template rebind< value_type const > const_local_type
 
typedef GlobMemT memory_type
 
template<typename T >
using rebind = dash::GlobPtr< T, GlobMemT >
 Rebind to a different type of pointer. More...
 

Public Member Functions

constexpr GlobPtr ()=default
 Default constructor, underlying global address is unspecified. More...
 
constexpr GlobPtr (dart_gptr_t gptr) DASH_NOEXCEPT
 Constructor, specifies underlying global address. More...
 
constexpr GlobPtr (std::nullptr_t) DASH_NOEXCEPT
 Constructor for conversion of std::nullptr_t. More...
 
constexpr GlobPtr (const self_t &other)=default
 Copy constructor. More...
 
self_toperator= (const self_t &rhs)=default
 Assignment operator. More...
 
self_toperator= (std::nullptr_t)
 nullptr assignment operator. More...
 
template<typename From , typename = typename std::enable_if< dash::internal::is_pointer_assignable< typename dash::remove_atomic<From>::type, typename dash::remove_atomic<value_type>::type>::value> ::type>
constexpr GlobPtr (const GlobPtr< From, GlobMemT > &other) DASH_NOEXCEPT
 Implicit Converting Constructor, only allowed if one of the following conditions is satisfied: More...
 
constexpr GlobPtr (self_t &&other) DASH_NOEXCEPT=default
 Move constructor. More...
 
self_toperator= (self_t &&rhs) DASH_NOEXCEPT=default
 Move-assignment operator. More...
 
 operator value_type * () const DASH_NOEXCEPT
 Converts pointer to its referenced native pointer or nullptr if the GlobPtr does not point to a local address. More...
 
 operator value_type * ()
 Conversion operator to local pointer. More...
 
constexpr operator dart_gptr_t () const DASH_NOEXCEPT
 Converts pointer to its underlying global address. More...
 
constexpr dart_gptr_t dart_gptr () const DASH_NOEXCEPT
 The pointer's underlying global address. More...
 
constexpr index_type operator- (const self_t &rhs) const DASH_NOEXCEPT
 Pointer offset difference operator. More...
 
self_toperator++ () DASH_NOEXCEPT
 Prefix increment operator. More...
 
self_t operator++ (int) DASH_NOEXCEPT
 Postfix increment operator. More...
 
self_t operator+ (index_type n) const DASH_NOEXCEPT
 Pointer increment operator. More...
 
self_toperator+= (index_type n) DASH_NOEXCEPT
 Pointer increment operator. More...
 
self_toperator-- () DASH_NOEXCEPT
 Prefix decrement operator. More...
 
self_t operator-- (int) DASH_NOEXCEPT
 Postfix decrement operator. More...
 
self_t operator- (index_type n) const DASH_NOEXCEPT
 Pointer decrement operator. More...
 
self_toperator-= (index_type n) DASH_NOEXCEPT
 Pointer decrement operator. More...
 
constexpr bool operator== (const GlobPtr &other) const DASH_NOEXCEPT
 Equality comparison operator. More...
 
constexpr bool operator== (std::nullptr_t) const DASH_NOEXCEPT
 Equality comparison operator. More...
 
template<class GlobPtrT >
constexpr bool operator!= (const GlobPtrT &other) const DASH_NOEXCEPT
 Inequality comparison operator. More...
 
template<class GlobPtrT >
constexpr bool operator< (const GlobPtrT &other) const DASH_NOEXCEPT
 Less comparison operator. More...
 
template<class GlobPtrT >
constexpr bool operator<= (const GlobPtrT &other) const DASH_NOEXCEPT
 Less-equal comparison operator. More...
 
template<class GlobPtrT >
constexpr bool operator> (const GlobPtrT &other) const DASH_NOEXCEPT
 Greater comparison operator. More...
 
template<class GlobPtrT >
constexpr bool operator>= (const GlobPtrT &other) const DASH_NOEXCEPT
 Greater-equal comparison operator. More...
 
constexpr GlobRef< const value_type > operator[] (gptrdiff_t n) const DASH_NOEXCEPT
 Subscript operator. More...
 
GlobRef< value_type > operator[] (gptrdiff_t n) DASH_NOEXCEPT
 Subscript assignment operator. More...
 
GlobRef< value_type > operator* () DASH_NOEXCEPT
 Dereference operator. More...
 
constexpr GlobRef< const value_type > operator* () const DASH_NOEXCEPT
 Dereference operator. More...
 
value_type * local ()
 Conversion to local pointer. More...
 
const value_type * local () const
 Conversion to local const pointer. More...
 
void set_unit (team_unit_t unit_id) DASH_NOEXCEPT
 Set the global pointer's associated unit. More...
 
constexpr auto get_unit () const DASH_NOEXCEPT
 
bool is_local () const
 Check whether the global pointer is in the local address space the pointer's associated unit. More...
 
constexpr operator bool () const DASH_NOEXCEPT
 

Friends

template<typename T , class MemSpaceT >
std::ostream & operator<< (std::ostream &os, const GlobPtr< T, MemSpaceT > &gptr)
 
template<class T , class MemSpaceT >
dash::gptrdiff_t distance (GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
 Returns the number of hops from gbegin to gend. More...
 

Detailed Description

template<typename ElementType, class GlobMemT>
class dash::GlobPtr< ElementType, GlobMemT >

Pointer in global memory space with random access arithmetics.

Forward declarations.

See also
GlobIter
Implemented concept:
DashMemorySpaceConcept

Definition at line 33 of file GlobPtr.h.

Member Typedef Documentation

◆ rebind

template<typename ElementType, class GlobMemT>
template<typename T >
using dash::GlobPtr< ElementType, GlobMemT >::rebind = dash::GlobPtr<T, GlobMemT>

Rebind to a different type of pointer.

Definition at line 75 of file GlobPtr.h.

Constructor & Destructor Documentation

◆ GlobPtr() [1/6]

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( )
default

Default constructor, underlying global address is unspecified.

Referenced by dash::GlobPtr< event_ctr_t, globmem_t >::GlobPtr().

◆ GlobPtr() [2/6]

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( dart_gptr_t  gptr)
inlineexplicit

Constructor, specifies underlying global address.

Definition at line 101 of file GlobPtr.h.

102  : m_dart_pointer(gptr)
103  {
104  }

◆ GlobPtr() [3/6]

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( std::nullptr_t  )
inlineexplicit

Constructor for conversion of std::nullptr_t.

Definition at line 109 of file GlobPtr.h.

110  : m_dart_pointer(DART_GPTR_NULL)
111  {
112  }
#define DART_GPTR_NULL
A NULL global pointer.
Definition: dart_globmem.h:105

◆ GlobPtr() [4/6]

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( const self_t other)
default

Copy constructor.

◆ GlobPtr() [5/6]

template<typename ElementType, class GlobMemT>
template<typename From , typename = typename std::enable_if< dash::internal::is_pointer_assignable< typename dash::remove_atomic<From>::type, typename dash::remove_atomic<value_type>::type>::value> ::type>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( const GlobPtr< From, GlobMemT > &  other)
inline

Implicit Converting Constructor, only allowed if one of the following conditions is satisfied:

  • Either From or To (value_type) are void. Like in C we can convert any pointer type to a void pointer and back again.
  • From::value_type& is assignable to value_type&.

NOTE: Const correctness is considered. We can assign a GlobPtr<const T> to a GlobPtr<T> but not the other way around

Definition at line 155 of file GlobPtr.h.

156  : m_dart_pointer(other.m_dart_pointer)
157  {
158  }

◆ GlobPtr() [6/6]

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::GlobPtr ( self_t &&  other)
default

Move constructor.

Member Function Documentation

◆ dart_gptr()

template<typename ElementType, class GlobMemT>
constexpr dart_gptr_t dash::GlobPtr< ElementType, GlobMemT >::dart_gptr ( ) const
inline

The pointer's underlying global address.

Definition at line 203 of file GlobPtr.h.

Referenced by dash::GlobLocalMemoryPool< dash::HostSpace >::flush_local().

204  {
205  return m_dart_pointer;
206  }

◆ is_local()

template<typename ElementType, class GlobMemT>
bool dash::GlobPtr< ElementType, GlobMemT >::is_local ( ) const
inline

Check whether the global pointer is in the local address space the pointer's associated unit.

Definition at line 445 of file GlobPtr.h.

446  {
447  return dash::internal::is_local(m_dart_pointer);
448  }

◆ local() [1/2]

template<typename ElementType, class GlobMemT>
value_type* dash::GlobPtr< ElementType, GlobMemT >::local ( )
inline

Conversion to local pointer.

Returns
A native pointer to the local element referenced by this GlobPtr instance, or nullptr if the referenced element is not local to the calling unit.

Definition at line 405 of file GlobPtr.h.

Referenced by dash::GlobPtr< event_ctr_t, globmem_t >::operator value_type *().

406  {
407  void *addr = nullptr;
408  if (dart_gptr_getaddr(m_dart_pointer, &addr) == DART_OK) {
409  return static_cast<value_type *>(addr);
410  }
411  return nullptr;
412  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_gptr_getaddr(const dart_gptr_t gptr, void **addr)
Get the local memory address for the specified global pointer gptr.

◆ local() [2/2]

template<typename ElementType, class GlobMemT>
const value_type* dash::GlobPtr< ElementType, GlobMemT >::local ( ) const
inline

Conversion to local const pointer.

Returns
A native pointer to the local element referenced by this GlobPtr instance, or nullptr if the referenced element is not local to the calling unit.

Definition at line 421 of file GlobPtr.h.

421  {
422  void *addr = nullptr;
423  if (dart_gptr_getaddr(m_dart_pointer, &addr) == DART_OK) {
424  return static_cast<const value_type *>(addr);
425  }
426  return nullptr;
427  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_gptr_getaddr(const dart_gptr_t gptr, void **addr)
Get the local memory address for the specified global pointer gptr.

◆ operator dart_gptr_t()

template<typename ElementType, class GlobMemT>
constexpr dash::GlobPtr< ElementType, GlobMemT >::operator dart_gptr_t ( ) const
inlineexplicit

Converts pointer to its underlying global address.

Definition at line 195 of file GlobPtr.h.

196  {
197  return m_dart_pointer;
198  }

◆ operator value_type *() [1/2]

template<typename ElementType, class GlobMemT>
dash::GlobPtr< ElementType, GlobMemT >::operator value_type * ( ) const
inlineexplicit

Converts pointer to its referenced native pointer or nullptr if the GlobPtr does not point to a local address.

Definition at line 175 of file GlobPtr.h.

176  {
177  return local();
178  }
value_type * local()
Conversion to local pointer.
Definition: GlobPtr.h:405

◆ operator value_type *() [2/2]

template<typename ElementType, class GlobMemT>
dash::GlobPtr< ElementType, GlobMemT >::operator value_type * ( )
inlineexplicit

Conversion operator to local pointer.

Returns
A native pointer to the local element referenced by this GlobPtr instance, or nullptr if the referenced element is not local to the calling unit.

Definition at line 187 of file GlobPtr.h.

188  {
189  return local();
190  }
value_type * local()
Conversion to local pointer.
Definition: GlobPtr.h:405

◆ operator!=()

template<typename ElementType, class GlobMemT>
template<class GlobPtrT >
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator!= ( const GlobPtrT &  other) const
inline

Inequality comparison operator.

Definition at line 325 of file GlobPtr.h.

326  {
327  return !(*this == other);
328  }

◆ operator*() [1/2]

template<typename ElementType, class GlobMemT>
GlobRef<value_type> dash::GlobPtr< ElementType, GlobMemT >::operator* ( )
inline

Dereference operator.

Definition at line 385 of file GlobPtr.h.

386  {
387  return GlobRef<value_type>(*this);
388  }

◆ operator*() [2/2]

template<typename ElementType, class GlobMemT>
constexpr GlobRef<const value_type> dash::GlobPtr< ElementType, GlobMemT >::operator* ( ) const
inline

Dereference operator.

Definition at line 393 of file GlobPtr.h.

394  {
395  return GlobRef<const value_type>(*this);
396  }

◆ operator+()

template<typename ElementType, class GlobMemT>
self_t dash::GlobPtr< ElementType, GlobMemT >::operator+ ( index_type  n) const
inline

Pointer increment operator.

Definition at line 238 of file GlobPtr.h.

239  {
240  self_t res(*this);
241  res += n;
242  return res;
243  }

◆ operator++() [1/2]

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator++ ( )
inline

Prefix increment operator.

Definition at line 219 of file GlobPtr.h.

220  {
221  increment(1);
222  return *this;
223  }

◆ operator++() [2/2]

template<typename ElementType, class GlobMemT>
self_t dash::GlobPtr< ElementType, GlobMemT >::operator++ ( int  )
inline

Postfix increment operator.

Definition at line 228 of file GlobPtr.h.

229  {
230  self_t res(*this);
231  increment(1);
232  return res;
233  }

◆ operator+=()

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator+= ( index_type  n)
inline

Pointer increment operator.

Definition at line 248 of file GlobPtr.h.

249  {
250  if (n >= 0) {
251  increment(n);
252  }
253  else {
254  decrement(-n);
255  }
256  return *this;
257  }

◆ operator-() [1/2]

template<typename ElementType, class GlobMemT>
constexpr index_type dash::GlobPtr< ElementType, GlobMemT >::operator- ( const self_t rhs) const
inline

Pointer offset difference operator.

Definition at line 211 of file GlobPtr.h.

212  {
213  return dash::distance(rhs, *this);
214  }
dash::gptrdiff_t distance(GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
Returns the number of hops from gbegin to gend.
Definition: GlobPtr.h:547

◆ operator-() [2/2]

template<typename ElementType, class GlobMemT>
self_t dash::GlobPtr< ElementType, GlobMemT >::operator- ( index_type  n) const
inline

Pointer decrement operator.

Definition at line 281 of file GlobPtr.h.

282  {
283  self_t res(*this);
284  res -= n;
285  return res;
286  }

◆ operator--() [1/2]

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator-- ( )
inline

Prefix decrement operator.

Definition at line 262 of file GlobPtr.h.

263  {
264  decrement(1);
265  return *this;
266  }

◆ operator--() [2/2]

template<typename ElementType, class GlobMemT>
self_t dash::GlobPtr< ElementType, GlobMemT >::operator-- ( int  )
inline

Postfix decrement operator.

Definition at line 271 of file GlobPtr.h.

272  {
273  self_t res(*this);
274  decrement(1);
275  return res;
276  }

◆ operator-=()

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator-= ( index_type  n)
inline

Pointer decrement operator.

Definition at line 291 of file GlobPtr.h.

292  {
293  if (n >= 0) {
294  decrement(n);
295  }
296  else {
297  increment(-n);
298  }
299  return *this;
300  }

◆ operator<()

template<typename ElementType, class GlobMemT>
template<class GlobPtrT >
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator< ( const GlobPtrT &  other) const
inline

Less comparison operator.

Definition at line 334 of file GlobPtr.h.

335  {
336  return (other - *this) > 0;
337  }

◆ operator<=()

template<typename ElementType, class GlobMemT>
template<class GlobPtrT >
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator<= ( const GlobPtrT &  other) const
inline

Less-equal comparison operator.

Definition at line 343 of file GlobPtr.h.

344  {
345  return !(*this > other);
346  }

◆ operator=() [1/3]

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator= ( const self_t rhs)
default

Assignment operator.

Referenced by dash::GlobPtr< event_ctr_t, globmem_t >::GlobPtr().

◆ operator=() [2/3]

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator= ( std::nullptr_t  )
inline

nullptr assignment operator.

Definition at line 127 of file GlobPtr.h.

127  {
128  m_dart_pointer = DART_GPTR_NULL;
129 
130  return *this;
131  }
#define DART_GPTR_NULL
A NULL global pointer.
Definition: dart_globmem.h:105

◆ operator=() [3/3]

template<typename ElementType, class GlobMemT>
self_t& dash::GlobPtr< ElementType, GlobMemT >::operator= ( self_t &&  rhs)
default

Move-assignment operator.

◆ operator==() [1/2]

template<typename ElementType, class GlobMemT>
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator== ( const GlobPtr< ElementType, GlobMemT > &  other) const
inline

Equality comparison operator.

Definition at line 306 of file GlobPtr.h.

307  {
308  return DART_GPTR_EQUAL(
309  static_cast<dart_gptr_t>(m_dart_pointer),
310  static_cast<dart_gptr_t>(other.m_dart_pointer));
311  }
#define DART_GPTR_EQUAL(gptr1_, gptr2_)
Compare two global pointers.
Definition: dart_globmem.h:128

◆ operator==() [2/2]

template<typename ElementType, class GlobMemT>
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator== ( std::nullptr_t  ) const
inline

Equality comparison operator.

Definition at line 316 of file GlobPtr.h.

317  {
318  return DART_GPTR_ISNULL(static_cast<dart_gptr_t>(m_dart_pointer));
319  }
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
Definition: dart_globmem.h:118

◆ operator>()

template<typename ElementType, class GlobMemT>
template<class GlobPtrT >
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator> ( const GlobPtrT &  other) const
inline

Greater comparison operator.

Definition at line 352 of file GlobPtr.h.

353  {
354  return (*this - other) > 0;
355  }

◆ operator>=()

template<typename ElementType, class GlobMemT>
template<class GlobPtrT >
constexpr bool dash::GlobPtr< ElementType, GlobMemT >::operator>= ( const GlobPtrT &  other) const
inline

Greater-equal comparison operator.

Definition at line 361 of file GlobPtr.h.

362  {
363  return (*this - other) >= 0;
364  }

◆ operator[]() [1/2]

template<typename ElementType, class GlobMemT>
constexpr GlobRef<const value_type> dash::GlobPtr< ElementType, GlobMemT >::operator[] ( gptrdiff_t  n) const
inline

Subscript operator.

Definition at line 369 of file GlobPtr.h.

370  {
371  return GlobRef<const value_type>(self_t((*this) + n));
372  }

◆ operator[]() [2/2]

template<typename ElementType, class GlobMemT>
GlobRef<value_type> dash::GlobPtr< ElementType, GlobMemT >::operator[] ( gptrdiff_t  n)
inline

Subscript assignment operator.

Definition at line 377 of file GlobPtr.h.

378  {
379  return GlobRef<value_type>(self_t((*this) + n));
380  }

◆ set_unit()

template<typename ElementType, class GlobMemT>
void dash::GlobPtr< ElementType, GlobMemT >::set_unit ( team_unit_t  unit_id)
inline

Set the global pointer's associated unit.

Definition at line 432 of file GlobPtr.h.

433  {
434  m_dart_pointer.unitid = unit_id.id;
435  }
dart_unit_t unitid
The unit holding the memory element.
Definition: dart_globmem.h:83

Friends And Related Function Documentation

◆ distance

template<typename ElementType, class GlobMemT>
template<class T , class MemSpaceT >
dash::gptrdiff_t distance ( GlobPtr< T, MemSpaceT >  gbegin,
GlobPtr< T, MemSpaceT >  gend 
)
friend

Returns the number of hops from gbegin to gend.

Equivalent to (gend - gbegin).

Note
The distance is calculate by considering the memory traits of the underlying global memory distances.
Returns
The number of increments to go from gbegin to gend
Implemented concept:
DashMemorySpaceConcept

Definition at line 547 of file GlobPtr.h.

552 {
553  using memory_space_traits = dash::memory_space_traits<MemSpaceT>;
554 
555  auto const begin = static_cast<dart_gptr_t>(gbegin);
556  auto const end = static_cast<dart_gptr_t>(gbegin);
557 
558  DASH_ASSERT_EQ(begin.teamid, end.teamid, "teamid must be equal");
559  DASH_ASSERT_EQ(begin.segid, end.segid, "segid must be equal");
560 
561  auto & reg = dash::internal::MemorySpaceRegistry::GetInstance();
562  auto const *mem_space =
563  static_cast<const MemSpaceT *>(reg.lookup(begin));
564 
565  return dash::internal::distance<T>(
566  static_cast<dart_gptr_t>(gbegin),
567  static_cast<dart_gptr_t>(gend),
568  mem_space,
570 }
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
Definition: Range.h:98
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Definition: Range.h:89
DART Global pointer type.
Definition: dart_globmem.h:77
typename details::memspace_traits_layout_tag< MemSpace >::type memory_space_layout_tag
May be contiguous or noncontiguous.

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