#include <stdlib.h>
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[])
{
int x, y, np, id;
int tag = 42;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &np);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
if (id == 0)
{
printf("We have %d processes \n", np
); x=5;
printf("Process %d sending to process 1\n", id
); printf("Process %d sent %d to process 1\n", id
, x
); MPI_Send(&x, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
}
else
{ /* id == 1 */
printf("Process %d receiving from process 0\n", id
); MPI_Recv (&y, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
printf("Process %d received %d form process 0\n", id
, y
); }
MPI_Finalize();
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgIm1waS5oIgppbnQgbWFpbihpbnQgYXJnYywgY2hhciogYXJndltdKQp7CiAgIGludCB4LCB5LCBucCwgaWQ7CiAgIGludCB0YWcgPSA0MjsKICAgTVBJX1N0YXR1cyBzdGF0dXM7CiAgIE1QSV9Jbml0KCZhcmdjLCAmYXJndik7CiAgIE1QSV9Db21tX3NpemUoTVBJX0NPTU1fV09STEQsICZucCk7CiAgIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZpZCk7CiAgIGlmIChpZCA9PSAwKSAKICB7CiAgICAgIHByaW50ZigiV2UgaGF2ZSAlZCAgcHJvY2Vzc2VzIFxuIiwgbnApOwogICAgICB4PTU7CiAgICAgIHByaW50ZigiUHJvY2VzcyAlZCBzZW5kaW5nIHRvIHByb2Nlc3MgMVxuIiwgaWQpOyAgCiAgICAgIHByaW50ZigiUHJvY2VzcyAlZCBzZW50ICVkIHRvIHByb2Nlc3MgMVxuIiwgaWQsIHgpOyAKICAgICBNUElfU2VuZCgmeCwgMSwgTVBJX0lOVCwgMSwgdGFnLCBNUElfQ09NTV9XT1JMRCk7CiB9IAplbHNlIAp7IC8qIGlkID09IDEgKi8KICAgICBwcmludGYoIlByb2Nlc3MgJWQgcmVjZWl2aW5nIGZyb20gcHJvY2VzcyAwXG4iLCBpZCk7ICAgIAogICAgIE1QSV9SZWN2ICgmeSwgMSwgTVBJX0lOVCwgMCwgdGFnLCBNUElfQ09NTV9XT1JMRCwgJnN0YXR1cyk7CiAgICAgcHJpbnRmKCJQcm9jZXNzICVkIHJlY2VpdmVkICVkIGZvcm0gcHJvY2VzcyAwXG4iLCBpZCwgeSk7IAogICAgIHByaW50ZigiUmVzdWx0PSAlZCBcbiIseSoyKTsgICAgCn0KICBNUElfRmluYWxpemUoKTsKICBleGl0KDApOwp9