#include<stdio.h>
#include "mpi.h"
#include<string.h>
main(int argc, char **argv)
{
int MyRank, Numprocs, tag, ierror, i;
MPI_Status status;
char send_message[20], recv_message[20];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &Numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &MyRank);
tag=100;
strcpy(send_message
, "Hello-Participants"); if (MyRank==0)
{
for(i=1;i<Numprocs;i++)
{
MPI_Recv(recv_message,20,MPI_CHAR,i,tag,MPI_COMM_WORLD,&status);
printf("node %d : %s \n",i
,recv_message
); }
}
else
MPI_Send(send_message,20,MPI_CHAR,0,tag,MPI_COMM_WORLD);
MPI_Finalize();
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGUgIm1waS5oIgojaW5jbHVkZTxzdHJpbmcuaD4KbWFpbihpbnQgYXJnYywgY2hhciAqKmFyZ3YpCnsKICAgIGludCBNeVJhbmssIE51bXByb2NzLCB0YWcsIGllcnJvciwgaTsKICAgIE1QSV9TdGF0dXMgc3RhdHVzOwogICAgY2hhciBzZW5kX21lc3NhZ2VbMjBdLCByZWN2X21lc3NhZ2VbMjBdOwogICAgTVBJX0luaXQoJmFyZ2MsICZhcmd2KTsKICAgIE1QSV9Db21tX3NpemUoTVBJX0NPTU1fV09STEQsICZOdW1wcm9jcyk7CiAgICBNUElfQ29tbV9yYW5rKE1QSV9DT01NX1dPUkxELCAmTXlSYW5rKTsKICAgIHRhZz0xMDA7CiAgICBzdHJjcHkoc2VuZF9tZXNzYWdlLCAiSGVsbG8tUGFydGljaXBhbnRzIik7CiAgICBpZiAoTXlSYW5rPT0wKQogICAgewogICAgICAgIGZvcihpPTE7aTxOdW1wcm9jcztpKyspCiAgICAgICAgewogICAgICAgICAgICBNUElfUmVjdihyZWN2X21lc3NhZ2UsMjAsTVBJX0NIQVIsaSx0YWcsTVBJX0NPTU1fV09STEQsJnN0YXR1cyk7CiAgICAgICAgICAgIHByaW50Zigibm9kZSAlZCA6ICVzIFxuIixpLHJlY3ZfbWVzc2FnZSk7CiAgICAgICAgfQogICAgfQogICAgZWxzZQogICAgICAgIE1QSV9TZW5kKHNlbmRfbWVzc2FnZSwyMCxNUElfQ0hBUiwwLHRhZyxNUElfQ09NTV9XT1JMRCk7CiAgICBNUElfRmluYWxpemUoKTsKfQ==