Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending class instances using MPI_Send() or MPI_Bcast in C++

Tags:

mpi

How can I transmit instances of my class or a std::vector using MPI_Send() or MPI_Bcast() in C++?

like image 384
Marcinho Avatar asked Mar 20 '23 16:03

Marcinho


1 Answers

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.

like image 56
Hristo Iliev Avatar answered Apr 28 '23 12:04

Hristo Iliev