Reputation: 683
I'm trying to send this structure through MPI, but I don't know if that's right.
struct Node {
int sum_node;
int depth_node;
vector<vector<int> > subset;
vector<int> sum_subset;
vector<int> depth_subset;
};
Sending like this:
Node zz = stack.back();
stack.pop_back();
MPI_Send(&zz, sizeof(struct Node), MPI_BYTE, 1, MSG_WORK_SENT, MPI_COMM_WORLD);
Receiving like this:
Node gg;
MPI_Recv(&gg, sizeof(struct Node), MPI_BYTE, status.MPI_SOURCE, MSG_WORK_SENT, MPI_COMM_WORLD, &status);
stack.push_back(gg);
And program terminated with Segmentation fault. Can anyone help me, please?
Upvotes: 1
Views: 1704
Reputation: 45410
You are sending non-POD data over MPI which is not correct. You need to serialize/deserialize the whole Node during send/receive work.
For example, if I have a node and I have 1000 elements in its sum_subset, now you only send sizeof(Node) over:
Node d;
for(int i=0;i<1000;i++)
{
d.sum_subset.push_back(1);
}
cout << sizeof(Node) << endl;
checkout http://www.boost.org/doc/libs/1_51_0/libs/serialization/doc/index.html for more information
Upvotes: 4