#include <stdio.h>
#include <mpi.h>
#include <string.h>
#define BUFFER_SIZE 32
int main(int argc,char *argv[])
{
int MyRank,Numprocs, Destination, iproc;
int tag = 0;
int Root = 0, temp = 1;
char Message[BUFFER_SIZE];
MPI_Init(&argc,&argv);
MPI_Status status;
MPI_Comm_rank(MPI_COMM_WORLD,&MyRank);
MPI_Comm_size(MPI_COMM_WORLD,&Numprocs);
/* print host name, and send message from process with rank 0 to all other processes */
if(MyRank == 0) {
strcpy(Message
, "Hello India"); for (temp=1; temp<Numprocs;temp++)
{
MPI_Send(Message, BUFFER_SIZE, MPI_CHAR, temp,
tag,MPI_COMM_WORLD);
}
}
else
{
MPI_Recv(Message, BUFFER_SIZE, MPI_CHAR, Root,
tag,MPI_COMM_WORLD, &status);
printf("\n%s in process with rank %d from Process with rank %d\n", Message,MyRank,Root);
}
MPI_Finalize();
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtcGkuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojZGVmaW5lIEJVRkZFUl9TSVpFIDMyCmludCBtYWluKGludCBhcmdjLGNoYXIgKmFyZ3ZbXSkKewppbnQgTXlSYW5rLE51bXByb2NzLCBEZXN0aW5hdGlvbiwgaXByb2M7CmludCB0YWcgPSAwOwppbnQgUm9vdCA9IDAsIHRlbXAgPSAxOwpjaGFyIE1lc3NhZ2VbQlVGRkVSX1NJWkVdOwogTVBJX0luaXQoJmFyZ2MsJmFyZ3YpOwogTVBJX1N0YXR1cyBzdGF0dXM7CiBNUElfQ29tbV9yYW5rKE1QSV9DT01NX1dPUkxELCZNeVJhbmspOwogTVBJX0NvbW1fc2l6ZShNUElfQ09NTV9XT1JMRCwmTnVtcHJvY3MpOwovKiBwcmludCBob3N0IG5hbWUsIGFuZCBzZW5kIG1lc3NhZ2UgZnJvbSBwcm9jZXNzIHdpdGggcmFuayAwIHRvIGFsbCBvdGhlciBwcm9jZXNzZXMgKi8KaWYoTXlSYW5rID09IDApIHsKIHN5c3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