DASH  0.3.0
dash::GlobAsyncRef< T > Class Template Reference

Global value reference for asynchronous / non-blocking operations. More...

#include <GlobAsyncRef.h>

Public Types

using value_type = T
 
using const_value_type = typename std::add_const< T >::type
 
using nonconst_value_type = typename std::remove_const< T >::type
 
using self_t = GlobAsyncRef< T >
 
using const_type = GlobAsyncRef< const_value_type >
 
using nonconst_type = GlobAsyncRef< nonconst_value_type >
 

Public Member Functions

 GlobAsyncRef (dart_gptr_t dart_gptr)
 Conctructor, creates an GlobRefAsync object referencing an element in global memory. More...
 
template<typename _T , int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
 GlobAsyncRef (const GlobAsyncRef< _T > &gref)
 Copy constructor, implicit if at least one of the following conditions is satisfied: 1) value_type and _T are exactly the same types (including const and volatile qualifiers 2) value_type and _T are the same types after removing const and volatile qualifiers and value_type itself is const. More...
 
template<typename _T , long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
 GlobAsyncRef (const GlobAsyncRef< _T > &gref)
 Copy constructor, explicit if the following conditions are satisfied. More...
 
template<typename _T , int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
 GlobAsyncRef (const GlobRef< _T > &gref)
 
template<typename _T , long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
 GlobAsyncRef (const GlobRef< _T > &gref)
 
 GlobAsyncRef (self_t &&other)=default
 
self_toperator= (self_t &&other)=default
 MOVE Assignment. More...
 
self_toperator= (const self_t &other)=delete
 Copy Assignment. More...
 
bool is_local () const noexcept
 Whether the referenced element is located in local memory. More...
 
template<typename MEMTYPE >
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. More...
 
template<class MEMTYPE , class P = T>
GlobAsyncRef< typename internal::add_const_from_type< T, MEMTYPE >::type > member (const MEMTYPE P::*mem) const
 Get the member via pointer to member. More...
 
nonconst_value_type get () const
 Return the value referenced by this GlobAsyncRef. More...
 
void get (nonconst_value_type *tptr) const
 Asynchronously write the value referenced by this GlobAsyncRef into tptr. More...
 
void get (nonconst_value_type &tref) const
 Asynchronously write the value referenced by this GlobAsyncRef into tref. More...
 
void set (const_value_type *tptr) const
 Asynchronously set the value referenced by this GlobAsyncRef to the value pointed to by tptr. More...
 
void set (const_value_type &new_value) const
 Asynchronously set the value referenced by this GlobAsyncRef to the value pointed to by new_value. More...
 
const self_toperator= (const_value_type &new_value) const
 Value assignment operator, calls non-blocking put. More...
 
dart_gptr_t dart_gptr () const
 Returns the underlying DART global pointer. More...
 
template<class ValueT >
bool operator== (const GlobAsyncRef< ValueT > &other)=delete
 Disallow implicit comparison with other global references. More...
 
template<class ValueT >
bool operator!= (const GlobAsyncRef< ValueT > &other)=delete
 
void flush () const
 Flush all pending asynchronous operations on this asynchronous reference. More...
 

Friends

template<typename U >
std::ostream & operator<< (std::ostream &os, const GlobAsyncRef< U > &gar)
 
void swap (self_t &a, self_t &b)
 Swap values with synchronous reads and asynchronous writes. More...
 

Detailed Description

template<typename T>
class dash::GlobAsyncRef< T >

Global value reference for asynchronous / non-blocking operations.

Example:

GlobAsyncRef<int> gar0 = array.async[0];
GlobAsyncRef<int> gar1 = array.async[1];
gar0 = 123;
gar1 = 456;
// Changes are not guaranteed to be visible locally
int val = array.async[0].get(); // might yield the old value
// Values can be read asynchronously, which will not block.
// Instead, the value will be available after `flush()`.
array.async[0].get(&val);
// Changes can be published (committed) directly using a GlobAsyncRef
// object:
gar0.flush();
// New value of array[0] is published to all units, array[1] is not
// committed yet
// Changes on a container can be published in bulk:
array.flush();
// From here, all changes are published

