CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter > Struct Template Reference

Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space, a new chunk is allocated. More...

#include <chunkedData.hpp>

Inheritance diagram for codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >:

Public Types

using Chunk = T_Chunk
 See ChunkedData.
 
using InternalPosHandle = size_t
 Position in the chunk.
 
using NestedData = T_NestedData
 See ChunkedData.
 
using NestedPosition = typename NestedData::Position
 Position of NestedData.
 
template<int selectedDepth>
using NestingDepthPointerInserter
 For selectedDepth == 0 create a pointer inserter that calls the function object.
 
using PointerInserter = T_PointerInserter
 See ChunkedData.
 
using Position = ChunkPosition<NestedPosition>
 Contains position data for this DataInterface and all nested interfaces.
 
- 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

 ChunkedData (size_t const &chunkSize)
 Allocate chunkSize entries. Requires a call to setNested.
 
 ChunkedData (size_t const &chunkSize, NestedData *nested)
 Allocate chunkSize entries and set the nested DataInterface.
 
 ~ChunkedData ()
 Destructor.
 
Adding items
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.
 
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.
 
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.


 
Size management
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)
 
Position functions
size_t getDataSize () const
 
Position getPosition () const
 
size_t getPushedDataCount (InternalPosHandle const &startPos)
 
Position getZeroPosition () const
 
Misc functions
void addToTapeValues (TapeValues &values) const
 Add amount of stored data to the TapeValues object. Not called on the nested vector.


 
template<typename TargetPosition , typename = typename enable_if_not_same<TargetPosition, Position>::type>
TargetPosition extractPosition (Position const &pos) const
 Extract the position of a nested DataInterface from the global position object provide by this interface.
 
template<typename TargetPosition , typename = typename enable_if_same<TargetPosition, Position>::type>
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 (ChunkedData< Chunk, NestedData > &other)
 
Iterator functions
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.
 

Detailed Description

template<typename T_Chunk, typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
struct codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >

Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space, a new chunk is allocated.

See DataInterface documentation for details.

Each chunk has the size provided in the constructor.

Template Parameters
T_ChunkHas to implement ChunkBase. The chunk defines the data stored in this implementation.
T_NestedDataNested DataInterface.
T_PointerInserterDefines how data is appended to evaluate* function calls.

Member Typedef Documentation

◆ NestingDepthPointerInserter

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<int selectedDepth>
using codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::NestingDepthPointerInserter
Initial value:
typename std::conditional<selectedDepth == 0, TerminatingPointerStore<PointerInserter>,
T_PointerInserter PointerInserter
See ChunkedData.
Definition chunkedData.hpp:69

For selectedDepth == 0 create a pointer inserter that calls the function object.

◆ Position

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
using codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::Position = ChunkPosition<NestedPosition>

Contains position data for this DataInterface and all nested interfaces.

Member Function Documentation

◆ addDataSize()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::addDataSize ( size_t size)
inline

Add this many items to the data stream, after the data has been manipulated via pointers obtained from getDataPointers().

See getDataPointers for details.

Parameters
[in]sizeNumber of data items that have been written.

◆ addToTapeValues()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::addToTapeValues ( TapeValues & values) const
inline

Add amount of stored data to the TapeValues object. Not called on the nested vector.

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

Implementation: Adds: Total number, Number of chunks, Memory used, Memory allocated

◆ erase()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::erase ( Position const & start,
Position const & end,
bool recursive = true )
inline

Erase the given range of data. Implementations may choose to free allocated memory. The parameter recursive controls whether erase is also called on nested interfaces. Implementation: If the given range start..end does not only overlap with parts of chunks but contains complete chunks, those completely contained chunks are deleted in the course of the erase.

◆ evaluateForward()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::evaluateForward ( Position const & start,
Position const & end,
FunctionObject function,
Args &&... args )
inline

Evaluates the function object with segments of continuous and valid data for all nested DataInterfaces.

