Libraraies about cpp object serilization in distrirbuted communication.
Discuss one exmaple library about cpp serilization and unserilization
Unlike the golang or java that provide the official serilization and decirilization libraray, we may need to use the third part library for the object serilization and decirilization. One example library that we want to introduce is this library: cereal (https://github.com/USCiLab/cereal). There are detailed documents about how to use this library. We just put an small example here to show some ideas about this library.
Cereal
Just like many convenient cpp tool libraray, we only need to include the header file in order to use the cereal.
you may need to use stringstream to transfer the marshaled data into a string
you also need to add an public template function in the defination of the object in order to use the cereal
When we check the size of the object
serilized size 4508 original size 112 ifequal 1 major ariables m_width 8, m_extents 24, m_origin 24, stackVar 108 heapVar 4448
You could see that the serilized size contains both the stack variable and the heap variable. The sizeof only caculate the stack varaible, that is why the size of the object is 112
DIY
The diy library is maintained by kitware, that is desinged for executing the visualization algorithm in an distributed manner. Talking about the distributed things, we need to send data object back and forth and also includes different types of data communication patterns.
The memory buffer of the diy is easy to undersdand, just a simple vector<char> which is supposed to store the serialized data. Assuming the buffer is a file, It use the position to store the current location of current offset of the memory buffer.
This is an exmaple of data serilization and deseriliazation, remember to reset the position before deserialize the data set.
The difficult thing is all kinds of communication pattern. Instead of using the MPI direactly, it provides all kinds of high level concepts to facilitate the communition in the context of the scientific visualization.
To use DIY, you have to create a Masterobject, set up block neighbors, enqueue objects to send, exchange the data, and then dequeue the objects.
enqueue and dequeue can be viewed as process to put the data into the send queue and recieve queue for memory managed by the