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:417
#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
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
Full tape interface that supports all features of CoDiPack.
Definition fullTapeInterface.hpp:84
Abstracts the internal set of adjoint variables provided as part of the tape.
Definition internalAdjointsInterface.hpp:80
Provides global adjoint variables owned by a tape type. Thread-safe for use in parallel taping.
Definition threadSafeGlobalAdjoints.hpp:53
T_Gradient Gradient
See ThreadSafeGlobalAdjoints.
Definition threadSafeGlobalAdjoints.hpp:58
T_Identifier Identifier
Definition threadSafeGlobalAdjoints.hpp:59
void zeroAll(Identifier const &maxIdentifier)
Set all adjoint variables up to and including maxIdentifier to Gradient().
Definition threadSafeGlobalAdjoints.hpp:112
Gradient & operator[](Identifier const &identifier)
Reference access to the adjoint variable identified by identifier.
Definition threadSafeGlobalAdjoints.hpp:83
T_ParallelToolbox ParallelToolbox
See ThreadSafeGlobalAdjoints.
Definition threadSafeGlobalAdjoints.hpp:61
void beginUse()
Declare that the adjoints are in use, e.g., during a tape evaluation, and cannot be resized right now...
Definition threadSafeGlobalAdjoints.hpp:126
void endUse()
Declare that the adjoints are no longer occupied.
Definition threadSafeGlobalAdjoints.hpp:132
void swap(ThreadSafeGlobalAdjoints &)
Swap two sets of adjoint variables. Internally, declares usage of the adjoints.
Definition threadSafeGlobalAdjoints.hpp:120
Gradient const & operator[](Identifier const &identifier) const
Constant reference access to the adjoint variable identified by identifier.
Definition threadSafeGlobalAdjoints.hpp:89
typename ParallelToolbox::LockForWrite LockForRealloc
See ParallelToolbox.
Definition threadSafeGlobalAdjoints.hpp:65
Gradient * data()
Return an array-like object for data access, for example a pointer to an underlying array or a refere...
Definition threadSafeGlobalAdjoints.hpp:94
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
size_t size() const
Returns the number of adjoint variables. Internally, declares usage of the adjoints.
Definition threadSafeGlobalAdjoints.hpp:100
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