1 #ifndef DASH__GLOBREF_H_ 2 #define DASH__GLOBREF_H_ 4 #include <dash/GlobPtr.h> 5 #include <dash/Onesided.h> 6 #include <dash/iterator/internal/GlobRefBase.h> 15 template<
typename T,
class MemSpaceT>
class GlobPtr;
21 friend std::ostream & operator<<(
23 const GlobRef<U> & gref);
25 template <
typename ElementT>
30 using const_value_type =
typename std::add_const<T>::type;
31 using nonconst_value_type =
typename std::remove_const<T>::type;
32 using self_t = GlobRef<T>;
33 using const_type = GlobRef<const_value_type>;
36 template <
class _T,
class _M>
39 template <
class _T,
class _Pat,
class _M,
class _Ptr,
class _Ref>
40 friend class GlobIter;
42 template <
class _T,
class _Pat,
class _M,
class _Ptr,
class _Ref>
43 friend class GlobViewIter;
50 template<
class ElementT,
class MemSpaceT>
53 const GlobPtr<ElementT, MemSpaceT> & gptr)
54 : GlobRef(gptr.dart_gptr())
84 long = internal::enable_implicit_copy_ctor<value_type, _T>::value>
98 int = internal::enable_explicit_copy_ctor<value_type, _T>::value>
110 long = internal::enable_implicit_copy_ctor<value_type, _T>::value>
112 : _gptr(gref.dart_gptr())
118 int = internal::enable_explicit_copy_ctor<value_type, _T>::value>
128 :_gptr(std::move(other._gptr))
130 DASH_LOG_TRACE(
"GlobRef.GlobRef(GlobRef &&)", _gptr);
141 set(
static_cast<T
>(other));
149 DASH_LOG_TRACE(
"GlobRef.operator=(GlobRef &&)", _gptr);
163 operator nonconst_value_type()
const {
164 DASH_LOG_TRACE(
"GlobRef.T()",
"conversion operator");
165 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
166 nonconst_value_type t;
167 dash::internal::get_blocking(_gptr, &t, 1);
168 DASH_LOG_TRACE_VAR(
"GlobRef.T >", _gptr);
172 template <
typename ValueT>
174 ValueT val = other.get();
175 return operator==(val);
178 template <
typename ValueT>
180 return !(*
this == other);
183 template<
typename ValueT>
184 constexpr
bool operator==(
const ValueT& value)
const 186 return static_cast<T
>(*this) == value;
189 template<
typename ValueT>
190 constexpr
bool operator!=(
const ValueT& value)
const 192 return !(*
this == value);
196 set(
const value_type & val)
const {
197 static_assert(std::is_same<value_type, nonconst_value_type>::value,
198 "Cannot modify value referenced by GlobRef<const T>!");
200 DASH_LOG_TRACE_VAR(
"GlobRef.set()", val);
201 DASH_LOG_TRACE_VAR(
"GlobRef.set", _gptr);
204 dash::internal::put_blocking(_gptr, &val, 1);
205 DASH_LOG_TRACE_VAR(
"GlobRef.set >", _gptr);
208 nonconst_value_type
get()
const {
209 DASH_LOG_TRACE(
"T GlobRef.get()",
"explicit get");
210 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
211 nonconst_value_type t;
212 dash::internal::get_blocking(_gptr, &t, 1);
216 void get(nonconst_value_type *tptr)
const {
217 DASH_LOG_TRACE(
"GlobRef.get(T*)",
"explicit get into provided ptr");
218 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
219 dash::internal::get_blocking(_gptr, tptr, 1);
222 void get(nonconst_value_type& tref)
const {
223 DASH_LOG_TRACE(
"GlobRef.get(T&)",
"explicit get into provided ref");
224 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
225 dash::internal::get_blocking(_gptr, &tref, 1);
229 put(const_value_type& tref)
const {
230 static_assert(std::is_same<value_type, nonconst_value_type>::value,
231 "Cannot assign to GlobRef<const T>!");
232 DASH_LOG_TRACE(
"GlobRef.put(T&)",
"explicit put of provided ref");
233 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
234 dash::internal::put_blocking(_gptr, &tref, 1);
238 put(const_value_type* tptr)
const {
239 static_assert(std::is_same<value_type, nonconst_value_type>::value,
240 "Cannot modify value referenced by GlobRef<const T>!");
241 DASH_LOG_TRACE(
"GlobRef.put(T*)",
"explicit put of provided ptr");
242 DASH_LOG_TRACE_VAR(
"GlobRef.T()", _gptr);
243 dash::internal::put_blocking(_gptr, tptr, 1);
247 operator+=(
const nonconst_value_type& ref)
const {
248 static_assert(std::is_same<value_type, nonconst_value_type>::value,
249 "Cannot modify value referenced by GlobRef<const T>!");
256 reinterpret_cast<void *>(&add_val),
257 reinterpret_cast<void *>(&old_val),
263 nonconst_value_type val =
operator nonconst_value_type();
271 operator-=(
const nonconst_value_type& ref)
const {
272 static_assert(std::is_same<value_type, nonconst_value_type>::value,
273 "Cannot modify value referenced by GlobRef<const T>!");
274 nonconst_value_type val =
operator nonconst_value_type();
282 static_assert(std::is_same<value_type, nonconst_value_type>::value,
283 "Cannot modify value referenced by GlobRef<const T>!");
284 nonconst_value_type val =
operator nonconst_value_type();
290 operator++(
int)
const {
291 static_assert(std::is_same<value_type, nonconst_value_type>::value,
292 "Cannot modify value referenced by GlobRef<const T>!");
293 nonconst_value_type val =
operator nonconst_value_type();
294 nonconst_value_type res = val++;
301 static_assert(std::is_same<value_type, nonconst_value_type>::value,
302 "Cannot modify value referenced by GlobRef<const T>!");
303 nonconst_value_type val =
operator nonconst_value_type();
309 operator--(
int)
const {
310 static_assert(std::is_same<value_type, nonconst_value_type>::value,
311 "Cannot modify value referenced by GlobRef<const T>!");
312 nonconst_value_type val =
operator nonconst_value_type();
313 nonconst_value_type res = val--;
319 operator*=(const_value_type& ref)
const {
320 static_assert(std::is_same<value_type, nonconst_value_type>::value,
321 "Cannot modify value referenced by GlobRef<const T>!");
322 nonconst_value_type val =
operator nonconst_value_type();
329 operator/=(const_value_type& ref)
const {
330 static_assert(std::is_same<value_type, nonconst_value_type>::value,
331 "Cannot modify value referenced by GlobRef<const T>!");
332 nonconst_value_type val =
operator nonconst_value_type();
339 operator^=(const_value_type& ref)
const {
340 static_assert(std::is_same<value_type, nonconst_value_type>::value,
341 "Cannot modify value referenced by GlobRef<const T>!");
342 nonconst_value_type val =
operator nonconst_value_type();
359 return _gptr.
unitid == luid.id;
366 template<
typename MEMTYPE>
371 dart_gptr_incaddr(&dartptr, offs),
379 template<
class MEMTYPE,
class P=T>
382 const MEMTYPE P::*mem)
const {
384 auto offs = (size_t) & (reinterpret_cast<P*>(0)->*mem);
385 return member<typename internal::add_const_from_type<T, MEMTYPE>::type>(offs);
392 static_assert(std::is_same<value_type, nonconst_value_type>::value,
393 "Cannot modify value referenced by GlobRef<const T>!");
394 auto tmp =
static_cast<T
>(*this);
404 std::ostream & operator<<(
410 "(%06X|%02X|%04X|%04X|%016lX)",
415 gref._gptr.addr_or_offs.offset);
431 template <
class MemSpaceT,
class T>
439 #endif // DASH__GLOBREF_H_ GlobRef(self_t &&other) noexcept
Move Constructor.
Reduce operands to their sum.
GlobRef()=delete
Reference semantics forbid declaration without definition.
int16_t teamid
The team associated with the allocation.
GlobRef< typename internal::add_const_from_type< T, MEMTYPE >::type > member(size_t offs) const
Get a global ref to a member of a certain type at the specified offset.
dart_ret_t dart_team_myid(dart_team_t teamid, dart_team_unit_t *myid)
Return the unit id of the caller in the specified team.
This class is a simple memory pool which holds allocates elements of size ValueType.
auto addressof(dash::GlobRef< T > const &ref)
specialization for unqualified calls to swap
constexpr GlobRef(dart_gptr_t dart_gptr) noexcept
Constructor, creates an GlobRef object referencing an element in global memory.
constexpr GlobRef(const GlobRef< _T > &gref) noexcept
Copy constructor, implicit if at least one of the following conditions is satisfied: 1) value_type an...
dart_unit_t unitid
The unit holding the memory element.
void swap(dash::GlobRef< T > &b) const
specialization which swappes the values of two global references
Data type for storing a unit ID relative to a team.
const self_t & operator=(const self_t &other) const
Copy Assignment.
dart_gptr_t dart_gptr() const
Returns the underlying DART global pointer.
DART Global pointer type.
Type trait for mapping to DART data types.
#define DART_GPTR_EQUAL(gptr1_, gptr2_)
Compare two global pointers.
self_t & operator=(self_t &&other) noexcept
Move Assignment: Redirects to Copy Assignment.
dart_ret_t
Return values of functions in the DART interface.
const self_t & operator=(const value_type &val) const
Value-assignment operator.
std::string typestr(const T &obj)
Returns string containing the type name of the given object.
bool is_local() const
Checks whether the globally referenced element is in the calling unit's local memory.
Pointer in global memory space with random access arithmetics.
GlobRef< typename internal::add_const_from_type< T, MEMTYPE >::type > member(const MEMTYPE P::*mem) const
Get the member via pointer to member.
dart_ret_t dart_fetch_and_op(dart_gptr_t gptr, const void *value, void *result, dart_datatype_t dtype, dart_operation_t op)
Perform an element-wise atomic update on the value of type dtype pointed to by gptr by applying the o...
Global value reference for asynchronous / non-blocking operations.
static Team & All()
The invariant Team instance containing all available units.
Query the underlying dart_operation_t for arbitrary binary operations.
constexpr GlobRef(const GlobAsyncRef< _T > &gref) noexcept
Constructor to convert GlobAsyncRef to GlobRef.
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...