Boost MPI Serialization : Sending serialized array of user defined classes

I want to send my Array class using boost Mpi template<class T> class Array { private: int size; T* data; public: // constructors + other stuff }; Here T can be any built in type or user defined type. Suppose I have a class complex struct complex { std::vector<double> real_imag; // contain two elements }; How can I send Array<complex> using Boost::Mpi + serialization. Thanks in anticipation Regards Noman

Hi Noman, Do you just want to know how it can be done or what would be needed to make it efficient? To just make it work, all you have to do is write serialize functions for your Array class and your complex struct. To make it efficient there are two considerations: 1.) it is very inefficient to store your complex numbers as a std::vector - each complex number will require a dynamic allocation. Why don't you just use std::complex or implement real_imag as a fixed-size array of length 2. 2.) to make array serialization of built in types and some of your own structs efficient you need to use array wrappers when you serialize your Array class. 3.) consider using the skeleton&contents mechanism if you need to send your array often and only the contents but not the size of the array change I hope this helps Matthias On 3 Jun 2010, at 12:13, Noman Javed wrote:
I want to send my Array class using boost Mpi
template<class T> class Array { private: int size; T* data; public: // constructors + other stuff };
Here T can be any built in type or user defined type. Suppose I have a class complex
struct complex { std::vector<double> real_imag; // contain two elements };
How can I send Array<complex> using Boost::Mpi + serialization.
Thanks in anticipation Regards Noman
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Matthias Troyer
Hi Noman,
Do you just want to know how it can be done or what would be needed to make it
efficient?
Both
To just make it work, all you have to do is write serialize functions for your Array class and your complex struct.
Is it some specialized serialize function for array class or its the same as we normally write for boost serialization?
To make it efficient there are two considerations:
1.) it is very inefficient to store your complex numbers as a std::vector - each complex number will require a dynamic allocation. Why don't you just use std::complex or implement real_imag as a fixed-size array of length 2.
I have used complex here just as an example. Infact it can be any user defined struct/class containing anything
2.) to make array serialization of built in types and some of your own structs efficient you need to use array wrappers when you serialize your Array class.
3.) consider using the skeleton&contents mechanism if you need to send your array often and only the contents but not the size of the array change
Can you give me some pointer about skeleton&contents mechanism and array wrappers
I hope this helps
Matthias
Thanks Noman
_______________________________________________ Boost-users mailing list Boost-users <at> lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 3 Jun 2010, at 21:59, Noman Javed wrote:
Matthias Troyer
writes: To just make it work, all you have to do is write serialize functions for your Array class and your complex struct.
Is it some specialized serialize function for array class or its the same as we normally write for boost serialization?
It uses the serialization library, and hence you don't need to do more than you normally do for serialization.
2.) to make array serialization of built in types and some of your own structs efficient you need to use array wrappers when you serialize your Array class.
3.) consider using the skeleton&contents mechanism if you need to send your array often and only the contents but not the size of the array change
Can you give me some pointer about skeleton&contents mechanism and array wrappers
http://www.boost.org/doc/libs/1_43_0/libs/serialization/doc/wrappers.html http://www.boost.org/doc/libs/1_43_0/doc/html/mpi/tutorial.html#mpi.skeleton... Matthias
participants (2)
-
Matthias Troyer
-
Noman Javed