1 #ifndef DASH__GLOB_ASYNC_REF_H__ 2 #define DASH__GLOB_ASYNC_REF_H__ 6 #include <dash/GlobPtr.h> 7 #include <dash/Onesided.h> 9 #include <dash/iterator/internal/GlobRefBase.h> 46 friend std::ostream & operator<<(
48 const GlobAsyncRef<U> & gar);
52 friend class GlobAsyncRef;
54 struct ReleaseHandle {
66 using const_value_type =
typename std::add_const<T>::type;
67 using nonconst_value_type =
typename std::remove_const<T>::type;
68 using self_t = GlobAsyncRef<T>;
69 using const_type = GlobAsyncRef<const_value_type>;
70 using nonconst_type = GlobAsyncRef<nonconst_value_type>;
76 mutable nonconst_value_type _value;
79 unique_ptr<std::remove_pointer<dart_handle_t>::type, ReleaseHandle>
88 template<
typename ParentT>
91 const GlobAsyncRef<ParentT> & parent,
97 dart_gptr_incaddr(&_gptr, offset),
105 template<
class ElementT,
class MemSpaceT>
106 explicit GlobAsyncRef(
108 GlobPtr<ElementT, MemSpaceT> & gptr)
132 template<
typename _T,
133 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
146 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
154 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
156 : GlobAsyncRef(gref.dart_gptr())
162 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
164 : GlobAsyncRef(gref.dart_gptr())
168 ~GlobAsyncRef() =
default;
170 GlobAsyncRef(
self_t&& other) =
default;
187 return dash::internal::is_local(this->_gptr);
194 template<
typename MEMTYPE>
203 template<
class MEMTYPE,
class P=T>
206 const MEMTYPE P::*mem)
const {
207 auto offs = (size_t) & (reinterpret_cast<P*>(0)->*mem);
208 return member<typename internal::add_const_from_type<T, MEMTYPE>::type>(offs);
215 static_assert(std::is_same<value_type, nonconst_value_type>::value,
216 "Cannot swap GlobAsyncRef<const T>!");
217 nonconst_value_type temp = a->
get();
226 nonconst_value_type
get()
const {
227 nonconst_value_type value;
228 DASH_LOG_TRACE_VAR(
"GlobAsyncRef.T()", _gptr);
229 dash::internal::get_blocking(_gptr, &value, 1);
239 void get(nonconst_value_type *tptr)
const {
240 dash::internal::get(_gptr, tptr, 1);
249 void get(nonconst_value_type& tref)
const {
259 void set(const_value_type* tptr)
const {
260 static_assert(std::is_same<value_type, nonconst_value_type>::value,
261 "Cannot modify value through GlobAsyncRef<const T>!");
262 DASH_LOG_TRACE_VAR(
"GlobAsyncRef.set()", *tptr);
263 DASH_LOG_TRACE_VAR(
"GlobAsyncRef.set()", _gptr);
264 dash::internal::put(_gptr, tptr, 1);
273 void set(const_value_type& new_value)
const {
274 static_assert(std::is_same<value_type, nonconst_value_type>::value,
275 "Cannot modify value through GlobAsyncRef<const T>!");
276 DASH_LOG_TRACE_VAR(
"GlobAsyncRef.set()", new_value);
277 DASH_LOG_TRACE_VAR(
"GlobAsyncRef.set()", _gptr);
282 dash::internal::put_handle(_gptr, &_value, 1, &new_handle);
284 _handle.reset(new_handle);
309 template <
class ValueT>
312 template <
class ValueT>
329 std::ostream & operator<<(
332 os <<
"dash::GlobAsyncRef(" << gar._gptr <<
")";
338 #endif // DASH__GLOB_ASYNC_REF_H__ This class is a simple memory pool which holds allocates elements of size ValueType.
GlobAsyncRef(const GlobAsyncRef< _T > &gref)
Copy constructor, implicit if at least one of the following conditions is satisfied: 1) value_type an...
friend void swap(self_t &a, self_t &b)
Swap values with synchronous reads and asynchronous writes.
GlobAsyncRef< 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.
const self_t & operator=(const_value_type &new_value) const
Value assignment operator, calls non-blocking put.
void flush() const
Flush all pending asynchronous operations on this asynchronous reference.
GlobAsyncRef(dart_gptr_t dart_gptr)
Conctructor, creates an GlobRefAsync object referencing an element in global memory.
bool operator==(const GlobAsyncRef< ValueT > &other)=delete
Disallow implicit comparison with other global references.
dart_gptr_t dart_gptr() const
Returns the underlying DART global pointer.
DART Global pointer type.
struct dart_handle_struct * dart_handle_t
Handle returned by dart_get_handle and the like used to wait for a specific operation to complete usi...
#define DART_HANDLE_NULL
Handle returned by dart_get_handle and the like used to wait for a specific operation to complete usi...
dart_ret_t dart_wait_local(dart_handle_t *handle)
Wait for the local completion of an operation.
Global value reference for asynchronous / non-blocking operations.
self_t & operator=(self_t &&other)=default
MOVE Assignment.
nonconst_value_type get() const
Return the value referenced by this GlobAsyncRef.
bool is_local() const noexcept
Whether the referenced element is located in local memory.
GlobAsyncRef< 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_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...