1 #ifndef DASH__GLOB_PTR_H_ 2 #define DASH__GLOB_PTR_H_ 10 #include <dash/Exception.h> 11 #include <dash/Init.h> 13 #include <dash/atomic/Type_traits.h> 15 #include <dash/internal/Logging.h> 16 #include <dash/iterator/internal/GlobPtrBase.h> 18 #include <dash/memory/MemorySpaceBase.h> 20 std::ostream &operator<<(std::ostream &os,
const dart_gptr_t &dartptr);
32 template <
class T,
class MemSpaceT>
35 template <
class T,
class MemSpaceT>
46 template <
typename ElementType,
class GlobMemT>
51 using local_pointer_traits =
52 std::pointer_traits<typename GlobMemT::local_void_pointer>;
57 typedef ElementType value_type;
59 typedef typename GlobMemT::index_type index_type;
60 typedef typename GlobMemT::size_type size_type;
61 typedef index_type gptrdiff_t;
69 typedef GlobMemT memory_type;
78 template <
typename T,
class MemSpaceT>
81 template <
typename T,
class MemSpaceT>
82 friend std::ostream &operator<<(
85 template <
class T,
class MemSpaceT>
102 : m_dart_pointer(gptr)
109 explicit constexpr
GlobPtr(std::nullptr_t) DASH_NOEXCEPT
117 constexpr
GlobPtr(
const self_t &other) =
default;
122 self_t &
operator=(
const self_t &rhs) =
default;
147 typename =
typename std::enable_if<
150 dash::internal::is_pointer_assignable<
151 typename dash::remove_atomic<From>::type,
152 typename dash::remove_atomic<value_type>::type>::value>
156 : m_dart_pointer(other.m_dart_pointer)
163 constexpr
GlobPtr(self_t &&other) DASH_NOEXCEPT =
default;
168 self_t &
operator=(self_t &&rhs) DASH_NOEXCEPT =
default;
175 explicit operator value_type *()
const DASH_NOEXCEPT
187 explicit operator value_type *()
197 return m_dart_pointer;
205 return m_dart_pointer;
211 constexpr index_type
operator-(
const self_t &rhs)
const DASH_NOEXCEPT
309 static_cast<dart_gptr_t>(m_dart_pointer),
310 static_cast<dart_gptr_t>(other.m_dart_pointer));
316 constexpr
bool operator==(std::nullptr_t)
const DASH_NOEXCEPT
324 template <
class GlobPtrT>
325 constexpr
bool operator!=(
const GlobPtrT &other)
const DASH_NOEXCEPT
327 return !(*
this == other);
333 template <
class GlobPtrT>
334 constexpr
bool operator<(
const GlobPtrT &other)
const DASH_NOEXCEPT
336 return (other - *
this) > 0;
342 template <
class GlobPtrT>
343 constexpr
bool operator<=(
const GlobPtrT &other)
const DASH_NOEXCEPT
345 return !(*
this > other);
351 template <
class GlobPtrT>
352 constexpr
bool operator>(
const GlobPtrT &other)
const DASH_NOEXCEPT
354 return (*
this - other) > 0;
360 template <
class GlobPtrT>
361 constexpr
bool operator>=(
const GlobPtrT &other)
const DASH_NOEXCEPT
363 return (*
this - other) >= 0;
407 void *addr =
nullptr;
409 return static_cast<value_type *
>(addr);
422 void *addr =
nullptr;
424 return static_cast<const value_type *
>(addr);
434 m_dart_pointer.
unitid = unit_id.id;
437 constexpr
auto get_unit()
const DASH_NOEXCEPT {
447 return dash::internal::is_local(m_dart_pointer);
450 constexpr
explicit operator bool()
const DASH_NOEXCEPT
456 void increment(size_type offs) DASH_NOEXCEPT
465 "GlobPtr.increment(offs)",
466 "cannot increment a global null pointer");
469 auto& reg = dash::internal::MemorySpaceRegistry::GetInstance();
470 auto const * mem_space =
static_cast<const GlobMemT *
>(reg.lookup(m_dart_pointer));
472 auto const newPtr = dash::internal::increment<value_type>(
480 m_dart_pointer = newPtr;
483 void decrement(size_type offs) DASH_NOEXCEPT
493 "GlobPtr.increment(offs)",
494 "cannot decrement a global null pointer");
497 auto & reg = dash::internal::MemorySpaceRegistry::GetInstance();
498 auto const *mem_space =
499 static_cast<const GlobMemT *
>(reg.lookup(m_dart_pointer));
502 auto const newPtr = dash::internal::decrement<value_type>(
510 m_dart_pointer = newPtr;
514 template <
typename T,
class MemSpaceT>
515 std::ostream &operator<<(std::ostream &os, const GlobPtr<T, MemSpaceT> &gptr)
517 std::ostringstream ss;
521 "u%06X|f%02X|s%04X|t%04X|o%016lX",
522 gptr.m_dart_pointer.unitid,
523 gptr.m_dart_pointer.flags,
524 gptr.m_dart_pointer.segid,
525 gptr.m_dart_pointer.teamid,
526 gptr.m_dart_pointer.addr_or_offs.offset);
527 ss <<
"dash::GlobPtr<" <<
typeid(T).name() <<
">(" << buf <<
")";
528 return operator<<(os, ss.str());
546 template <
class T,
class MemSpaceT>
558 DASH_ASSERT_EQ(
begin.teamid,
end.teamid,
"teamid must be equal");
559 DASH_ASSERT_EQ(
begin.segid,
end.segid,
"segid must be equal");
561 auto & reg = dash::internal::MemorySpaceRegistry::GetInstance();
562 auto const *mem_space =
563 static_cast<const MemSpaceT *
>(reg.lookup(
begin));
565 return dash::internal::distance<T>(
567 static_cast<dart_gptr_t>(gend),
586 template <
class T,
class MemSpaceT>
587 DASH_CONSTEXPR
inline typename std::enable_if<
590 MemSpaceT>::memory_space_layout_tag,
604 #endif // DASH__GLOB_PTR_H_ internal::default_signed_index gptrdiff_t
Difference type for global pointers.
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.
self_t & operator=(const self_t &rhs)=default
Assignment operator.
self_t operator--(int) DASH_NOEXCEPT
Postfix decrement operator.
value_type * local()
Conversion to local pointer.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
const value_type * local() const
Conversion to local const pointer.
self_t & operator=(std::nullptr_t)
nullptr assignment operator.
constexpr bool operator==(const GlobPtr &other) const DASH_NOEXCEPT
Equality comparison operator.
self_t & operator-=(index_type n) DASH_NOEXCEPT
Pointer decrement operator.
union dart_gptr_t::@0 addr_or_offs
Absolute address or relative offset.
constexpr GlobPtr()=default
Default constructor, underlying global address is unspecified.
constexpr bool operator<=(const GlobPtrT &other) const DASH_NOEXCEPT
Less-equal comparison operator.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
constexpr bool operator>=(const GlobPtrT &other) const DASH_NOEXCEPT
Greater-equal comparison operator.
constexpr GlobPtr(dart_gptr_t gptr) DASH_NOEXCEPT
Constructor, specifies underlying global address.
self_t operator-(index_type n) const DASH_NOEXCEPT
Pointer decrement operator.
constexpr GlobRef< const value_type > operator[](gptrdiff_t n) const DASH_NOEXCEPT
Subscript operator.
constexpr GlobRef< const value_type > operator*() const DASH_NOEXCEPT
Dereference operator.
self_t & operator--() DASH_NOEXCEPT
Prefix decrement operator.
dart_unit_t unitid
The unit holding the memory element.
constexpr bool operator!=(const GlobPtrT &other) const DASH_NOEXCEPT
Inequality comparison operator.
GlobRef< value_type > operator[](gptrdiff_t n) DASH_NOEXCEPT
Subscript assignment operator.
constexpr GlobPtr(const GlobPtr< From, GlobMemT > &other) DASH_NOEXCEPT
Implicit Converting Constructor, only allowed if one of the following conditions is satisfied: ...
void set_unit(team_unit_t unit_id) DASH_NOEXCEPT
Set the global pointer's associated unit.
#define DART_GPTR_NULL
A NULL global pointer.
friend dash::gptrdiff_t distance(GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
Returns the number of hops from gbegin to gend.
DART Global pointer type.
constexpr index_type operator-(const self_t &rhs) const DASH_NOEXCEPT
Pointer offset difference operator.
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
constexpr bool operator<(const GlobPtrT &other) const DASH_NOEXCEPT
Less comparison operator.
GlobRef< value_type > operator*() DASH_NOEXCEPT
Dereference operator.
#define DART_GPTR_EQUAL(gptr1_, gptr2_)
Compare two global pointers.
self_t operator++(int) DASH_NOEXCEPT
Postfix increment operator.
constexpr dart_gptr_t dart_gptr() const DASH_NOEXCEPT
The pointer's underlying global address.
dart_ret_t dart_gptr_getaddr(const dart_gptr_t gptr, void **addr)
Get the local memory address for the specified global pointer gptr.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
constexpr bool operator==(std::nullptr_t) const DASH_NOEXCEPT
Equality comparison operator.
self_t operator+(index_type n) const DASH_NOEXCEPT
Pointer increment operator.
Pointer in global memory space with random access arithmetics.
constexpr bool operator>(const GlobPtrT &other) const DASH_NOEXCEPT
Greater comparison operator.
constexpr GlobPtr(std::nullptr_t) DASH_NOEXCEPT
Constructor for conversion of std::nullptr_t.
self_t & operator++() DASH_NOEXCEPT
Prefix increment operator.
typename details::memspace_traits_layout_tag< MemSpace >::type memory_space_layout_tag
May be contiguous or noncontiguous.
self_t & operator+=(index_type n) DASH_NOEXCEPT
Pointer increment operator.
bool is_local() const
Check whether the global pointer is in the local address space the pointer's associated unit...
dash::gptrdiff_t distance(GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
Returns the number of hops from gbegin to gend.