Re: [Boost-users] mpi: sending/receiving different types
The way we do this is send a special message saying that a broadcast will be sent next. Brian
probe() checks only for messages sent by send(), not by broadcast(). Matthias
Thanks, I spend most of my time broadcasting, and sometimes sending.... I guess that means in the slave processes: . use mpi::broadcast() . if the received value is a signal that a send() to me will be issued next, then I'll recv() About the broadcast() function, I obviously have many types of messages to send, would you rather: 1. send a broadcast with just an int (like a tag) to tell which broadcast is following next or 2. construct a virtual base class my_mpi_broadcast , derive all the sendable broadcasts from it, from sender, send actual instance of derived from my_mpi_broadcast, and at receiver, can the mechanism reconstruct for me the derived class? (with boost::serialization) Is 2 doable at all? If so, pros/cons regards,
On Mon, Dec 6, 2010 at 6:01 PM, Hicham Mouline
About the broadcast() function, I obviously have many types of messages to send, would you rather:
1. send a broadcast with just an int (like a tag) to tell which broadcast is following next
or
2. construct a virtual base class my_mpi_broadcast , derive all the sendable broadcasts from it, from sender, send actual instance of derived from my_mpi_broadcast, and at receiver, can the mechanism reconstruct for me the derived class? (with boost::serialization)
I'm not sure I understand this question: mpi::broadcast() works like a send+recv in one call: one MPI rank (the *root*) sends, the others receive. Any data that is allowed in send() can be used in a broadcast(); in particular, if you have classes with Serialization support, you send() or broadcast() them with no additional effort. Best regards, Riccardo
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Riccardo Murri Sent: 07 December 2010 08:20 To: boost-users@lists.boost.org Subject: Re: [Boost-users] mpi: sending/receiving different types
On Mon, Dec 6, 2010 at 6:01 PM, Hicham Mouline
wrote: About the broadcast() function, I obviously have many types of messages to send, would you rather:
1. send a broadcast with just an int (like a tag) to tell which broadcast is following next
or
2. construct a virtual base class my_mpi_broadcast , derive all the sendable broadcasts from it, from sender, send actual instance of derived from my_mpi_broadcast, and at receiver, can the mechanism reconstruct for me the derived class? (with boost::serialization)
I'm not sure I understand this question: mpi::broadcast() works like a send+recv in one call: one MPI rank (the *root*) sends, the others receive.
Any data that is allowed in send() can be used in a broadcast(); in particular, if you have classes with Serialization support, you send() or broadcast() them with no additional effort.
Best regards, Riccardo _______________________________________________ Hello
During a sequence of communication, the slave processes don't know what type to get broadcast of, next. What should be the T in the call to broadcast. 1. the root sends a tag for the T to tell the receivers I will broadcast you this and this. This means 2 broadcast each time 2. the root sends directly a reference to a base class of anything sendable, then the receivers construct the derived classes on reception with broadcast. The T is then the base class type. 3. I just thought of using boost::variant<> over all the possible types. rds,
Hi Hicham,
now I see your problem...
On Tue, Dec 7, 2010 at 9:41 AM, Hicham Mouline
During a sequence of communication, the slave processes don't know what type to get broadcast of, next. What should be the T in the call to broadcast.
1. the root sends a tag for the T to tell the receivers I will broadcast you this and this. This means 2 broadcast each time
Safe and easy option. Could be the slowest if you plan broadcasting a lot of messages and/or running on a large number of ranks.
2. the root sends directly a reference to a base class of anything sendable, then the receivers construct the derived classes on reception with broadcast. The T is then the base class type.
There's a risk of slicing here, i.e., if you pass a reference to a base class, only the base class data will be serialized and received. As far as I understand, Boost.Serialization (hence Boost.MPI) will do the correct thing if you use *pointers* instead: i.e., you send a pointer to a (derived) class and you receive it through a pointer to the base class. (Beware: I have not checked!)
3. I just thought of using boost::variant<> over all the possible types.
Should work, provided you #include
Hi Hicham,
On Wed, Dec 8, 2010 at 2:50 PM, Riccardo Murri
2. the root sends directly a reference to a base class of anything sendable, then the receivers construct the derived classes on reception with broadcast. The T is then the base class type.
There's a risk of slicing here, i.e., if you pass a reference to a base class, only the base class data will be serialized and received.
As far as I understand, Boost.Serialization (hence Boost.MPI) will do the correct thing if you use *pointers* instead: i.e., you send a pointer to a (derived) class and you receive it through a pointer to the base class.
(Beware: I have not checked!)
Now I actually tried and could not get this to work; the main problem is that the mpi::broadcast expects an already-built object to call the (de)serialization procedure on, irrespective of whether the object was passed as a pointer or as a reference.
3. I just thought of using boost::variant<> over all the possible types.
I think this is the way to go; I'm attaching a sample program. Not sure this is exactly what you need, but could be enough to get you started. Best regards, Riccardo
participants (2)
-
Hicham Mouline
-
Riccardo Murri