Definition at line 17 of file GlobAtomicRef.h.

Constructor & Destructor Documentation

◆ GlobAsyncRef() [1/3]

template<typename T>
dash::GlobAsyncRef< T >::GlobAsyncRef ( dart_gptr_t  dart_gptr)
inlineexplicit

Conctructor, creates an GlobRefAsync object referencing an element in global memory.

Parameters
dart_gptrPointer to referenced object in global memory

Definition at line 118 of file GlobAsyncRef.h.

121  : _gptr(dart_gptr)
122  { }

◆ GlobAsyncRef() [2/3]

template<typename T>
template<typename _T , int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
dash::GlobAsyncRef< T >::GlobAsyncRef ( const GlobAsyncRef< _T > &  gref)
inline

Copy constructor, implicit if at least one of the following conditions is satisfied: 1) value_type and _T are exactly the same types (including const and volatile qualifiers 2) value_type and _T are the same types after removing const and volatile qualifiers and value_type itself is const.

Definition at line 134 of file GlobAsyncRef.h.

135  : GlobAsyncRef(gref.dart_gptr())
136  { }

◆ GlobAsyncRef() [3/3]

template<typename T>
template<typename _T , long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
dash::GlobAsyncRef< T >::GlobAsyncRef ( const GlobAsyncRef< _T > &  gref)
inlineexplicit

Copy constructor, explicit if the following conditions are satisfied.

1) value_type and _T are the same types after excluding const and volatile qualifiers 2) value_type is const and _T is non-const

Definition at line 147 of file GlobAsyncRef.h.

References dash::GlobAsyncRef< T >::operator=().

148  : GlobAsyncRef(gref.dart_gptr())
149  {
150  }

Member Function Documentation

◆ dart_gptr()

template<typename T>
dart_gptr_t dash::GlobAsyncRef< T >::dart_gptr ( ) const
inline

Returns the underlying DART global pointer.

Definition at line 302 of file GlobAsyncRef.h.

References dash::GlobAsyncRef< T >::operator==().

Referenced by dash::GlobAsyncRef< dash::Atomic< T > >::GlobAsyncRef(), and dash::GlobRef< T >::GlobRef().

302  {
303  return this->_gptr;
304  }

◆ flush()

template<typename T>
void dash::GlobAsyncRef< T >::flush ( ) const
inline

Flush all pending asynchronous operations on this asynchronous reference.

Definition at line 318 of file GlobAsyncRef.h.

References dart_flush(), and DART_OK.

