1

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?

2
  • 2
    Please show us the segmentation fault backtrace ... Commented Nov 2, 2012 at 10:28
  • Remember that internally, std::vector will have a pointer to a chunk of memory that will lie outside of a Node instance. Commented Nov 2, 2012 at 12:22

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I will have to serialize my struct. I will do it into vector which I should send through MPI.
«You are sending non-POD data over MPI which is not correct» You mean that although sending a vector<int> works, it's not correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.