#include <iostream>
#include <mpi.h>
int main(int argc, char** argv) {
int world_rank;
int world_size;
int data = 0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
if (world_rank == 0) {
data = 42;
MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if (world_rank == 1) {
MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
if (world_rank == 1) {
std::cout << "Process " << world_rank << " received: " << data << std::endl;
}
MPI_Finalize();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bXBpLmg+CgppbnQgbWFpbihpbnQgYXJnYywgY2hhcioqIGFyZ3YpIHsKICAgIGludCB3b3JsZF9yYW5rOwogICAgaW50IHdvcmxkX3NpemU7CiAgICBpbnQgZGF0YSA9IDA7CgogICAgTVBJX0luaXQoJmFyZ2MsICZhcmd2KTsKICAgIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZ3b3JsZF9yYW5rKTsKICAgIE1QSV9Db21tX3NpemUoTVBJX0NPTU1fV09STEQsICZ3b3JsZF9zaXplKTsKCiAgICBpZiAod29ybGRfcmFuayA9PSAwKSB7CiAgICAgICAgZGF0YSA9IDQyOwogICAgICAgIE1QSV9TZW5kKCZkYXRhLCAxLCBNUElfSU5ULCAxLCAwLCBNUElfQ09NTV9XT1JMRCk7CiAgICB9CiAgICBlbHNlIGlmICh3b3JsZF9yYW5rID09IDEpIHsKICAgICAgICBNUElfUmVjdigmZGF0YSwgMSwgTVBJX0lOVCwgMCwgMCwgTVBJX0NPTU1fV09STEQsIE1QSV9TVEFUVVNfSUdOT1JFKTsKICAgIH0KCiAgICBpZiAod29ybGRfcmFuayA9PSAxKSB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJQcm9jZXNzICIgPDwgd29ybGRfcmFuayA8PCAiIHJlY2VpdmVkOiAiIDw8IGRhdGEgPDwgc3RkOjplbmRsOwogICAgfQoKICAgIE1QSV9GaW5hbGl6ZSgpOwogICAgcmV0dXJuIDA7Cn0=