OpenLB 1.7
|
Base class for serializable objects of constant size. For dynamic size use BufferSerializable
.
More...
#include <serializer.h>
Public Member Functions | |
virtual | ~Serializable ()=default |
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. | |
virtual std::size_t | getNblock () const =0 |
Returns the number of blocks. | |
virtual std::size_t | getSerializableSize () const =0 |
Returns the binary size of the data to be saved. | |
template<bool includeLogOutputDir = true> | |
bool | save (std::string fileName="", const bool enforceUint=false) |
Save Serializable into file fileName | |
template<bool includeLogOutputDir = true> | |
bool | load (std::string fileName="", const bool enforceUint=false) |
Load Serializable from file fileName | |
bool | save (std::uint8_t *buffer) |
Save Serializable into buffer of length getSerializableSize | |
bool | load (const std::uint8_t *buffer) |
Load Serializable from buffer of length getSerializableSize | |
virtual void | postLoad () |
Protected Member Functions | |
template<typename DataType > | |
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. | |
template<typename DataType > | |
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. | |
template<typename DataType > | |
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. | |
Base class for serializable objects of constant size. For dynamic size use BufferSerializable
.
All serializable classes have to implement their individual getBlock()
method. An individual getNblock()
method must also be provided. An individual getSerializableSize()
method should also be provided for efficiency reasons.
All Serializable
subclasses with dynamic size (unknown at compile time, e.g. holding std::vector
or std::map
members) have to inherit from BufferSerializable
. _Note: If the dynamic size is computable through constant values (see BlockLattice2D
), the Serializable
does not need to be a BufferSerializable
.
Any serializable class inherits from either Serializable
or BufferSerializable
(if it contains dynamic-sized member variables) and has to implement its individual getBlock()
method.
getBlock()
is called by the Serializer
repeatedly with an increasing counter iBlock
. getBlock()
returns a (bool*)
address to the i-th data block and fills sizeBlock
with the corresponding size. As long as getBlock()
does not return a nullptr
, iBlock
is increased and getBlock()
is called again by Serializer
.
It is strongly recommended (and obligatory for the correct usage of register
methods) to define std::size_t currentBlock = 0;
within getBlock()
. currentBlock
will be increased by the register
methods by the number of blocks they occupy.
For user's convenience the Serializable
class provides register
methods for data of constant size:
Method | Suitable for |
---|---|
registerVar() | Primitive data types and arrays of those (e.g. int , double , std::string , ...) |
registerSerializableOfConstSize() | Constant-sized Serializable object |
registerSerializablesOfConstSize() | Array of constant-sized Serializable objects |
registerVar()
, currentBlock
is counted up by 1 - arrays
are treated as one block of size sizeof(DataType) * arrayLength
.registerSerializableOfConstSize()
, currentBlock
is increased by getNblock()
of the given Serializable
.registerSerializablesOfConstSize()
, currentBlock
is increased by arrayLength * data.getNblock()
of the given Serializable
.Note: Dynamic-sized objects need to inherit from BufferSerializable
, which uses buffers and provides additional register
methods for:
Method | Suitable for |
---|---|
registerSerializable() | Dynamic-sized Serializable object (for constant-sized Serializable |
| use registerSerializableOfConstSize()
registerStdVectorOfVars()
| std::vector<DataType>
(for primitive DataType
, e.g. int
, | double
, ...) registerStdVectorOfSerializablesOfConstSize()
| std::vector<DataType>
(for Serializable
s of constant size) registerStdVectorOfSerializables()
| std::vector<DataType>
(for Serializable
s of dynamic size) registerMap()
| std::map<DataTypeKey, DataTypeValue>
(for primitive types)
Definition at line 145 of file serializer.h.
|
virtualdefault |
|
pure virtual |
Returns the address of the i-th block and its size.
iBlock | Index of the block to be returned |
sizeBlock | Reference to the size of the returned block |
Each getBlock()
method should look like this:
std::size_t currentBlock = 0; bool* dataPtr = nullptr; // ... register methods... return dataPtr;
Implemented in olb::LoadBalancer< T >, olb::LoadBalancer< S >, olb::BlockData< D, T, U >, olb::BlockData< 2, T, BaseType >, olb::BlockData< 2, T, bool >, olb::BlockData< 2, T, T >, olb::BlockData< 3, S, S >, olb::BlockData< 3, T, BaseType >, olb::BlockData< 3, T, bool >, olb::BlockData< 3, T, T >, olb::BlockData< DESCRIPTOR::d, T, bool >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::CPU_SIMD >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA >, olb::ConcreteBlockLattice< T, DESCRIPTOR, SOURCE >, olb::ConcreteBlockLattice< T, DESCRIPTOR, TARGET >, olb::CellIndexListD< T, DESCRIPTOR, FIELDS >, olb::ColumnVector< COLUMN, D >, olb::ColumnVector< ImplementationOf< FIELD::template column_type< int >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< S >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< FIELD >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< olb::cpu::simd::Column< T >, D >, olb::ColumnVector< olb::cpu::sisd::Column< int >, 1 >, olb::Data< T, DESCRIPTOR, PLATFORM >, olb::Data< T, DESCRIPTOR, Platform::CPU_SISD >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS... >, olb::MultiFieldArrayD< T, DESCRIPTOR, Platform::CPU_SISD, olb::descriptors::CELL_ID, FIELDS... >, olb::ConcreteParametersD< T, DESCRIPTOR, PLATFORM, PARAMETERS >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename DYNAMICS::parameters >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename OPERATOR::parameters >, olb::cpu::simd::Column< T >, olb::cpu::simd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SIMD >, olb::cpu::sisd::Column< T >, olb::cpu::sisd::Column< BaseType >, olb::cpu::sisd::Column< bool >, olb::cpu::sisd::Column< int >, olb::cpu::sisd::Column< S >, olb::cpu::sisd::Column< U >, olb::cpu::sisd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SISD >, olb::gpu::cuda::Column< T >, olb::gpu::cuda::Column< CellID >, olb::gpu::cuda::Column< std::uint8_t >, olb::gpu::cuda::CyclicColumn< T >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, PARAMETERS >, olb::ConcreteBlockMask< T, Platform::GPU_CUDA >, olb::SuperLattice< T, DESCRIPTOR >, olb::SuperLattice< S, descriptor >, olb::SuperLattice< T, Lattice >, olb::SuperLattice< T, TDESCRIPTOR >, olb::BlockGeometry< T, D >, olb::BlockGeometry< S, D >, olb::BlockGeometry< T, 2 >, olb::BlockGeometry< T, 3 >, olb::BlockGeometry< T, DESCRIPTOR::d >, olb::Cuboid3D< T >, olb::Cuboid3D< S >, olb::CuboidGeometry3D< T >, olb::SuperGeometry< T, D >, olb::SuperGeometry< S, D >, olb::SuperGeometry< S, dim >, olb::SuperGeometry< T, 2 >, olb::SuperGeometry< T, 3 >, and olb::SuperGeometry< T, DESCRIPTOR::d >.
|
pure virtual |
Returns the number of blocks.
All Serializable
classes have to implement this method.
Implemented in olb::LoadBalancer< T >, olb::LoadBalancer< S >, olb::BlockData< D, T, U >, olb::BlockData< 2, T, BaseType >, olb::BlockData< 2, T, bool >, olb::BlockData< 2, T, T >, olb::BlockData< 3, S, S >, olb::BlockData< 3, T, BaseType >, olb::BlockData< 3, T, bool >, olb::BlockData< 3, T, T >, olb::BlockData< DESCRIPTOR::d, T, bool >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::CPU_SIMD >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA >, olb::ConcreteBlockLattice< T, DESCRIPTOR, SOURCE >, olb::ConcreteBlockLattice< T, DESCRIPTOR, TARGET >, olb::CellIndexListD< T, DESCRIPTOR, FIELDS >, olb::ColumnVector< COLUMN, D >, olb::ColumnVector< ImplementationOf< FIELD::template column_type< int >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< S >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< FIELD >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< olb::cpu::simd::Column< T >, D >, olb::ColumnVector< olb::cpu::sisd::Column< int >, 1 >, olb::Data< T, DESCRIPTOR, PLATFORM >, olb::Data< T, DESCRIPTOR, Platform::CPU_SISD >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS... >, olb::MultiFieldArrayD< T, DESCRIPTOR, Platform::CPU_SISD, olb::descriptors::CELL_ID, FIELDS... >, olb::ConcreteParametersD< T, DESCRIPTOR, PLATFORM, PARAMETERS >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename DYNAMICS::parameters >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename OPERATOR::parameters >, olb::cpu::simd::Column< T >, olb::cpu::simd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SIMD >, olb::cpu::sisd::Column< T >, olb::cpu::sisd::Column< BaseType >, olb::cpu::sisd::Column< bool >, olb::cpu::sisd::Column< int >, olb::cpu::sisd::Column< S >, olb::cpu::sisd::Column< U >, olb::cpu::sisd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SISD >, olb::gpu::cuda::Column< T >, olb::gpu::cuda::Column< CellID >, olb::gpu::cuda::Column< std::uint8_t >, olb::gpu::cuda::CyclicColumn< T >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, PARAMETERS >, olb::ConcreteBlockMask< T, Platform::GPU_CUDA >, olb::SuperLattice< T, DESCRIPTOR >, olb::SuperLattice< S, descriptor >, olb::SuperLattice< T, Lattice >, olb::SuperLattice< T, TDESCRIPTOR >, olb::BlockGeometry< T, D >, olb::BlockGeometry< S, D >, olb::BlockGeometry< T, 2 >, olb::BlockGeometry< T, 3 >, olb::BlockGeometry< T, DESCRIPTOR::d >, olb::Cuboid3D< T >, olb::Cuboid3D< S >, olb::CuboidGeometry3D< T >, olb::SuperGeometry< T, D >, olb::SuperGeometry< S, D >, olb::SuperGeometry< S, dim >, olb::SuperGeometry< T, 2 >, olb::SuperGeometry< T, 3 >, and olb::SuperGeometry< T, DESCRIPTOR::d >.
|
pure virtual |
Returns the binary size of the data to be saved.
This method must be overloaded by all child classes.
Implemented in olb::LoadBalancer< T >, olb::LoadBalancer< S >, olb::BlockData< D, T, U >, olb::BlockData< 2, T, BaseType >, olb::BlockData< 2, T, bool >, olb::BlockData< 2, T, T >, olb::BlockData< 3, S, S >, olb::BlockData< 3, T, BaseType >, olb::BlockData< 3, T, bool >, olb::BlockData< 3, T, T >, olb::BlockData< DESCRIPTOR::d, T, bool >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::CPU_SIMD >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA >, olb::ConcreteBlockLattice< T, DESCRIPTOR, SOURCE >, olb::ConcreteBlockLattice< T, DESCRIPTOR, TARGET >, olb::CellIndexListD< T, DESCRIPTOR, FIELDS >, olb::ColumnVector< COLUMN, D >, olb::ColumnVector< ImplementationOf< FIELD::template column_type< int >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< S >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< FIELD >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< olb::cpu::simd::Column< T >, D >, olb::ColumnVector< olb::cpu::sisd::Column< int >, 1 >, olb::Data< T, DESCRIPTOR, PLATFORM >, olb::Data< T, DESCRIPTOR, Platform::CPU_SISD >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS >, olb::MultiFieldArrayD< T, DESCRIPTOR, PLATFORM, FIELDS... >, olb::MultiFieldArrayD< T, DESCRIPTOR, Platform::CPU_SISD, olb::descriptors::CELL_ID, FIELDS... >, olb::ConcreteParametersD< T, DESCRIPTOR, PLATFORM, PARAMETERS >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename DYNAMICS::parameters >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, typename OPERATOR::parameters >, olb::cpu::simd::Column< T >, olb::cpu::simd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SIMD >, olb::cpu::sisd::Column< T >, olb::cpu::sisd::Column< BaseType >, olb::cpu::sisd::Column< bool >, olb::cpu::sisd::Column< int >, olb::cpu::sisd::Column< S >, olb::cpu::sisd::Column< U >, olb::cpu::sisd::CyclicColumn< T >, olb::ConcreteBlockMask< T, Platform::CPU_SISD >, olb::gpu::cuda::Column< T >, olb::gpu::cuda::Column< CellID >, olb::gpu::cuda::Column< std::uint8_t >, olb::gpu::cuda::CyclicColumn< T >, olb::ConcreteParametersD< T, DESCRIPTOR, Platform::GPU_CUDA, PARAMETERS >, olb::ConcreteBlockMask< T, Platform::GPU_CUDA >, olb::SuperLattice< T, DESCRIPTOR >, olb::SuperLattice< S, descriptor >, olb::SuperLattice< T, Lattice >, olb::SuperLattice< T, TDESCRIPTOR >, olb::BlockGeometry< T, D >, olb::BlockGeometry< S, D >, olb::BlockGeometry< T, 2 >, olb::BlockGeometry< T, 3 >, olb::BlockGeometry< T, DESCRIPTOR::d >, olb::Cuboid3D< T >, olb::Cuboid3D< S >, olb::CuboidGeometry3D< T >, olb::SuperGeometry< T, D >, olb::SuperGeometry< S, D >, olb::SuperGeometry< S, dim >, olb::SuperGeometry< T, 2 >, olb::SuperGeometry< T, 3 >, and olb::SuperGeometry< T, DESCRIPTOR::d >.
bool olb::Serializable::load | ( | const std::uint8_t * | buffer | ) |
Load Serializable
from buffer of length getSerializableSize
Definition at line 164 of file serializer.hh.
References olb::Serializer::load().
bool olb::Serializable::load | ( | std::string | fileName = "", |
const bool | enforceUint = false ) |
Load Serializable
from file fileName
Definition at line 152 of file serializer.hh.
References olb::Serializer::load().
|
inlinevirtual |
Reimplemented in olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::CPU_SIMD >, olb::ConcreteBlockLattice< T, DESCRIPTOR, Platform::GPU_CUDA >, olb::ConcreteBlockLattice< T, DESCRIPTOR, SOURCE >, olb::ConcreteBlockLattice< T, DESCRIPTOR, TARGET >, olb::ColumnVector< COLUMN, D >, olb::ColumnVector< ImplementationOf< FIELD::template column_type< int >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< S >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< FIELD >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< NORMAL >()>, olb::ColumnVector< ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type, DESCRIPTOR::template size< olb::descriptors::MATERIAL >()>, olb::ColumnVector< olb::cpu::simd::Column< T >, D >, olb::ColumnVector< olb::cpu::sisd::Column< int >, 1 >, olb::cpu::simd::CyclicColumn< T >, olb::cpu::sisd::CyclicColumn< T >, olb::gpu::cuda::CyclicColumn< T >, olb::SuperLattice< T, DESCRIPTOR >, olb::SuperLattice< S, descriptor >, olb::SuperLattice< T, Lattice >, and olb::SuperLattice< T, TDESCRIPTOR >.
Definition at line 191 of file serializer.h.
|
inlineprotected |
Register Serializable
object of constant size.
This method is suitable for all Serializable
objects that are of constant size.
For information about the parameters of this method, see registerVar()
.
This method registers a Serializable
by simply delegating the getBlock()
call to the Serializable
.
Since those Serializable
objects must(!) have constant return value from Serializable.getNblock()
, the number of blocks is known both in reading and writing mode.
Note that DataType
must only provide Serializable
-equivalent methods and not necessarily inherit. E.g. Vector<T,D>
is serializable despite not being derived from Serializable
.
Definition at line 239 of file serializer.h.
|
inlineprotected |
Register an array of Serializable
objects of constant size.
This method is suitable for all Serializable
objects that are of constant size.
For information about the parameters of this method, see registerVar()
.
This method registers an array of Serializable
s by delegating the getBlock()
call to the corresponding Serializable
.
Since those Serializable
objects must(!) have constant return value from Serializable.getNblock()
, the number of blocks is known both in reading and writing mode.
Definition at line 261 of file serializer.h.
References getNblock().
|
inlineprotected |
Register primitive data types (int
, double
, ...) or arrays of those.
This method is suitable for all primitive data types or arrays of those. The address of the data is returned in combination with the size sizeof(DataType) * arrayLength
.
iBlock | iBlock from getBlock() - to determine if this is the current block. |
sizeBlock | sizeBlock from getBlock() - will be filled if this is the current block. |
currentBlock | local variable of getBlock() - will always be counted up by the number of blocks this method registers (always 1 in this case). |
dataPtr | dataPtr from getBlock() - will be filled with pointer to the data at iBlock if this is the current block. |
data | Reference to the data to be registered by this method. Fills dataPtr with a (bool*) -casted pointer to data if this is the current block. |
arrayLength | Number of elements of DataType in data , if data is an array. Defaults to 1 for single values. |
DataType | Type of data |
Definition at line 212 of file serializer.h.
bool olb::Serializable::save | ( | std::string | fileName = "", |
const bool | enforceUint = false ) |
Save Serializable
into file fileName
Definition at line 145 of file serializer.hh.
References olb::Serializer::save().
bool olb::Serializable::save | ( | std::uint8_t * | buffer | ) |
Save Serializable
into buffer of length getSerializableSize
Definition at line 158 of file serializer.hh.
References olb::Serializer::save().