include "mpiSim.f90" PROGRAM simple_deadlock include "useSim.f90" ! INCLUDE 'mpif.h' ! ! This example is from: ! "Introduction to MPI" – created by the PACS Training Group ! Note that mpiSim does not detect deadlock occurring in this example. ! This code does in fact deadlock when run with a real MPI library. ! The correct code for this example is: nodeadlock_ex.f90 ! INTEGER myrank, ierr, status(MPI_STATUS_SIZE) REAL a(100), b(100) a=3 b=4 ! Initialize MPI: call MPI_INIT(ierr) ! Get my rank: call MPI_COMM_RANK(MPI_COMM_WORLD, myrank, ierr) ! "Deadlock occurs when 2 (or more) processes are blocked and each is ! waiting for the other to make progress. Neither process makes ! progress because each depends on the other to make progress first." ! Process 1 receives and sends; same for process 1 if( myrank.eq.0 )then call MPI_RECV( b, 100, MPI_REAL, 1, 19, MPI_COMM_WORLD, status, ierr ) call MPI_SEND( a, 100, MPI_REAL, 1, 17, MPI_COMM_WORLD, ierr) else if ( myrank.eq.1 )then call MPI_RECV( b, 100, MPI_REAL, 0, 17, MPI_COMM_WORLD, status, ierr ) call MPI_SEND( a, 100, MPI_REAL, 0, 19, MPI_COMM_WORLD, ierr) endif ! Wrap Up. call MPI_FINALIZE(ierr) write(*,*) "Simple deadlock example all done." end program simple_deadlock