C /* C * Illustrate the usage of MPI_SEND_RECV C * All the proc send message to the next proc simultaneously, C * and then receive message from the previous proc C */ program main include 'mpif.h' integer rank, tag integer ierr, nproc, dest integer sendbuf(1), recvbuf(1) integer status(MPI_STATUS_SIZE) tag = 0 CALL MPI_INIT(ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr) dest = MOD ((rank + 1), nproc) print *, 'Proc ', rank, ': Sending message to ', dest, '...' IF (rank.EQ.0) THEN CALL MPI_SENDRECV(sendbuf, 1, MPI_INTEGER, dest, tag, recvbuf, 1, MPI_INTEGER, nproc - 1, tag, MPI_COMM_WORLD, status, ierr); ELSE CALL MPI_SENDRECV(sendbuf, 1, MPI_INTEGER, dest, tag, recvbuf, 1, MPI_INTEGER, rank - 1, tag, MPI_COMM_WORLD, status, ierr); END IF print *, 'Proc ', rank, ': Receive message from ', status(MPI_SOURCE), '...' call MPI_FINALIZE(ierr) end