func is called for each region of continuous data that is valid for all nested DataInterfaces. func is then called as

function(args...,
start, end, dataEntry1*, dataEntry2*,
startNested, endNested, dataEntry1Nested*, dataEntry2Nested*,
startNestedNested, endNestedNested, dataEntry1NestedNested*,
...);

What kind of data is appended by each DataInterface is implementation dependent. The default is the set (start, end, dataEntry1, dataEntry2, etc.) which is appended.

It has to hold start <= end.

Positions count up in this call.

Parameters
[in]startStarting position.
[in]endEnding position.
[in]functionFunction object called.
[in,out]argsAdditional arguments for the function object.
Template Parameters
selectedDepthSelected depth for the recursion into nested data interfaces. 0 means that only the data from this interface is used. A value of 1 means that the data from the first nested interface is used, etc.. A value of -1 can be used to select the innermost interface, regardless of the number of nested interfaces.
FunctionObjectFunction object which is called.
ArgsArguments for the function object.

◆ evaluateReverse()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<int selectedDepth = -1, typename FunctionObject , typename... Args>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::evaluateReverse ( Position const & start,
Position const & end,
FunctionObject function,
Args &&... args )
inline

Evaluates the function object with segments of continuous and valid data for all nested DataInterfaces.

Same as evaluateForward. It has to hold start >= end. Positions count down in this call.

Parameters
[in]startStarting position.
[in]endEnding position.
[in]functionFunction object called.
[in,out]argsAdditional arguments for the function object.
Template Parameters
selectedDepthSelected depth for the recursion into nested data interfaces. 0 means that only the data from this interface is used. A value of 1 means that the data from the first nested interface is used, etc.. A value of -1 can be used to select the innermost interface, regardless of the number of nested interfaces.
FunctionObjectFunction object which is called.
ArgsArguments for the function object.

◆ extractPosition() [1/2]

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename TargetPosition , typename = typename enable_if_not_same<TargetPosition, Position>::type>
TargetPosition codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::extractPosition ( Position const & pos) const
inline

Extract the position of a nested DataInterface from the global position object provide by this interface.

Parameters
[in]posPosition of the DataInterface.
Template Parameters
TargetPositionPosition definition of a nested DataInterface.

◆ extractPosition() [2/2]

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename TargetPosition , typename = typename enable_if_same<TargetPosition, Position>::type>
Position codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::extractPosition ( Position const & pos) const
inline

Extract the position of a nested DataInterface from the global position object provide by this interface.

Parameters
[in]posPosition of the DataInterface.
Template Parameters
TargetPositionPosition definition of a nested DataInterface.

◆ forEachChunk()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename FunctionObject , typename... Args>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::forEachChunk ( FunctionObject & function,
bool recursive,
Args &&... args )
inline

Calls the function object for each continuous segment of data.

The call is

function(chunk, args...);

Chunk is of the type ChunkBase.

Parameters
[in]functionFunction object called.
[in]recursiveTrue if same call should be performed for all nested DataInterfaces.
[in,out]argsAdditional arguments for the function object.
Template Parameters
FunctionObjectFunction object which is called.
ArgsArguments for the function object.

◆ forEachForward()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename FunctionObject , typename... Args>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::forEachForward ( Position const & start,
Position const & end,
FunctionObject function,
Args &&... args )
inline

Calls the function object for each item in the data stream. This call is not recursive.

The call to function is

function(args..., entry1*, entry2*, ...);

It has to hold start <= end.

Parameters
[in]startStarting position.
[in]endEnding position
[in]functionFunction object called.
[in,out]argsAdditional arguments for the function object.
Template Parameters
FunctionObjectFunction object which is called.
ArgsArguments for the function object.

◆ forEachReverse()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename FunctionObject , typename... Args>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::forEachReverse ( Position const & start,
Position const & end,
FunctionObject function,
Args &&... args )
inline

