51 std::string _fileName;
67 bool*
getNextBlock(std::size_t& sizeBlock,
const bool loadingMode);
70 template<
bool includeLogOutputDir=true>
71 bool load(std::string fileName =
"",
const bool enforceUint=
false);
73 template<
bool includeLogOutputDir=true>
74 bool save(std::string fileName =
"",
const bool enforceUint=
false);
77 bool load(
const std::uint8_t* buffer);
79 bool save(std::uint8_t* buffer);
82 void computeSize(
const bool enforceRecompute=
false);
86 void validateFileName(std::string &fileName);
88 template<
bool includeLogOutputDir=true>
89 const std::string getFullFileName(
const std::string& fileName);
164 virtual bool*
getBlock(
const std::size_t iBlock, std::size_t& sizeBlock,
165 const bool loadingMode =
false) = 0;
180 template<
bool includeLogOutputDir=true>
181 bool save(std::string fileName =
"",
const bool enforceUint=
false);
183 template<
bool includeLogOutputDir=true>
184 bool load(std::string fileName =
"",
const bool enforceUint=
false);
187 bool save(std::uint8_t* buffer);
189 bool load(
const std::uint8_t* buffer);
211 template<
typename DataType>
212 void registerVar(
const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock,
bool *&dataPtr,
213 const DataType &data,
const size_t arrayLength = 1)
const
215 if (iBlock == currentBlock) {
216 sizeBlock =
sizeof(DataType) * arrayLength;
217 dataPtr = (
bool *) (&data);
238 template<
typename DataType>
240 bool *&dataPtr, DataType &data,
const bool loadingMode=
false)
242 if (iBlock >= currentBlock && iBlock < currentBlock + data.getNblock()) {
243 dataPtr = data.getBlock(iBlock - currentBlock, sizeBlock, loadingMode);
245 currentBlock += data.getNblock();
260 template<
typename DataType>
262 bool *&dataPtr, DataType* data,
const size_t arrayLength,
263 const bool loadingMode=
false)
265 static_assert(std::is_base_of<Serializable, DataType>::value,
"DataType must be a Serializable.");
267 if ( arrayLength > 0 ) {
268 if (iBlock >= currentBlock && iBlock < currentBlock + arrayLength * data[0].
getNblock()) {
269 size_t local_iBlock = iBlock - currentBlock;
270 size_t dataBlockCount = data[0].getNblock();
271 dataPtr = data[local_iBlock / dataBlockCount].getBlock(local_iBlock % dataBlockCount, sizeBlock, loadingMode);
273 currentBlock += arrayLength * data[0].getNblock();
328 template<
typename DataType>
330 size_t &sizeBufferIndex,
bool *&dataPtr, DataType &data,
331 const bool loadingMode=
false)
333 static_assert(std::is_base_of<Serializable, DataType>::value,
"DataType must be a Serializable.");
335 size_t dataBlockCount = 0;
339 dataBlockCount =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, 0);
342 dataBlockCount =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, data.getNblock());
345 if (iBlock >= currentBlock) {
346 if (iBlock < currentBlock + dataBlockCount) {
347 dataPtr = data.getBlock(iBlock - currentBlock, sizeBlock, loadingMode);
370 template<
typename DataType>
372 size_t &sizeBufferIndex,
bool *&dataPtr, std::vector<DataType> &data,
373 const bool loadingMode =
false)
375 if (iBlock >= currentBlock) {
377 size_t sizeOfVector =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, data.size());
380 if (iBlock == currentBlock && loadingMode) {
384 if (iBlock >= currentBlock && iBlock < currentBlock + sizeOfVector) {
385 sizeBlock =
sizeof(DataType);
386 dataPtr = (
bool *) (&data[iBlock - currentBlock]);
388 currentBlock += sizeOfVector;
417 template<
typename DataType>
419 std::size_t ¤tBlock,
size_t &sizeBufferIndex,
bool *&dataPtr,
420 std::vector<DataType> &data,
const bool loadingMode =
false)
422 static_assert(std::is_base_of<Serializable, DataType>::value,
"DataType must be a Serializable.");
424 if (iBlock >= currentBlock) {
426 size_t sizeOfVector =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, data.size());
429 if (iBlock == currentBlock && loadingMode) {
435 if (iBlock >= currentBlock && sizeOfVector > 0) {
436 for ( DataType& dataValue : data ) {
470 template<
typename DataType>
472 size_t &sizeBufferIndex,
bool *&dataPtr, std::vector<DataType> &data,
473 const bool loadingMode =
false)
475 static_assert(std::is_base_of<Serializable, DataType>::value,
"DataType must be a Serializable.");
477 if (iBlock >= currentBlock) {
479 size_t sizeOfVector =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, data.size());
482 if (iBlock == currentBlock && loadingMode) {
487 if (iBlock >= currentBlock && sizeOfVector > 0) {
488 for ( DataType& dataValue : data ) {
489 registerSerializable(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, dataValue, loadingMode);
521 template<
typename DataTypeKey,
typename DataTypeValue>
522 void registerMap(
const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock,
size_t &sizeBufferIndex,
523 bool *&dataPtr, std::map<DataTypeKey, DataTypeValue> &data,
const bool loadingMode =
false)
525 if (iBlock >= currentBlock) {
527 size_t sizeOfMap =
addSizeToBuffer(iBlock, sizeBlock, currentBlock, sizeBufferIndex, dataPtr, data.size());
529 if (iBlock >= currentBlock && iBlock < currentBlock + sizeOfMap + 1) {
531 sizeBlock =
sizeof(std::pair<DataTypeKey, DataTypeValue>);
536 if (iBlock > currentBlock) {
537 std::pair<DataTypeKey, DataTypeValue> *pairPtr = (std::pair<DataTypeKey, DataTypeValue> *)
_dataBuffer.back();
538 data.insert(*pairPtr);
544 if (iBlock < currentBlock + sizeOfMap) {
545 _dataBuffer.push_back((
bool *)
new std::pair<DataTypeKey, DataTypeValue>);
552 if (iBlock < currentBlock + sizeOfMap) {
554 auto map_it = data.begin();
555 std::advance(map_it, iBlock - currentBlock);
556 dataPtr = (
bool *) (&(*map_it));
560 currentBlock += sizeOfMap;
571 size_t addSizeToBuffer(
const std::size_t iBlock, std::size_t& sizeBlock, std::size_t¤tBlock,
572 size_t& sizeBufferIndex,
bool*& dataPtr,
const size_t data)
const
574 size_t returnSize = 0;
576 if (iBlock == currentBlock) {
581 if (iBlock >= currentBlock) {
Base class for serializable objects of dynamic size
void registerStdVectorOfVars(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
Method for registering a std::vector<DataType> of primitive DataType (int, double,...
std::vector< size_t > _sizeBuffer
std::vector of integer buffers (e.g. for std::vector size) to be buffered for the whole iteration pro...
void registerMap(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::map< DataTypeKey, DataTypeValue > &data, const bool loadingMode=false)
Method for registering a std::map<DataTypeKey, DataTypeValue> of fixed-sized types (i....
void registerStdVectorOfSerializablesOfConstSize(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
Method for registering a std::vector<DataType> of constant-sized Serializable
std::vector< bool * > _dataBuffer
Data buffer for data that has to be buffered between two getBlock() iterations.
void registerStdVectorOfSerializables(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, std::vector< DataType > &data, const bool loadingMode=false)
Method for registering a std::vector<DataType> of dynamic-sized DataType
void registerSerializable(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, DataType &data, const bool loadingMode=false)
Register Serializable object of dynamic size.
size_t addSizeToBuffer(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, size_t &sizeBufferIndex, bool *&dataPtr, const size_t data) const
Add a size_t to the sizeBuffer in the n-th util::round and return that size_t in all successive round...
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
virtual std::size_t getNblock() const =0
Returns the number of blocks.
virtual bool * getBlock(const std::size_t iBlock, std::size_t &sizeBlock, const bool loadingMode=false)=0
Returns the address of the i-th block and its size.
void registerVar(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
Register primitive data types (int, double, ...) or arrays of those.
void registerSerializablesOfConstSize(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, bool *&dataPtr, DataType *data, const size_t arrayLength, const bool loadingMode=false)
Register an array of Serializable objects of constant size.
virtual ~Serializable()=default
virtual std::size_t getSerializableSize() const =0
Returns the binary size of the data to be saved.
bool save(std::string fileName="", const bool enforceUint=false)
Save Serializable into file fileName
bool load(std::string fileName="", const bool enforceUint=false)
Load Serializable from file fileName
void registerSerializableOfConstSize(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t ¤tBlock, bool *&dataPtr, DataType &data, const bool loadingMode=false)
Register Serializable object of constant size.
Class for writing, reading, sending and receiving Serializable objects.
void resetCounter()
Resets the _iBlock counter.
std::size_t getSize() const
Returns the total memory size in bits.
bool load(std::string fileName="", const bool enforceUint=false)
Loads a file and pushes the data into the serialized class. Always in parallel, i....
bool save(std::string fileName="", const bool enforceUint=false)
Save _serializable into file filename. Always in parallel, i.e. one file per rank.
void computeSize(const bool enforceRecompute=false)
computes _size based on the individual definition of getBlock()
Serializer(Serializable &serializable, std::string fileName="")
Constructor.
bool * getNextBlock(std::size_t &sizeBlock, const bool loadingMode)
Returns pointer to the memory of the current block and increments iBlock
Top level namespace for all of OpenLB.