41#include "reuseIndexManager.hpp"
56 template<
typename T_Index>
76 std::vector<Index> indexUse;
94 double memoryindexUseVector = (double)indexUse.size() * (double)(
sizeof(
Index));
96 TapeValues::LocalReductionOperation
constexpr operation =
97 NeedsStaticStorage ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
99 values.
addDoubleEntry(
"Memory: index use vector", memoryindexUseVector, operation,
true,
true);
103 template<
typename Tape>
105 bool generatedNewIndex =
false;
108 indexUse[index] -= 1;
118 generatedNewIndex = Base::template assignIndex<Tape>(index);
119 if (generatedNewIndex) {
126 return generatedNewIndex;
130 template<
typename Tape>
132 freeIndex<Tape>(index);
134 bool generatedNewIndex = Base::template assignUnusedIndex<Tape>(index);
135 if (generatedNewIndex) {
141 return generatedNewIndex;
145 template<
typename Tape>
151 freeIndex<Tape>(lhs);
162 assignIndex<Tape>(lhs);
167 template<
typename Tape>
170 indexUse[index] -= 1;
172 if (indexUse[index] == 0) {
173 Base::template freeIndex<Tape>(index);
#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
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
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
static Index constexpr InactiveIndex
Default inactive index for all index managers.
Definition indexManagerInterface.hpp:86
Extends the ReuseIndexManager with a copy optimization.
Definition multiUseIndexManager.hpp:57
bool assignIndex(Index &index)
Call on assignment of a primal value, e.g. on w for w = a + b.
Definition multiUseIndexManager.hpp:104
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition multiUseIndexManager.hpp:91
T_Index Index
See MultiUseIndexManager.
Definition multiUseIndexManager.hpp:60
void freeIndex(Index &index)
Call on destruction of a primal value. Usually called from the destructor.
Definition multiUseIndexManager.hpp:168
void copyIndex(Index &lhs, Index const &rhs)
Call on copy of a primal value, e.g. w = a.
Definition multiUseIndexManager.hpp:146
MultiUseIndexManager(Index const &reservedIndices)
Constructor.
Definition multiUseIndexManager.hpp:81
static bool constexpr IsLinear
See ReuseIndexManager.
Definition multiUseIndexManager.hpp:69
bool assignUnusedIndex(Index &index)
Call on registering input values.
Definition multiUseIndexManager.hpp:131
static bool constexpr CopyNeedsStatement
Copy optimization only active if configured.
Definition multiUseIndexManager.hpp:67
bool valid
Prevent index free after destruction.
Definition reuseIndexManagerBase.hpp:95
Reuse index manager with a many-to-one relation between tapes and index manager.
Definition reuseIndexManager.hpp:53
Index getLargestCreatedIndex() const
Returns the largest created index.
Definition reuseIndexManager.hpp:109
static bool constexpr NeedsStaticStorage
< See ReuseIndexManagerBase.
Definition reuseIndexManagerBase.hpp:81
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition reuseIndexManager.hpp:91
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addDoubleEntry(std::string const &name, double const &value, LocalReductionOperation operation=LocalReductionOperation::Sum, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:137