Re: [Boost-users] mpi/serialization: broadcast function and the value argument
-----Original Message----- From: "Matthias Troyer" [troyer@phys.ethz.ch] Date: 13/12/2010 09:57 PM To: "Hicham Mouline" CC: boost-users@lists.boost.org Subject: Re: [Boost-users] mpi/serialization: broadcast function and the value argument
mpi::broadcast() appears to be incapable of sending the argument "value" in a polymorphic way, ie:
sender------------------- Base* base; If I call boost::mpi::broadcast(..., base, ...)
receiver----------------- Base* base; boost::mpi::broadcast(..., base, ...) This does not construct the most derived type of base on the heap and make base point there, as serialization would do.
Did you register the most derived type? Yes I have all types.
Did you test whether pointer deserialization works with other serialization archives? Matthias
I will test. However, this code from boost\mpi\collectives\broadcast.hpp (see where I put the comment marker) // We're sending a type that does not have an associated MPI // datatype, so we'll need to serialize it. Unfortunately, this // means that we cannot use MPI_Bcast, so we'll just send from the // root to everyone else. template<typename T> void broadcast_impl(const communicator& comm, T* values, int n, int root, mpl::false_) { if (comm.rank() == root) { packed_oarchive oa(comm); for (int i = 0; i < n; ++i) oa << values[i]; broadcast(comm, oa, root); } else { packed_iarchive ia(comm); broadcast(comm, ia, root); for (int i = 0; i < n; ++i) ia >> values[i]; /////////////////////////////////////////////////////////////////// } } template<typename T> void broadcast(const communicator& comm, T& value, int root) { detail::broadcast_impl(comm, &value, 1, root, is_mpi_datatype<T>()); } template<typename T> void broadcast(const communicator& comm, T* values, int n, int root) { detail::broadcast_impl(comm, values, n, root, is_mpi_datatype<T>()); } If at the receiver process, I pass a non initialized Base*, it crashes as far as I could see. PS: I've cc'ed the email in the comments for that file as well. regards,
On 14 Dec 2010, at 01:00, Hicham Mouline wrote:
-----Original Message----- From: "Matthias Troyer" [troyer@phys.ethz.ch] Date: 13/12/2010 09:57 PM To: "Hicham Mouline" CC: boost-users@lists.boost.org Subject: Re: [Boost-users] mpi/serialization: broadcast function and the value argument
mpi::broadcast() appears to be incapable of sending the argument "value" in a polymorphic way, ie:
sender------------------- Base* base; If I call boost::mpi::broadcast(..., base, ...)
receiver----------------- Base* base; boost::mpi::broadcast(..., base, ...) This does not construct the most derived type of base on the heap and make base point there, as serialization would do.
Did you register the most derived type? Yes I have all types.
Did you test whether pointer deserialization works with other serialization archives? Matthias
I will test.
This will be crucial. If it does not work with, e.g. text or binary archives then it will not work with serialization either. Matthias
-----Original Message----- From: Matthias Troyer [mailto:troyer@phys.ethz.ch] Sent: 14 December 2010 17:57 <snip>
mpi::broadcast() appears to be incapable of sending the argument
"value" in a polymorphic way, ie:
sender------------------- Base* base; If I call boost::mpi::broadcast(..., base, ...)
receiver----------------- Base* base; boost::mpi::broadcast(..., base, ...) This does not construct the most derived type of base on the heap
and make base point there, as serialization would do.
Did you register the most derived type? Yes I have all types.
Did you test whether pointer deserialization works with other serialization archives? Matthias
I will test.
This will be crucial. If it does not work with, e.g. text or binary archives then it will not work with serialization either.
Matthias
The attached works with serialization. I've also tested with the classes in my real case. However, looking at the implementation of mpi::broadcast, the receiver uses the "value" passed to it to store what it received. If value is a Base* that is not initialized, value[0], in particular, is used and that will never work, see mpi/collectives/broadcast.hpp line 48 ia >> values[i] Am i interpreting this incorrectly? Regards,
-----Original Message----- From: Matthias Troyer [mailto:troyer@phys.ethz.ch] Sent: 14 December 2010 17:57
This will be crucial. If it does not work with, e.g. text or binary archives then it will not work with serialization either.
Matthias
Apologies for forgotten attachment.
-----Original Message----- From: Matthias Troyer [mailto:troyer@phys.ethz.ch] Sent: 14 December 2010 17:57 <snip>
This will be crucial. If it does not work with, e.g. text or binary archives then it will not work with serialization either.
Matthias
Hello, Confirmed twice. It does work with boost.serialization, but throws an exception with mpi::broadcast() /// receiver Base* bptr=0; mpi::broadcast(world, bptr, 0); This throws an exception. See attached for the call stack. derived is a class inherits from base. somehow it tries to read something into the length of a string, but that number if very large. That is just nonsendse. regards,
participants (2)
-
Hicham Mouline
-
Matthias Troyer