40#include "../../misc/eventSystem.hpp"
42#include "../data/dataInterface.hpp"
43#include "indexManagerInterface.hpp"
65 template<
typename T_Index>
93 Index reservedIndices;
107 TapeValues::LocalReductionOperation
constexpr operation =
108 NeedsStaticStorage ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
115 template<
typename Tape>
126 template<
typename Tape>
129 CODI_EXCEPTION(
"Overflow in linear index handler. Use a larger index type or a reuse index manager.");
143 template<
typename Tape>
145 return assignIndex<Tape>(index);
149 template<
typename Tape>
179 template<
typename TargetPosition>
197 return count - startPos;
203 return reservedIndices;
230 count = reservedIndices;
235 count = reservedIndices;
252 std::swap(reservedIndices, other.reservedIndices);
253 std::swap(count, other.count);
258 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
261 function(std::forward<Args>(args)..., start, end);
266 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
269 function(std::forward<Args>(args)..., start, end);
273 template<
typename FunctionObject,
typename... Args>
280 template<
typename FunctionObject,
typename... Args>
287 template<
typename FunctionObject,
typename... Args>
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:53
bool constexpr IndexEvents
Enable index management events. Disabled by default.
Definition config.h:327
bool constexpr OverflowCheck
Check in the index manager if an overflow occurred.
Definition config.h:248
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static void notifyIndexAssignListeners(Index const &index)
Invoke callbacks for IndexAssign events.
Definition eventSystem.hpp:778
static void notifyIndexFreeListeners(Index const &index)
Invoke callbacks for IndexFree events.
Definition eventSystem.hpp:806
static void notifyIndexCopyListeners(Index const &index)
Invoke callbacks for IndexCopy events.
Definition eventSystem.hpp:833
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
static Index constexpr InvalidIndex
Default invalid index for all index mangers (max value for unsigned types).
Definition indexManagerInterface.hpp:87
static Index constexpr InactiveIndex
Default inactive index for all index managers.
Definition indexManagerInterface.hpp:86
Identifiers are created in a linear fashion. Each assign creates a new index which is counted up.
Definition linearIndexManager.hpp:66
LinearIndexManager(Index reservedIndices)
Constructor.
Definition linearIndexManager.hpp:98
InternalPosHandle reserveItems(size_t const &items)
Reserve this many items on the data stream. See pushData for details.
Definition linearIndexManager.hpp:210
size_t getDataSize() const
Definition linearIndexManager.hpp:185
size_t InternalPosHandle
Internal positions coincide with positions.
Definition linearIndexManager.hpp:87
void forEachChunk(FunctionObject &function, bool recursive, Args &&... args)
Calls the function object for each continuous segment of data.
Definition linearIndexManager.hpp:274
void swap(LinearIndexManager< Index > &other)
Definition linearIndexManager.hpp:251
void NestedData
Terminator, no further nested data.
Definition linearIndexManager.hpp:86
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition linearIndexManager.hpp:106
Position getZeroPosition() const
Definition linearIndexManager.hpp:202
void forEachForward(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Calls the function object for each item in the data stream. This call is not recursive.
Definition linearIndexManager.hpp:281
void resetHard()
Definition linearIndexManager.hpp:234
static bool constexpr CopyNeedsStatement
Copy optimization is implemented.
Definition linearIndexManager.hpp:76
void forEachReverse(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Calls the function object for each item in the data stream. This call is not recursive.
Definition linearIndexManager.hpp:288
T_Index Index
See LinearIndexManager.
Definition linearIndexManager.hpp:69
Index Position
Positions coincide with indices.
Definition linearIndexManager.hpp:85
bool assignIndex(Index &index)
Call on assignment of a primal value, e.g. on w for w = a + b.
Definition linearIndexManager.hpp:127
void pushData()
Add data to the storage allocated by the implementation. The method can only be called after a call t...
Definition linearIndexManager.hpp:207
void freeIndex(Index &index) const
Call on destruction of a primal value. Usually called from the destructor.
Definition linearIndexManager.hpp:116
void evaluateForward(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Evaluates the function object with segments of continuous and valid data for all nested DataInterface...
Definition linearIndexManager.hpp:259
void erase(Position const &start, Position const &end, bool recursive=true)
Definition linearIndexManager.hpp:241
void copyIndex(Index &lhs, Index const &rhs)
Call on copy of a primal value, e.g. w = a.
Definition linearIndexManager.hpp:150
void resize(size_t const &totalSize)
Definition linearIndexManager.hpp:217
static bool constexpr NeedsStaticStorage
Linear indices are not meaningful across tape instances.
Definition linearIndexManager.hpp:78
void updateLargestCreatedIndex(Index const &index)
Update the largest generated index.
Definition linearIndexManager.hpp:169
size_t getPushedDataCount(InternalPosHandle const &startPos)
Definition linearIndexManager.hpp:196
void evaluateReverse(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Evaluates the function object with segments of continuous and valid data for all nested DataInterface...
Definition linearIndexManager.hpp:267
void reset()
Definition linearIndexManager.hpp:229
static bool constexpr IsLinear
Tightly coupled to statements.
Definition linearIndexManager.hpp:77
Index getLargestCreatedIndex() const
Returns the largest created index.
Definition linearIndexManager.hpp:164
TargetPosition extractPosition(Position const &pos) const
Extract the position of a nested DataInterface from the global position object provide by this interf...
Definition linearIndexManager.hpp:180
void setNested(NestedData *v)
Definition linearIndexManager.hpp:246
Position getPosition() const
Definition linearIndexManager.hpp:191
bool assignUnusedIndex(Index &index)
Call on registering input values.
Definition linearIndexManager.hpp:144
void resetTo(Position const &pos)
Definition linearIndexManager.hpp:222
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addLongEntry(std::string const &name, long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add long entry.
Definition tapeValues.hpp:152