I'm using Boost.MPI to exchange messages between processes. Each message carries one of my classes, serialized using Boost.Serialization. I also use the same serialization code to save that class to a file. What I need to send over MPI is smaller than what I need to save to a file (fewer relevant members). I was thinking that it would be nice to use the class versioning, supported by the Serialization library, to tell Boost.MPI to send the non-default version of the class, but I can't seem to find a way to do so. Do you know if this is possible?
Asked
Active
Viewed 287 times
1 Answers
2
It is not possible to serialize two different versions of the same type in the same binary module. The reason is that the version used is a compile time constant specified using the BOOST_CLASS_VERSION
construct (the version number defaults to zero if not specified).
What you could try is to implement specializations of the serialization member function for your type for specific archive types:
// generic overload, used for everything except the MPI archives
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
// do 'normal' (file-based) serialization
}
// overload for MPI archive used while deserialization
void serialize(boost::mpi::packed_iarchive& ar, const unsigned int version)
{
// do MPI deserialization
}
// overload for MPI archive used while serialization
void serialize(boost::mpi::packed_oarchive& ar, const unsigned int version)
{
// do MPI serialization
}
Similarily, you could provide overloads when using the split load/save serialization functions.

hkaiser
- 11,403
- 1
- 30
- 35
-
Oh, I see. I've misunderstood how one uses the version parameter. If I understand you (and the documentation) right, one can use it to read older versions of the class, but the version one can save is fixed at compile time. Is this correct? In any case, I like your solution to my problem very much -- it's much cleaner than what I had in mind. Thanks for your answer! – foxcub Apr 17 '11 at 04:11