Reputation: 592
Is it possible to send/receive C++ object and object arrays using MPI_Bcast, MPI_Scatter and MPI_Gather. If yes then which MPI datatype is used for objects? For example I have a class named cell.
class cell
{
private:
int abc;
double xyz;
public:
cell(){ }
...
};
In the main function, I would like to make an object array of class cell and would like to send/receive as object array. e.g.,
void main ()
{
...
cell** cells = new cell*[someVar];
for(int i = 0; i < someVar; ++i)
{
cells[i] = new cell[someVar];
}
MPI_Bcast(cells, someVar, ???, 0, MPI_COMM_WORLD);
...
}
How can we define an MPI data type to send / receive an object array?
Upvotes: 1
Views: 1995
Reputation: 5794
Check out the MPI_Pack / MPI_Unpack mechanism. On the sending side you stuff the elements into a pack buffer and you send that; the receiving side unpacks it component-by-component. This offers such cute possibilities as first unpacking an integer that tells you how many subsequent doubles there are to unpack. A big advantage of this approach is that it applies to objects that are only indirectly accessible through an iterator or such.
Upvotes: 1