Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialization without Boost.Serialization

I'm trying to implement a simple serialization/deserialization method for my code to be able to pass an object over the network using MPI. In an ideal world I would have used Boost.Serialization and Boost.MPI for that but they are not installed on some of the clusters I have access to so I'm considering doing this myself.

My strategy is to serialize every object into a std::stringstream object and then send a message via MPI_Send using MPI_CHAR as the datatype. In such a case I would pass std::stringstream::str()::c_str() as the pointer and std::streaingstream::str()::size()*sizeof(char) as the size of the message.

I've figured how to serialize everything into a std::stringstream object. My deserialization method also takes a std::stringstream object and deserializes everything back. This works fine except I do not know how to create a std::stringstream object from an array of chars and avoid the extra copy from the array into the stream. Should I change my deserialization method to directly work with an array of char using memcpy instead?

like image 684
mmirzadeh Avatar asked Nov 04 '22 18:11

mmirzadeh


1 Answers

The MPI way of doing this, would be using MPI_Pack and MPI_Unpack. Of course that is C and might not be as convenient as something using C++ features. For a simple example see http://www.mcs.anl.gov/research/projects/mpi/tutorial/mpiexmpl/src/bcast/C/pack/solution.html

like image 130
Zulan Avatar answered Nov 09 '22 16:11

Zulan