How can I transmit instances of my class or a std::vector using MPI_Send() or MPI_Bcast() in C++?
You cannot simply transmit instances of random classes since being C calls neither MPI_Send() nor MPI_Bcast() understand the structure of those classes. You can send instances of std::vector (since it uses contiguous memory storage) by providing &vector[0] to MPI_Send() but the receive operation should then be implemented in several steps: MPI_Probe() -> get the number of elements in the message -> resize the vector instance -> MPI_Recv() into the resized instance. For all other cases, you should use something like Boost.MPI or you should use MPI_Pack() and MPI_Unpack() to serialise and deserialise your class instances to and from MPI messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With