1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
if (rank == 0) {
dest = 1;//‘dest’ means rank of destination
source = 1;
MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
MPI_Recv(&inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
}
// task 1 waits for task 0 message then returns a message
else if (rank == 1) {
dest = 0;
source = 0;
MPI_Recv(&inmsg, 1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
}
| |