41#include "../../traits/misc/enableIfHelpers.hpp"
43#include "dataInterface.hpp"
44#include "emptyData.hpp"
45#include "pointerStore.hpp"
46#include "position.hpp"
63 template<
typename T_Chunk,
typename T_NestedData = EmptyData,
typename T_Po
interInserter = Po
interStore<T_Chunk>>
75 template<
int selectedDepth>
77 typename std::conditional<selectedDepth == 0, TerminatingPointerStore<PointerInserter>,
95 BlockData(
size_t const& chunkSize) : chunk(chunkSize), nested(nullptr) {}
101 template<
typename... Data>
104 chunk.pushData(data...);
108 template<
typename... Data>
111 chunk.dataPointer(chunk.getUsedSize(), pointers...);
117 chunk.setUsedSize(chunk.getUsedSize() + size);
124 codiAssert(chunk.getUsedSize() + items <= chunk.getSize());
126 return chunk.getUsedSize();
134 chunk.resize(totalSize);
153 chunk.setUsedSize(pos.
data);
155 nested->resetTo(pos.
inner);
172 return chunk.getUsedSize();
177 return Position(chunk.getUsedSize(), nested->getPosition());
182 return chunk.getUsedSize() - startPos;
187 return Position(0, nested->getZeroPosition());
196 size_t allocedSize = chunk.getSize();
198 size_t entrySize = Chunk::EntrySize;
200 double memoryUsed = (double)dataEntries * (
double)entrySize;
201 double memoryAlloc = (double)allocedSize * (
double)entrySize;
205 values.
addDoubleEntry(
"Memory allocated", memoryAlloc,
false,
true);
209 template<typename TargetPosition, typename = typename enable_if_not_same<TargetPosition, Position>::type>
211 return nested->template extractPosition<TargetPosition>(pos.
inner);
215 template<typename TargetPosition, typename = typename enable_if_same<TargetPosition, Position>::type>
224 codiAssert(v->getZeroPosition() == v->getPosition());
231 chunk.swap(other.chunk);
233 nested->swap(*other.nested);
240 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
244 pHandle.setPointers(0, &chunk);
246 size_t dataPos = start.
data;
247 pHandle.template callNestedForward<selectedDepth - 1>(
249 nested, dataPos, end.
data,
251 start.
inner, end.
inner, function, std::forward<Args>(args)...);
257 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
262 size_t dataPos = start.
data;
263 pHandle.setPointers(0, &chunk);
265 pHandle.template callNestedReverse<selectedDepth - 1>(
267 nested, dataPos, end.
data,
269 start.
inner, end.
inner, function, std::forward<Args>(args)...);
275 template<
typename FunctionObject,
typename... Args>
277 function(&chunk, std::forward<Args>(args)...);
280 nested->forEachChunk(function, recursive, std::forward<Args>(args)...);
285 template<
typename FunctionObject,
typename... Args>
292 for (
size_t dataPos = start.
data; dataPos < end.
data; dataPos += 1) {
293 pHandle.setPointers(dataPos, &chunk);
294 pHandle.call(function, std::forward<Args>(args)...);
299 template<
typename FunctionObject,
typename... Args>
307 for (
size_t dataPos = start.
data; dataPos > end.
data; ) {
310 pHandle.setPointers(dataPos, &chunk);
311 pHandle.call(function, std::forward<Args>(args)...);
317 template<
typename Chunk,
typename NestedData = EmptyData>
#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_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Position with one index for e.g. array access.
Definition position.hpp:102
size_t data
Array position index.
Definition position.hpp:107
NestedPosition inner
Position of nested data.
Definition position.hpp:109
Data is stored in one contiguous block in this DataInterface implementation.
Definition blockData.hpp:64
InternalPosHandle reserveItems(size_t const &items)
Reserve this many items on the data stream. See pushData for details.
Definition blockData.hpp:122
void addDataSize(size_t size)
Add this many items to the data stream, after the data has been manipulated via pointers obtained fro...
Definition blockData.hpp:115
void erase(Position const &start, Position const &end, bool recursive=true)
Definition blockData.hpp:160
void forEachChunk(FunctionObject &function, bool recursive, Args &&... args)
Calls the function object for each continuous segment of data.
Definition blockData.hpp:276
typename NestedData::Position NestedPosition
Position of NestedData.
Definition blockData.hpp:72
BlockData(size_t const &chunkSize)
Allocate chunkSize entries. Requires a call to setNested.
Definition blockData.hpp:95
void resize(size_t const &totalSize)
Definition blockData.hpp:133
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 blockData.hpp:258
size_t InternalPosHandle
Position in the chunk.
Definition blockData.hpp:71
Position extractPosition(Position const &pos) const
Extract the position of a nested DataInterface from the global position object provide by this interf...
Definition blockData.hpp:216
T_PointerInserter PointerInserter
See BlockData.
Definition blockData.hpp:69
Position getPosition() const
Definition blockData.hpp:176
typename std::conditional< selectedDepth==0, TerminatingPointerStore< PointerInserter >, PointerInserter >::type NestingDepthPointerInserter
For selectedDepth == 0 create a pointer inserter that calls the function object.
Definition blockData.hpp:76
void swap(BlockData< Chunk, NestedData > &other)
Definition blockData.hpp:230
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 blockData.hpp:241
void reset()
Definition blockData.hpp:138
ArrayPosition< NestedPosition > Position
Contains position data for this DataInterface and all nested interfaces.
Definition blockData.hpp:80
T_Chunk Chunk
See BlockData.
Definition blockData.hpp:67
T_NestedData NestedData
See BlockData.
Definition blockData.hpp:68
void setNested(NestedData *v)
Definition blockData.hpp:221
void resetHard()
Definition blockData.hpp:143
void getDataPointers(Data *&... pointers)
Get pointers to the data from the storage implementation. The method can only be called after a call ...
Definition blockData.hpp:109
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 blockData.hpp:300
TargetPosition extractPosition(Position const &pos) const
Extract the position of a nested DataInterface from the global position object provide by this interf...
Definition blockData.hpp:210
void resetTo(Position const &pos)
Definition blockData.hpp:150
Position getZeroPosition() const
Definition blockData.hpp:186
size_t getPushedDataCount(InternalPosHandle const &startPos)
Definition blockData.hpp:181
void pushData(Data const &... data)
Add data to the storage allocated by the implementation. The method can only be called after a call t...
Definition blockData.hpp:102
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 blockData.hpp:286
void addToTapeValues(TapeValues &values) const
Add amount of stored data to the TapeValues object. Not called on the nested vector.
Definition blockData.hpp:195
size_t getDataSize() const
Definition blockData.hpp:171
BlockData(size_t const &chunkSize, NestedData *nested)
Allocate chunkSize entries and set the nested DataInterface.
Definition blockData.hpp:90
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
Inserts data pointers at the back of all arguments in the nested call hierarchy.
Definition pointerStore.hpp:72
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:73
void addDoubleEntry(std::string const &name, double const &value, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:126
void addUnsignedLongEntry(std::string const &name, unsigned long const &value)
Add unsigned long entry.
Definition tapeValues.hpp:150