319  {
320  DASH_ASSERT_RETURNS(
321  dart_flush(_gptr),
322  DART_OK
323  );
324  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...

◆ get() [1/3]

template<typename T>
nonconst_value_type dash::GlobAsyncRef< T >::get ( ) const
inline

Return the value referenced by this GlobAsyncRef.

This operation will block until the value has been transfered.

Definition at line 226 of file GlobAsyncRef.h.

Referenced by dash::GlobAsyncRef< dash::Atomic< T > >::GlobAsyncRef().

226  {
227  nonconst_value_type value;
228  DASH_LOG_TRACE_VAR("GlobAsyncRef.T()", _gptr);
229  dash::internal::get_blocking(_gptr, &value, 1);
230  return value;
231  }

◆ get() [2/3]

template<typename T>
void dash::GlobAsyncRef< T >::get ( nonconst_value_type *  tptr) const
inline

Asynchronously write the value referenced by this GlobAsyncRef into tptr.

This operation is guaranteed to be complete after a call to flush, at which point the referenced value can be used.

Definition at line 239 of file GlobAsyncRef.h.

239  {
240  dash::internal::get(_gptr, tptr, 1);
241  }

◆ get() [3/3]

template<typename T>
void dash::GlobAsyncRef< T >::get ( nonconst_value_type &  tref) const
inline

Asynchronously write the value referenced by this GlobAsyncRef into tref.

This operation is guaranteed to be complete after a call to flush, at which point the referenced value can be used.

Definition at line 249 of file GlobAsyncRef.h.

249  {
250  get(&tref);
251  }

◆ is_local()

template<typename T>
bool dash::GlobAsyncRef< T >::is_local ( ) const
inlinenoexcept

Whether the referenced element is located in local memory.

Definition at line 185 of file GlobAsyncRef.h.

186  {
187  return dash::internal::is_local(this->_gptr);
188  }

◆ member() [1/2]

template<typename T>
template<typename MEMTYPE >
GlobAsyncRef<typename internal::add_const_from_type<T, MEMTYPE>::type> dash::GlobAsyncRef< T >::member ( size_t  offs) const
inline

Get a global ref to a member of a certain type at the specified offset.

Definition at line 196 of file GlobAsyncRef.h.

196  {
197  return GlobAsyncRef<typename internal::add_const_from_type<T, MEMTYPE>::type>(*this, offs);
198  }

◆ member() [2/2]

template<typename T>
template<class MEMTYPE , class P = T>
GlobAsyncRef<typename internal::add_const_from_type<T, MEMTYPE>::type> dash::GlobAsyncRef< T >::member ( const MEMTYPE P::*  mem) const
inline

Get the member via pointer to member.

Definition at line 205 of file GlobAsyncRef.h.

206  {
207  auto offs = (size_t) & (reinterpret_cast<P*>(0)->*mem);
208  return member<typename internal::add_const_from_type<T, MEMTYPE>::type>(offs);
209  }

◆ operator=() [1/3]

template<typename T>
self_t& dash::GlobAsyncRef< T >::operator= ( self_t &&  other)
default

◆ operator=() [2/3]

template<typename T>
self_t& dash::GlobAsyncRef< T >::operator= ( const self_t other)
delete

Copy Assignment.

◆ operator=() [3/3]

template<typename T>
const self_t& dash::GlobAsyncRef< T >::operator= ( const_value_type &  new_value) const
inline

Value assignment operator, calls non-blocking put.

This operation is guaranteed to be complete after a call to flush, but the value referenced by new_value can be re-used immediately.

Definition at line 293 of file GlobAsyncRef.h.

294  {
295  set(new_value);
296  return *this;
297  }

◆ operator==()

template<typename T>
template<class ValueT >
bool dash::GlobAsyncRef< T >::operator== ( const GlobAsyncRef< ValueT > &  other)
delete

Disallow implicit comparison with other global references.

Referenced by dash::GlobAsyncRef< T >::dart_gptr(), and dash::GlobAsyncRef< dash::Atomic< T > >::GlobAsyncRef().

◆ set() [1/2]

template<typename T>
void dash::GlobAsyncRef< T >::set ( const_value_type *  tptr) const
inline

Asynchronously set the value referenced by this GlobAsyncRef to the value pointed to by tptr.

This operation is guaranteed to be complete after a call to flush and the pointer tptr should not be reused before completion.

Definition at line 259 of file GlobAsyncRef.h.

259  {
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);
265  }

◆ set() [2/2]

template<typename T>
void dash::GlobAsyncRef< T >::set ( const_value_type &  new_value) const
inline

Asynchronously set the value referenced by this GlobAsyncRef to the value pointed to by new_value.

This operation is guaranteed to be complete after a call to flush, but the value referenced by new_value can be re-used immediately.

Definition at line 273 of file GlobAsyncRef.h.

273  {
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);
278 
279  _value = new_value;
280 
281  dart_handle_t new_handle;
282  dash::internal::put_handle(_gptr, &_value, 1, &new_handle);
283 
284  _handle.reset(new_handle);
285  }
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...

Friends And Related Function Documentation

◆ swap

template<typename T>
void swap ( self_t a,
self_t b 
)
friend

Swap values with synchronous reads and asynchronous writes.

Definition at line 214 of file GlobAsyncRef.h.

214  {
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();
218  a = b->get();
219  b = temp;
220  }

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