1 #ifndef DASH__ATOMIC_ASYNC_GLOBREF_H_ 2 #define DASH__ATOMIC_ASYNC_GLOBREF_H_ 4 #include <dash/Types.h> 5 #include <dash/GlobPtr.h> 6 #include <dash/algorithm/Operation.h> 7 #include <dash/GlobAsyncRef.h> 8 #include <dash/GlobRef.h> 38 friend std::ostream & operator<<(
44 using const_value_type =
typename std::add_const<T>::type;
45 using nonconst_value_type =
typename std::remove_const<T>::type;
61 template<
typename GlobMemT>
72 template<
typename GlobMemT>
78 static_assert(std::is_same<value_type, const_value_type>::value,
79 "Cannot create GlobAsyncRef<Atomic<T>> from GlobPtr<Atomic<const T>>!");
98 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>(dart_gptr_t)", dart_gptr);
109 template<
typename _T,
110 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
121 template<
typename _T,
122 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
128 template<
typename _T,
129 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
134 template<
typename _T,
135 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
141 ~GlobAsyncRef() =
default;
147 GlobAsyncRef(
self_t && other) =
default;
161 return this->
get() == other.
get();
164 inline bool operator!=(
const self_t & other)
const noexcept
166 return !(*
this == other);
169 inline bool operator==(
const T & value)
const =
delete;
170 inline bool operator!=(
const T & value)
const =
delete;
181 return dash::internal::is_local(_gptr);
203 void set(
const T & value)
const 205 static_assert(std::is_same<value_type, nonconst_value_type>::value,
206 "Cannot modify value referenced by GlobAsyncRef<Atomic<const T>>!");
207 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.set()", value);
208 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.set", _gptr);
215 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
216 DASH_LOG_DEBUG(
"GlobAsyncRef<Atomic>.set >");
224 void set(
const T * ptr)
const 226 static_assert(std::is_same<value_type, nonconst_value_type>::value,
227 "Cannot modify value referenced by GlobAsyncRef<Atomic<const T>>!");
228 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.set()", *ptr);
229 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.set", _gptr);
236 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
237 DASH_LOG_DEBUG(
"GlobAsyncRef<Atomic>.set >");
245 inline void store(
const T & value)
const {
254 inline void store(
const T * ptr)
const {
266 DASH_LOG_DEBUG(
"GlobAsyncRef<Atomic>.get()");
267 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.get", _gptr);
268 nonconst_value_type nothing;
269 nonconst_value_type result;
277 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
278 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.get >", result);
289 void get(T * result)
const 291 DASH_LOG_DEBUG(
"GlobAsyncRef<Atomic>.get()");
292 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.get", _gptr);
293 nonconst_value_type nothing;
300 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
316 template<
typename BinaryOp>
320 const T & value)
const 322 static_assert(std::is_same<value_type, nonconst_value_type>::value,
323 "Cannot modify value referenced by GlobAsyncRef<Atomic<const T>>!");
324 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.op()", value);
325 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.op", _gptr);
326 DASH_LOG_TRACE(
"GlobAsyncRef<Atomic>.op",
"dart_accumulate");
332 binary_op.dart_operation());
333 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate_blocking_local failed");
342 template<
typename BinaryOp>
349 static_assert(std::is_same<value_type, nonconst_value_type>::value,
350 "Cannot modify value referenced by GlobAsyncRef<Atomic<const T>>!");
351 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.fetch_op()", value);
352 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.fetch_op", _gptr);
353 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.fetch_op",
typeid(value).name());
359 binary_op.dart_operation());
360 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_fetch_op failed");
387 static_assert(std::is_same<value_type, nonconst_value_type>::value,
388 "Cannot modify value referenced by GlobAsyncRef<Atomic<const T>>!");
389 DASH_LOG_DEBUG_VAR(
"GlobAsyncRef<Atomic>.compare_exchange()", desired);
390 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.compare_exchange", _gptr);
391 DASH_LOG_TRACE_VAR(
"GlobAsyncRef<Atomic>.compare_exchange", expected);
393 "GlobAsyncRef<Atomic>.compare_exchange",
typeid(desired).name());
400 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_compare_and_swap failed");
407 void add(
const T & value)
const 433 void sub(
const T & value)
const 496 #endif // DASH__ATOMIC_ASYNC_GLOBREF_H_
Reduce operands to their sum.
void store(const T &value) const
Set the value of the shared atomic variable.
void fetch_sub(const T &value, T *result) const
Atomic fetch-and-sub operation on the referenced shared value.
dart_ret_t dart_accumulate_blocking_local(dart_gptr_t gptr, const void *values, size_t nelem, dart_datatype_t dtype, dart_operation_t op)
Perform an element-wise atomic update on the values pointed to by gptr by applying the operation op w...
GlobAsyncRef(dart_gptr_t dart_gptr)
Constructor, creates an GlobRef object referencing an element in global memory.
This class is a simple memory pool which holds allocates elements of size ValueType.
GlobAsyncRef(const GlobAsyncRef< dash::Atomic< _T >> &gref)
Copy constructor: Implicit if at least one of the following conditions is satisfied: 1) value_type an...
void compare_exchange(const T &expected, const T &desired, T *result) const
Atomically compares the value with the value of expected and if thosei are bitwise-equal, replaces the former with desired.
void add(const T &value) const
DASH specific variant which is faster than fetch_add but does not return value.
dart_ret_t dart_flush_local(dart_gptr_t gptr)
Guarantee local completion of all outstanding operations involving a segment on a certain unit...
Type wrapper to mark any trivial type atomic.
dart_ret_t dart_accumulate(dart_gptr_t gptr, const void *values, size_t nelem, dart_datatype_t dtype, dart_operation_t op)
Perform an element-wise atomic update on the values pointed to by gptr by applying the operation op w...
Type trait for mapping to punned DART data type for reduce operations.
void sub(const T &value) const
DASH specific variant which is faster than fetch_sub but does not return value.
void fetch_op(BinaryOp binary_op, const T &value, T *result) const
Atomic fetch-and-op operation on the referenced shared value.
Reduce operands to their product.
dart_ret_t dart_compare_and_swap(dart_gptr_t gptr, const void *value, const void *compare, void *result, dart_datatype_t dtype)
Atomically replace the single value pointed to by gptr with the the value in value if it is equal to ...
void exchange(const T &value, T *result) const
Atomically exchanges value.
void multiply(const T &value) const
DASH specific variant which is faster than fetch_mul but does not return value.
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.
void fetch_add(const T &value, T *result) const
Atomic fetch-and-add operation on the referenced shared value.
constexpr dart_gptr_t dart_gptr() const DASH_NOEXCEPT
The pointer's underlying global address.
dart_ret_t
Return values of functions in the DART interface.
Pointer in global memory space with random access arithmetics.
void store(const T *ptr) const
Set the value of the shared atomic variable.
void flush() const
Flush all pending asynchronous operations on this asynchronous reference.
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...
void op(BinaryOp binary_op, const T &value) const
Atomically executes specified operation on the referenced shared value.
void fetch_multiply(const T &value, T *result) const
Atomic fetch-and-multiply operation on the referenced shared value.
Global value reference for asynchronous / non-blocking operations.
T load() const
Load the value of the shared atomic variable.
self_t & operator=(self_t &&other)=default
MOVE Assignment.
nonconst_value_type get() const
Return the value referenced by this GlobAsyncRef.
T operator=(const T &value) const
atomically assigns value
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...
bool is_local() const
Checks whether the globally referenced element is in the calling unit's local memory.