Reputation: 397
I am trying to send some MPI messages to a process using boost library. However, the receiver side cannot receive them properly. The receiver gets only NULL, instead of the real messages. My code is here:
// Receiver side, rank = 0
boost::mpi::communicator* world
// initialization of the world, etc...
map<int, string> messageMap;
map<int, boost::mpi::request> requestMap;
for(int j=1; j<world->size(); j++){
requestMap[j] = world->irecv(j, 0, messageMap[j]);
}
for(typename map<int, boost::mpi::request>::iterator it = requestMap.begin(); it != requestMap.end(); it++){
it->second.wait();
cout << "Received message from " << j << " is: " << messageMap[j] << endl;
}
// Sender side, ranks = 1, 2 and 3
boost::mpi::communicator* world
// initialization of the world, etc...
world->isend(0, 0, "1");
Now, the problem is that receiver's output is similar to this:
Received message from 1 is: NULNUL
Received message from 2 is: NULNUL
Received message from 3 is: NULNUL
I could not figure out what the problem is.
Upvotes: 1
Views: 342
Reputation: 920
Your problem is in the underlying boost::serialization
.
In your question you send a string literal "1" which has the C++ type const char[2]
. boost::serialization
serializes this as an array of size 2 (and NOT as a std::string
). The receive then fails because boost::mpi
tries to deserialize the array as a std::string
and silently fails by returning null.
The solution, as you already figured out, is to send and receive the same type. In this case a std::string
.
Upvotes: 1
Reputation: 397
I do not know why, but it is fixed when I change the sender side like this:
// Sender side, ranks = 1, 2 and 3
boost::mpi::communicator* world
// initialization of the world, etc...
string s = "1";
world->isend(0, 0, s);
Upvotes: 0