program example7 include 'mpif.h' integer rank, ierr, ibuf, status(MPI_STATUS_SIZE) real rbuf call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) ibuf = rank rbuf = 1.0 * rank if(rank .eq. 1) call MPI_SEND(ibuf, 1, MPI_INTEGER, 0, 5, & MPI_COMM_WORLD, ierr) if(rank .eq. 2) call MPI_SEND(rbuf, 1, MPI_REAL, 0, 5, & MPI_COMM_WORLD, ierr) if(rank .eq. 0) then call MPI_PROBE(MPI_ANY_SOURCE, 5, MPI_COMM_WORLD, & status, ierr) if(status(MPI_SOURCE) .EQ. 1) then call MPI_RECV(ibuf, 1, MPI_INTEGER, 1, 5, & MPI_COMM_WORLD, status, ierr) call MPI_RECV(rbuf, 1, MPI_REAL, 2, 5, & MPI_COMM_WORLD, status, ierr) else if(status(MPI_SOURCE) .EQ. 2) then call MPI_RECV(rbuf, 1, MPI_REAL, 2, 5, & MPI_COMM_WORLD, status, ierr) call MPI_RECV(ibuf, 1, MPI_INTEGER, 1, 5, & MPI_COMM_WORLD, status, ierr) end if end if print *, 'Process 0 recv ', ibuf, ' from process 1, ', & rbuf, ' from process 2' end if call MPI_FINALIZE(ierr) end