1 #ifndef DASH__ATOMIC_GLOBREF_H_ 2 #define DASH__ATOMIC_GLOBREF_H_ 4 #include <dash/GlobPtr.h> 6 #include <dash/algorithm/Operation.h> 7 #include <dash/iterator/internal/GlobRefBase.h> 35 friend std::ostream& operator<<(std::ostream& os, const GlobRef<U>& gref);
39 using const_value_type =
typename std::add_const<T>::type;
40 using nonconst_value_type =
typename std::remove_const<T>::type;
66 DASH_LOG_TRACE_VAR(
"GlobRef(dart_gptr_t)", dart_gptr);
73 template <
typename PatternT>
80 std::is_same<value_type, const_value_type>::value,
81 "Cannot create GlobRef<Atomic<T>> from GlobPtr<Atomic<const T>>!");
84 template <
typename PatternT>
102 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
116 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
132 int = internal::enable_implicit_copy_ctor<value_type, _T>::value>
146 long = internal::enable_explicit_copy_ctor<value_type, _T>::value>
162 store(static_cast<atomic_t>(other));
190 return dash::internal::is_local(_gptr);
212 void set(
const T& value)
const 216 "Basic type or type smaller than 64bit required for " 219 std::is_same<value_type, nonconst_value_type>::value,
220 "Cannot modify value referenced by GlobRef<Atomic<const T>>!");
221 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.store()", value);
222 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.store", _gptr);
230 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
231 DASH_LOG_DEBUG(
"GlobRef<Atomic>.store >");
237 inline void store(
const T& value)
const 247 "Basic type or type smaller than 64bit required for " 249 DASH_LOG_DEBUG(
"GlobRef<Atomic>.load()");
250 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.load", _gptr);
251 nonconst_value_type nothing;
252 nonconst_value_type result;
260 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
261 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.get >", result);
276 template <
typename BinaryOp>
281 const T& value)
const 285 "Basic type or type smaller than 64bit required for " 286 "atomic operation!");
289 binary_op.op_kind() != dash::internal::OpKind::ARITHMETIC,
290 "Atomic arithmetic operations only valid on basic types");
292 std::is_same<value_type, nonconst_value_type>::value,
293 "Cannot modify value referenced by GlobRef<Atomic<const T>>!");
294 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.op()", value);
295 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.op", _gptr);
296 nonconst_value_type acc = value;
297 DASH_LOG_TRACE(
"GlobRef<Atomic>.op",
"dart_accumulate");
303 binary_op.dart_operation());
305 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_accumulate failed");
306 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.op >", acc);
315 template <
typename BinaryOp>
319 const T& value)
const 323 "Basic type or type smaller than 64bit required for " 327 binary_op.op_kind() != dash::internal::OpKind::ARITHMETIC,
328 "Atomic arithmetic operations only valid on basic types!");
330 std::is_same<value_type, nonconst_value_type>::value,
331 "Cannot modify value referenced by GlobRef<Atomic<const T>>!");
332 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.fetch_op()", value);
333 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.fetch_op", _gptr);
334 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.fetch_op",
typeid(value).name());
335 nonconst_value_type res;
341 binary_op.dart_operation());
343 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_fetch_op failed");
344 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.fetch_op >", res);
368 "Integral type or type smaller than 64bit required for " 369 "compare_exchange!");
371 !std::is_floating_point<T>::value,
372 "compare_exchange not available for floating point!");
374 std::is_same<value_type, nonconst_value_type>::value,
375 "Cannot modify value referenced by GlobRef<const T>!");
376 DASH_LOG_DEBUG_VAR(
"GlobRef<Atomic>.compare_exchange()", desired);
377 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.compare_exchange", _gptr);
378 DASH_LOG_TRACE_VAR(
"GlobRef<Atomic>.compare_exchange", expected);
380 "GlobRef<Atomic>.compare_exchange",
typeid(desired).name());
381 nonconst_value_type result;
389 DASH_ASSERT_EQ(
DART_OK, ret,
"dart_compare_and_swap failed");
391 "GlobRef<Atomic>.compare_exchange >", (expected == result));
392 return (expected == result);
399 void add(
const T& value)
const 402 std::is_same<value_type, nonconst_value_type>::value,
403 "Cannot modify value referenced by GlobRef<const T>!");
415 const T& value)
const 424 void sub(
const T& value)
const 437 const T& value)
const 459 const T& value)
const 477 return fetch_add(1) + 1;
504 return fetch_sub(1) - 1;
531 return fetch_add(value) + value;
547 return fetch_sub(value) - value;
553 #endif // DASH__ATOMIC_GLOBREF_H_ void store(const T &value) const
Set the value of the shared atomic variable.
Reduce operands to their sum.
GlobRef()=delete
Reference semantics forbid declaration without definition.
This class is a simple memory pool which holds allocates elements of size ValueType.
void multiply(const T &value) const
DASH specific variant which is faster than fetch_multiply but does not return value.
self_t & operator=(self_t &&other)
Move Assignment: Redirects to Copy Assignment.
GlobRef(const GlobPtr< nonconst_atomic_t, PatternT > &gptr)
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...
T load() const
Get the value of the shared atomic variable.
Type trait for mapping to punned DART data type for reduce operations.
bool is_local() const
Checks whether the globally referenced element is in the calling unit's local memory.
T operator++() const
prefix atomically increment value by one
bool compare_exchange(const T &expected, const T &desired) const
Atomically compares the value with the value of expected and if thosei are bitwise-equal, replaces the former with desired.
Reduce operands to their product.
const self_t & operator=(const self_t &other) const
Copy Assignment.
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 ...
GlobRef(const GlobAsyncRef< dash::Atomic< _T >> &gref)
Copy constructor: Implicit if at least one of the following conditions is satisfied: 1) value_type an...
T operator--(int) const
postfix atomically decrement value by one
T fetch_multiply(const T &value) const
Atomic fetch-and-multiply operation on the referenced shared value.
GlobRef(const GlobRef< dash::Atomic< _T >> &gref)
Copy constructor: Implicit if at least one of the following conditions is satisfied: 1) value_type an...
self_t & operator=(const self_t &other) const
Copy Assignment: Copies atomically the value from other.
T operator-=(const T &value) const
atomically decrement value by ref
T fetch_add(const T &value) const
Atomic fetch-and-add operation on the referenced shared value.
GlobRef(dart_gptr_t dart_gptr)
Constructor: Create an atomic reference to a element in global memory.
DART Global pointer type.
T exchange(const T &value) const
Atomically exchanges value.
Type trait for mapping to DART data types.
void sub(const T &value) const
DASH specific variant which is faster than fetch_sub but does not return value.
T operator++(int) const
postfix atomically increment value by one
T operator+=(const T &value) const
atomically increment value by ref
dart_ret_t
Return values of functions in the DART interface.
T fetch_sub(const T &value) const
Atomic fetch-and-sub operation on the referenced shared value.
T operator=(const T &value) const
atomically assigns value
void op(BinaryOp binary_op, const T &value) const
Atomically executes specified operation on the referenced shared value.
Pointer in global memory space with random access arithmetics.
void add(const T &value) const
DASH specific variant which is faster than fetch_add but does not return value.
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...
T operator--() const
prefix atomically decrement value by one
GlobRef(const GlobPtr< const_atomic_t, PatternT > &gptr)
Constructor, creates an GlobRef object referencing an element in global memory.
Global value reference for asynchronous / non-blocking operations.
T fetch_op(BinaryOp binary_op, const T &value) const
Atomic fetch-and-op operation on the referenced shared value.
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...