#include <stdio.h>
#include <string.h>
#include <mpi.h>
#include <ctime>
#include <cstdlib>
const int MAX_STRING = 100;
int main(void)
{
char gret[MAX_STRING];
int csize;
int prank;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &csize);
MPI_Comm_rank(MPI_COMM_WORLD, &prank);
std
::srand(static_cast
<unsigned int
>(std
::time(0)));
for(int i = 0; i < csize; i++){
int rand_num
= std
::rand() % 10; char temp[2];
sprintf(temp
, "%d%d", prank
, rand_num
); MPI_Send
(temp
, strlen(temp
) + 1, MPI_CHAR
, i
, 0, MPI_COMM_WORLD
); MPI_Recv(temp, 3, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
gret[temp[0]] = temp[0];
gret[temp[0]+1] = temp[1];
}
printf("Process %d recived:%s \n", prank
, gret
);
MPI_Finalize();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPG1waS5oPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxjc3RkbGliPgpjb25zdCBpbnQgTUFYX1NUUklORyA9IDEwMDsKaW50IG1haW4odm9pZCkKewogICAgY2hhciBncmV0W01BWF9TVFJJTkddOwogICAgaW50IGNzaXplOwogICAgaW50IHByYW5rOwogICAgTVBJX0luaXQoTlVMTCwgTlVMTCk7CiAgICBNUElfQ29tbV9zaXplKE1QSV9DT01NX1dPUkxELCAmY3NpemUpOwogICAgTVBJX0NvbW1fcmFuayhNUElfQ09NTV9XT1JMRCwgJnByYW5rKTsKICAgIHN0ZDo6c3JhbmQoc3RhdGljX2Nhc3Q8dW5zaWduZWQgaW50PihzdGQ6OnRpbWUoMCkpKTsKCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgY3NpemU7IGkrKyl7CiAgICAgICAgaW50IHJhbmRfbnVtID0gc3RkOjpyYW5kKCkgJSAxMDsKICAgICAgICBjaGFyIHRlbXBbMl07CiAgICAgICA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