39#include "../../../expressions/activeType.hpp"
40#include "../../../traits/atomicTraits.hpp"
41#include "../../../traits/realTraits.hpp"
42#include "../../../traits/tapeTraits.hpp"
43#include "../atomicInterface.hpp"
60 template<
typename T_Type,
typename T_Sfinae =
void>
68#ifndef DOXYGEN_DISABLE
71 template<
typename T_Type>
72 struct OpenMPAtomicImpl<T_Type, typename std::enable_if<std::is_arithmetic<T_Type>::value>::type>
74 T_Type, OpenMPAtomicImpl<T_Type, typename std::enable_if<std::is_arithmetic<T_Type>::value>::type>> {
85 CODI_OMP_ATOMIC(write)
86 this->value = newValue;
122 CODI_OMP_ATOMIC(capture) {
123 this->value += other;
124 result = this->value;
131 CODI_OMP_ATOMIC(capture)
132 result = ++this->value;
138 CODI_OMP_ATOMIC(capture)
139 result = this->value++;
145 CODI_OMP_ATOMIC(capture)
146 result = --this->value;
152 CODI_OMP_ATOMIC(capture)
153 result = this->value--;
163 template<
typename T_Type>
165 :
public AtomicInterface<T_Type,
166 OpenMPAtomicImpl<T_Type, TapeTraits::EnableIfForwardTape<typename T_Type::Tape>>>,
169 using Type =
CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
171 AtomicInterface<T_Type, OpenMPAtomicImpl<T_Type, TapeTraits::EnableIfForwardTape<typename T_Type::Tape>>>;
172 using Tape =
typename Type::Tape;
173 using Real =
typename Type::Real;
174 using Gradient =
typename Type::Gradient;
178 OpenMPAtomicImpl<Real>* atomicValue =
reinterpret_cast<OpenMPAtomicImpl<Real>*
>(&this->value());
179 OpenMPAtomicImpl<Gradient>* atomicGradient =
reinterpret_cast<OpenMPAtomicImpl<Gradient>*
>(&this->gradient());
181 *atomicValue = newValue.value();
182 *atomicGradient = newValue.gradient();
188 OpenMPAtomicImpl<Real>
const* atomicValue =
reinterpret_cast<OpenMPAtomicImpl<Real> const*
>(&this->value());
189 OpenMPAtomicImpl<Gradient>
const* atomicGradient =
190 reinterpret_cast<OpenMPAtomicImpl<Gradient> const*
>(&this->gradient());
192 result.value() = *atomicValue;
193 result.gradient() = *atomicGradient;
202 atomicSetValue(other.atomicGetValue());
206 atomicSetValue(other);
210 return operator=(other.atomicGetValue());
214 atomicSetValue(other);
223 OpenMPAtomicImpl<Real>* atomicValue =
reinterpret_cast<OpenMPAtomicImpl<Real>*
>(&this->value());
224 OpenMPAtomicImpl<Gradient>* atomicGradient =
reinterpret_cast<OpenMPAtomicImpl<Gradient>*
>(&this->gradient());
226 *atomicValue += other.value();
227 *atomicGradient += other.gradient();
232 return atomicGetValue();
240 template<
typename Type>
244 template<
typename T_Type>
247#ifndef DOXYGEN_DISABLE
249 template<
typename T_Type>
251 OpenMPAtomicImpl<T_Type, typename std::enable_if<std::is_arithmetic<T_Type>::value>::type>> {
259 return typename Type::Type() == v;
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
void setValue(Type &v, typename DataExtraction< Type >::Real const &value)
Set the primal values of a type of aggregated active types.
Definition realTraits.hpp:222
DataExtraction< Type >::Real getValue(Type const &v)
Extract the primal values from a type of aggregated active types.
Definition realTraits.hpp:210
typename std::enable_if< IsForwardTape< Tape >::value >::type EnableIfForwardTape
Enable if wrapper for IsForwardTape.
Definition tapeTraits.hpp:88
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Provides a data type on which operations are performed atomically.
Definition atomicInterface.hpp:56
Type operator--()
Pre-decrement operator.
Type operator+=(Impl const &other)
Incremental update with implementing type as rhs.
Impl & operator=(Impl const &other)
Assignment operator with implementing type as rhs.
Type operator++()
Pre-increment operator.
Indicate whether a type is atomic.
Definition atomicTraits.hpp:51
Atomic implementation for OpenMP.
Definition openMPAtomic.hpp:61
T_Type Type
See OpenMPAtomicImpl.
Definition openMPAtomic.hpp:63
OpenMPAtomicImpl()=delete
Constructor is deleted, will throw errors for unspecialized instantiations.
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:100
T_Type Type
See IsTotalZero.
Definition realTraits.hpp:103
static bool isTotalZero(Type const &v)
Checks if the values are completely zero.
Definition realTraits.hpp:106