1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include "stdio.h"
#include <windows.h>
#include "mpi.h"
int main(int argc, char* argv[])
{
int ProcNum1, ProcRank1;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum1);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank1);
if (ProcRank1 == 0)
{
printf("Process %3d are receiving messages\n", ProcRank1);
for (int i = 1; i < ProcNum1; i++)
{
int RecvRank1;
MPI_Status Status;
MPI_Recv(&RecvRank1, 1, MPI_INT, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
printf("Message from process: %3d\n", RecvRank1);
}
}
else
{
printf("Process %3d are sending message\n", ProcRank1);
MPI_Send(&ProcRank1, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
|