CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::MultiUseIndexManager< T_Index > Struct Template Reference

Extends the ReuseIndexManager with a copy optimization. More...

#include <multiUseIndexManager.hpp>

Inheritance diagram for codi::MultiUseIndexManager< T_Index >:

Public Types

using Base = ReuseIndexManager<Index>
 Base class abbreviation.
 
using Index = T_Index
 See MultiUseIndexManager.
 
- Public Types inherited from codi::ReuseIndexManager< T_Index >
using Base = ReuseIndexManagerBase<Index, ReuseIndexManager>
 Base class abbreviation.
 
using Index = T_Index
 See ReuseIndexManager.
 
- Public Types inherited from codi::ReuseIndexManagerBase< T_Index, ReuseIndexManager< T_Index > >
using Base
 Base class abbreviation.
 
using Impl
 See ReuseIndexManagerBase.
 
using Index
 See ReuseIndexManagerBase.
 
using Position
 See EmptyData.
 
- Public Types inherited from codi::IndexManagerInterface< T_Index >
using Index = T_Index
 See IndexManagerInterface.
 
- Public Types inherited from codi::EmptyData
using InternalPosHandle = size_t
 Will always be zero.
 
using NestedData = void
 No nested data.
 
using Position = EmptyPosition
 No positional data.
 
- Public Types inherited from codi::DataInterface< T_NestedData, T_InternalPosHandle >
using InternalPosHandle = T_InternalPosHandle
 See DataInterface.
 
using NestedData = T_NestedData
 See DataInterface.
 
using Position = EmptyPosition
 Contains position data for this DataInterface and all nested interfaces.
 

Public Member Functions

 MultiUseIndexManager (Index const &reservedIndices)
 Constructor.
 
ReuseIndexManager: Overwrites
void addToTapeValues (TapeValues &values) const
 Add storage and other information to the tape values.




 
template<typename Tape >
bool assignIndex (Index &index)
 Call on assignment of a primal value, e.g. on w for w = a + b.
 
template<typename Tape >
bool assignUnusedIndex (Index &index)
 Call on registering input values.
 
template<typename Tape >
void copyIndex (Index &lhs, Index const &rhs)
 Call on copy of a primal value, e.g. w = a.
 
template<typename Tape >
void freeIndex (Index &index)
 Call on destruction of a primal value. Usually called from the destructor.
 
- Public Member Functions inherited from codi::ReuseIndexManager< T_Index >
 ReuseIndexManager (Index const &reservedIndices)
 Constructor.
 
 ~ReuseIndexManager ()
 Destructor.
 
void addToTapeValues (TapeValues &values) const
 Add storage and other information to the tape values.


 
Index getLargestCreatedIndex () const
 Returns the largest created index.
 
- Public Member Functions inherited from codi::ReuseIndexManagerBase< T_Index, ReuseIndexManager< T_Index > >
 ReuseIndexManagerBase ()
 
 ~ReuseIndexManagerBase ()
 Destructor.
 
bool assignIndex (Index &index)
 Call on assignment of a primal value, e.g. on w for w = a + b.
 
bool assignUnusedIndex (Index &index)
 Call on registering input values.
 
void copyIndex (Index &lhs, Index const &rhs)
 Call on copy of a primal value, e.g. w = a.
 
void freeIndex (Index &index)
 Call on destruction of a primal value. Usually called from the destructor.
 
void reset ()
 Reset for a new recording.
 
void addToTapeValues (TapeValues &values) const
 Add storage and other information to the tape values.


 
- Public Member Functions inherited from codi::IndexManagerInterface< T_Index >
void addToTapeValues (TapeValues &values) const
 Add storage and other information to the tape values.
 
Index getLargestCreatedIndex () const
 Returns the largest created index.
 
template<typename Tape >
bool assignIndex (Index &index)
 Call on assignment of a primal value, e.g. on w for w = a + b.
 
template<typename Tape >
bool assignUnusedIndex (Index &index)
 Call on registering input values.
 
template<typename Tape >
void copyIndex (Index &lhs, Index const &rhs)
 Call on copy of a primal value, e.g. w = a.
 
