Let say I have a class named Node which makes the Node with x and y coordinate. Then I make a vector of objects from set of Node. now I want to send this vector of Node with its all properties to another processor.
I tried MPI_Send and it doesn't work in this case. how can I send a vector of objects in MPI?
This is the vector of Node;
I would assume whatever you send can't have pointers, since the receiving end might not be on the same process or even the same computer. So you'd need to serialize your data structure. For example, this:
1 2 3 4 5 6 7 8 9 10
std::vector<int *> data_structure;
int *one = newint(42);
int *two = newint(37);
int *three = newint(1024);
send(&data_structure, data_structure.size() * sizeof(int *)); //wrong
would have to be turned into this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
auto a = ints.size() * sizeof(int);
auto b = offsets.size() * sizeof(size_t);
buffer.resize(a + b);
memcpy(&buffer, &ints, a);
memcpy(&buffer[a], &offsetse, b);
You could also use a data exchange format such as JSON:
Plain Old Data (POD) means a simple struct or class with no embedded pointers or complex types. i.e. It may not contain for example a std::string, std::vector or other type which manages it's own memory.