Calls the function object for each item in the data stream. This call is not recursive.

See forEachForward.

It has to hold start >= end.

Parameters
[in]startStarting position.
[in]endEnding position
[in]functionFunction object called.
[in,out]argsAdditional arguments for the function object.
Template Parameters
FunctionObjectFunction object which is called.
ArgsArguments for the function object.

◆ getDataPointers()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename... Data>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::getDataPointers ( Data *&... pointers)
inline

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.

The call to reserveItems only represents the maximum number of data items that can be accessed safely. It is fine if less data items are accessed.

After all elements have been written to the arrays, addDataSize needs to be called with the final written number of entries.

Example usage:

// 1. Request space.
argVector.reserveItems(10);
// 2. Add the data.
int* dataInt;
double* dataDouble;
argVector.getDataPointers(dataInt, dataDouble);
for(int i = 0; i < 5; i += 1) {
dataInt[i] = i + 1;
dataDouble[i] = i + 11;
}
// 3. Add the number of items.
argVector.addDataSize(5);
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
void addDataSize(size_t const &size)
Add this many items to the data stream, after the data has been manipulated via pointers obtained fro...
void getDataPointers(Data *&... pointers)
Get pointers to the data from the storage implementation. The method can only be called after a call ...
InternalPosHandle reserveItems(size_t const &items)
Reserve this many items on the data stream. See pushData for details.
Parameters
[in]pointersThe pointers that are populated with the data from the internal representation.
Template Parameters
DataTypes of the pointers.

◆ getDataSize()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
size_t codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::getDataSize ( ) const
inline

Returns
Total number of data items stored.

◆ getPosition()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
Position codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::getPosition ( ) const
inline

Returns
The current global position of this DataInterface and all nested interfaces.

◆ getPushedDataCount()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
size_t codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::getPushedDataCount ( InternalPosHandle const & startPos)
inline

Compute the number of data items stored after a call to reserveItems.

◆ getZeroPosition()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
Position codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::getZeroPosition ( ) const
inline

Returns
The start position of the DataInterface and all nested interfaces.

◆ pushData()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
template<typename... Data>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::pushData ( Data const &... data)
inline

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.

pushData() can be called less often than indicated with reserveItems(). The call to reserveItems only represents the maximum number of data items that can be pushed safely.

After a new call to reserveItems(), only this many number of data items can be pushed, leftovers will not accumulate.

For an example of how to use pushData, please see the DataInterface documentation.

Parameters
[in]dataThe number of arguments has to match the number of data stores of the implementation.
Template Parameters
DataTypes of the pushed data.

◆ reserveItems()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
InternalPosHandle codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::reserveItems ( size_t const & items)
inline

Reserve this many items on the data stream. See pushData for details.

Parameters
[in]itemsNumber of data items to reserve.
Returns
Can be used in getPushedDataCount(). Only the newest handle is valid.

Implementation: Creates a new chunk if not enough space is left.

◆ reset()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::reset ( )
inline

Reset to the zero position. Data is not deallocated. Also called on nested interfaces.

◆ resetHard()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::resetHard ( )
inline

Reset to the zero position. Data is deallocated and the default size is allocated again. Also called on nested interfaces.

◆ resetTo()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::resetTo ( Position const & pos)
inline

Reset to the given position. Data is not deallocated. Also called on the nested interfaces.

◆ resize()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::resize ( size_t const & totalSize)
inline

Allocate the requested number of data items.

◆ setNested()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::setNested ( NestedData * v)
inline

Set the pointer to the nested vector. Needs to be done before any other action and only once.

◆ swap()

template<typename T_Chunk , typename T_NestedData = EmptyData, typename T_PointerInserter = PointerStore<T_Chunk>>
void codi::ChunkedData< T_Chunk, T_NestedData, T_PointerInserter >::swap ( ChunkedData< Chunk, NestedData > & other)
inline

Swap with other DataInterface of the same type.


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