template<typename Tape >
void freeIndex (Index &index)
 Call on destruction of a primal value. Usually called from the destructor.
 
void reset ()
 Reset for a new recording.
 
- Public Member Functions inherited from codi::EmptyData
void pushData ()
 Add data to the storage allocated by the implementation. The method can only be called after a call to reserveItems and only as often as the number of reserved items.
 
void getDataPointers ()
 Get pointers to the data from the storage implementation. The method can only be called after a call to reserveItems() and data can only be accessed from 0 to the number given by reserveItems (excluding). Afterwards, addDataSize() needs to be called with the actual number of elements that have been written.
 
void addDataSize (size_t size)
 Add this many items to the data stream, after the data has been manipulated via pointers obtained from getDataPointers().
 
InternalPosHandle reserveItems (size_t const &items)
 Reserve this many items on the data stream. See pushData for details.
 
void resize (size_t const &totalSize)
 
void reset ()
 
void resetHard ()
 
void resetTo (Position const &pos)
 
void erase (Position const &start, Position const &end, bool recursive=true)
 
size_t getDataSize () const
 
Position getPosition () const
 
size_t getPushedDataCount (InternalPosHandle const &startPos)
 
Position getZeroPosition () const
 
void addToTapeValues (TapeValues &values) const
 Add amount of stored data to the TapeValues object. Not called on the nested vector.
 
template<typename = void>
Position extractPosition (Position const &pos) const
 Extract the position of a nested DataInterface from the global position object provide by this interface.
 
void setNested (NestedData *v)
 


 
void swap (DataInterface &other)
 
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
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 DataInterfaces.


 
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
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 DataInterfaces.




 
template<typename FunctionObject , typename... Args>
void forEachChunk (FunctionObject &function, bool recursive, Args &&... args)
 Calls the function object for each continuous segment of data.
 
template<typename FunctionObject , typename... Args>
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.
 
template<typename FunctionObject , typename... Args>
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.
 
- Public Member Functions inherited from codi::DataInterface< T_NestedData, T_InternalPosHandle >
void addDataSize (size_t const &size)
 Add this many items to the data stream, after the data has been manipulated via pointers obtained from getDataPointers().
 
template<typename... Data>
void getDataPointers (Data *&... pointers)
 Get pointers to the data from the storage implementation. The method can only be called after a call to reserveItems() and data can only be accessed from 0 to the number given by reserveItems (excluding). Afterwards, addDataSize() needs to be called with the actual number of elements that have been written.
 
template<typename... Data>
void pushData (Data const &... data)
 Add data to the storage allocated by the implementation. The method can only be called after a call to reserveItems and only as often as the number of reserved items.
 
InternalPosHandle reserveItems (size_t const &items)
 Reserve this many items on the data stream. See pushData for details.
 
void resize (size_t const &totalSize)
 
void reset ()
 
void resetHard ()
 
void resetTo (Position const &pos)
 
void erase (Position const &start, Position const &end, bool recursive=true)
 
size_t getDataSize () const
 
Position getPosition () const
 
size_t getPushedDataCount (InternalPosHandle const &startPos)
 
Position getZeroPosition () const
 
void addToTapeValues (TapeValues &values) const
 Add amount of stored data to the TapeValues object. Not called on the nested vector.
 
template<typename TargetPosition >
TargetPosition extractPosition (Position const &pos) const
 Extract the position of a nested DataInterface from the global position object provide by this interface.
 
void setNested (NestedData *v)
 
void swap (DataInterface &other)
 
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
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 DataInterfaces.
 
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
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 DataInterfaces.
 
template<typename FunctionObject , typename... Args>
void forEachChunk (FunctionObject &function, bool recursive, Args &&... args)
 Calls the function object for each continuous segment of data.
 
template<typename FunctionObject , typename... Args>
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.
 
template<typename FunctionObject , typename... Args>
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.
 

Static Public Attributes

IndexManagerInterface: Constants
static bool constexpr CopyNeedsStatement
 Copy optimization only active if configured.
 
static bool constexpr IsLinear = false
 See ReuseIndexManager.
 
