C /* C * The proc 0 and proc 1 send to proc 2 separately, C * proc 2 call MPI_PROBE to know whether the messages come, C * if so, it calls MPI_RECV to receive the messages C * Compile: mpif77 mpi_probe01.f -o mpi_probe01 C * Run: mpirun -np 3 mpi_probe01 C */ program main include 'mpif.h' integer rank, tag integer ierr, n, i real x integer status(MPI_STATUS_SIZE) tag = 0 CALL MPI_INIT(ierr) CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) IF (rank.EQ.0) THEN print *, 'Proc 0: Sleep for 5 sec before send...' CALL SLEEP(5) print *, 'Proc 0: Sending message...' CALL MPI_SEND(i, 1, MPI_INTEGER, 2, tag, MPI_COMM_WORLD, ierr) ELSE IF(rank.EQ.1) THEN print *, 'Proc 1: Sleep for 3 sec before send...' CALL SLEEP(3) print *, 'Proc 1: Sending message...' CALL MPI_SEND(x, 1, MPI_REAL, 2, tag, MPI_COMM_WORLD, ierr) ELSE ! rank.EQ.2 DO n=1, 2 print *, 'Proc 2: Wait for message comes...' CALL MPI_PROBE(MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, status, ierr) print *, 'Proc 2: New message...' IF (status(MPI_SOURCE) .EQ. 0) THEN CALL MPI_RECV(i, 1, MPI_INTEGER, 0, tag, MPI_COMM_WORLD, status, ierr) ELSE CALL MPI_RECV(x, 1, MPI_REAL, 1, tag, MPI_COMM_WORLD, status, ierr) END IF print *, 'Proc 2: Received message from Proc ',status(MPI_SOURCE),' successfully!!' END DO END IF call MPI_FINALIZE(ierr) end