/* * example for send and recv */ #include #include int main(int argc, char *argv[]) { int myid, np, src, dest; double a, b; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &np); a = (double)myid; printf("Before communication: Process %d: a=%.2f\n", myid, a); src=myid-1; if (src==-1) src=np-1; dest=myid+1; if (dest==np) dest=0; MPI_Sendrecv(&a, 1, MPI_DOUBLE, dest, 111, &b, 1, MPI_DOUBLE, src, 111, MPI_COMM_WORLD, &status); printf("After communication: Process %d: b=%.2f\n", myid, b); MPI_Finalize(); return 0; }