- Static Public Attributes inherited from codi::ReuseIndexManager< T_Index >
static bool constexpr CopyNeedsStatement
 No copy optimization is implemented.
 
static bool constexpr IsLinear
 < See ReuseIndexManagerBase.
 
static bool constexpr NeedsStaticStorage
 < See ReuseIndexManagerBase.
 
- Static Public Attributes inherited from codi::ReuseIndexManagerBase< T_Index, ReuseIndexManager< T_Index > >
static bool constexpr CopyNeedsStatement
 No copy optimization is implemented.
 
static bool constexpr IsLinear
 Identifiers are not coupled to statements.
 
static bool constexpr NeedsStaticStorage
 Identifiers are managed globally.
 
- Static Public Attributes inherited from codi::IndexManagerInterface< T_Index >
static Index constexpr InactiveIndex = Index(0)
 Default inactive index for all index managers.
 
static Index constexpr InvalidIndex
 Default invalid index for all index mangers (max value for unsigned types).
 
static bool constexpr CopyNeedsStatement
 True if no copy optimization is implemented. See IndexManagerInterface.
 
static bool constexpr IsLinear
 True if identifiers are coupled to the statements. See IndexManagerInterface.
 
static bool constexpr NeedsStaticStorage = false
 True if the index manager is specific to a tape type (and not a tape instance). See IndexManagerInterface.
 

Additional Inherited Members

- Public Attributes inherited from codi::ReuseIndexManager< T_Index >
friend Base
 Allow the base class to call protected and private methods.
 
- Protected Attributes inherited from codi::ReuseIndexManagerBase< T_Index, ReuseIndexManager< T_Index > >
size_t indexSizeIncrement
 Block size for index pool enlargement.
 
std::vector< IndexunusedIndices
 Pool of indices that have not been used in this recording yet.
 
size_t unusedIndicesPos
 Number of remaining unused indices.
 
std::vector< IndexusedIndices
 Pool of indices that have already been used in this recording.
 
size_t usedIndicesPos
 Number of remaining used indices.
 
bool valid
 Prevent index free after destruction.
 

Detailed Description

template<typename T_Index>
struct codi::MultiUseIndexManager< T_Index >

Extends the ReuseIndexManager with a copy optimization.

Mathematical and implementational details are explained in SBG2021Index.

Performs reference counting for each index. If the reference count is zero, then the index is freed and given back to the ReuseIndexManager.

Template Parameters
T_IndexType for the identifier, usually an integer type.

Member Function Documentation

◆ addToTapeValues()

template<typename T_Index >
void codi::MultiUseIndexManager< T_Index >::addToTapeValues ( TapeValues & values) const
inline

Add storage and other information to the tape values.



Parameters
[in,out]valuesWill only create new data entries and no new section.

Implementation: Adds max live indices, cur live indices.

Implementation: Additionally adds memory consumed by the index use vector.

◆ assignIndex()

template<typename T_Index >
template<typename Tape >
bool codi::MultiUseIndexManager< T_Index >::assignIndex ( Index & index)
inline

Call on assignment of a primal value, e.g. on w for w = a + b.

Returns
true if new indices have been generated internally.

◆ assignUnusedIndex()

template<typename T_Index >
template<typename Tape >
bool codi::MultiUseIndexManager< T_Index >::assignUnusedIndex ( Index & index)
inline

Call on registering input values.

Returns
true if new indices have been generated internally.

◆ copyIndex()

template<typename T_Index >
template<typename Tape >
void codi::MultiUseIndexManager< T_Index >::copyIndex ( Index & lhs,
Index const & rhs )
inline

Call on copy of a primal value, e.g. w = a.

◆ freeIndex()

template<typename T_Index >
template<typename Tape >
void codi::MultiUseIndexManager< T_Index >::freeIndex ( Index & index)
inline

Call on destruction of a primal value. Usually called from the destructor.

Member Data Documentation

◆ CopyNeedsStatement

template<typename T_Index >
bool constexpr codi::MultiUseIndexManager< T_Index >::CopyNeedsStatement
staticconstexpr
Initial value:
=
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186

Copy optimization only active if configured.


The documentation for this struct was generated from the following file: