37#include "../../tools/parallel/parallelToolbox.hpp"
38#include "../../traits/adjointVectorTraits.hpp"
39#include "internalAdjointsInterface.hpp"
52 template<
typename T_Gradient,
typename T_Identifier,
typename T_Tape,
typename T_ParallelToolbox>
69 static std::vector<Gradient> adjoints;
84 return adjoints[(size_t)identifier];
90 return adjoints[(size_t)identifier];
96 return adjoints.data();
102 return adjoints.size();
108 adjoints.resize((
size_t)newSize);
127 adjointsMutex.lockRead();
133 adjointsMutex.unlockRead();
137 template<
typename Gradient,
typename Identifier,
typename Tape,
typename ParallelToolbox>
138 std::vector<
CODI_DD(Gradient,
double)>
139 ThreadSafeGlobalAdjoints<Gradient, Identifier, Tape, ParallelToolbox>::adjoints(1);
141 template<
typename Gradient,
typename Identifier,
typename Tape,
typename ParallelToolbox>
142 typename CODI_DD(ParallelToolbox, CODI_DEFAULT_PARALLEL_TOOLBOX)::ReadWriteMutex
143 ThreadSafeGlobalAdjoints<Gradient, Identifier, Tape, ParallelToolbox>::adjointsMutex;
145#ifndef DOXYGEN_DISABLE
148 namespace AdjointVectorTraits {
149 template<
typename T_Gradient,
typename T_Identifier,
typename T_Tape,
typename T_ParallelToolbox>
150 struct GradientImplementation<ThreadSafeGlobalAdjoints<T_Gradient, T_Identifier, T_Tape, T_ParallelToolbox>> {
152 using Gradient = T_Gradient;
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:426
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:116
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
Full tape interface that supports all features of CoDiPack.
Definition fullTapeInterface.hpp:84
InternalAdjointsInterface(size_t initialSize)
Definition internalAdjointsInterface.hpp:90
T_Gradient Gradient
See ThreadSafeGlobalAdjoints.
Definition threadSafeGlobalAdjoints.hpp:58
T_Identifier Identifier
Definition threadSafeGlobalAdjoints.hpp:59
T_ParallelToolbox ParallelToolbox
See ThreadSafeGlobalAdjoints.
Definition threadSafeGlobalAdjoints.hpp:61
inlineGradient & operator[](Identifier const &identifier)
Reference access to the adjoint variable identified by identifier.
Definition threadSafeGlobalAdjoints.hpp:83
inlinevoid zeroAll(Identifier const &maxIdentifier)
Set all adjoint variables up to and including maxIdentifier to Gradient().
Definition threadSafeGlobalAdjoints.hpp:112
inlineGradient * data()
Return an array-like object for data access, for example a pointer to an underlying array or a refere...
Definition threadSafeGlobalAdjoints.hpp:94
inlinevoid swap(ThreadSafeGlobalAdjoints &)
Swap two sets of adjoint variables. Internally, declares usage of the adjoints.
Definition threadSafeGlobalAdjoints.hpp:120
inlinevoid beginUse()
Declare that the adjoints are in use, e.g., during a tape evaluation, and cannot be resized right now...
Definition threadSafeGlobalAdjoints.hpp:126
typename ParallelToolbox::LockForWrite LockForRealloc
See ParallelToolbox.
Definition threadSafeGlobalAdjoints.hpp:65
typename ParallelToolbox::ReadWriteMutex ReadWriteMutex
See ParallelToolbox.
Definition threadSafeGlobalAdjoints.hpp:63
void resize(Identifier const &newSize)
Ensure that identifiers up to newSize can be passed to operator[] without error.
Definition threadSafeGlobalAdjoints.hpp:106
inlinevoid endUse()
Declare that the adjoints are no longer occupied.
Definition threadSafeGlobalAdjoints.hpp:132
ThreadSafeGlobalAdjoints(size_t initialSize)
Constructor.
Definition threadSafeGlobalAdjoints.hpp:78
typename ParallelToolbox::LockForRead LockForUse
See ParallelToolbox.
Definition threadSafeGlobalAdjoints.hpp:64
T_Tape Tape
See ThreadSafeGlobalAdjoints.
Definition threadSafeGlobalAdjoints.hpp:57
inlinesize_t size() const
Returns the number of adjoint variables. Internally, declares usage of the adjoints.
Definition threadSafeGlobalAdjoints.hpp:100
inlineGradient const & operator[](Identifier const &identifier) const
Constant reference access to the adjoint variable identified by identifier.
Definition threadSafeGlobalAdjoints.hpp:89