program main !---Testing wether messages are buffered on the current platform. ! (if messages are NOT buffered this program will deadlock) use mpi implicit none !--Include the mpi header file integer ierr,myid,numprocs integer irc,tag1,tag2 integer status(MPI_STATUS_SIZE) real a,b !--Initialize MPI call MPI_INIT( ierr ) !--Who am I? --- get my rank=myid call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr ) !--How many processes in the global group? call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr ) print *, "Process ", myid, " of ", numprocs, " is alive" if (myid == 0) then a=90. b=1. write(*,*)'part 1: myid=',myid,' a=',a,' b=',b else a=4. *myid b=7. *myid write(*,*)'part 1: myid=',myid,' a=',a,' b=',b end if !--Exchange messages tag1=1 tag2=2 if (myid == 0) then call mpi_sendrecv(a,1,mpi_real,1,tag1, & !send a, get b. b,1,mpi_real,2,tag2, & MPI_COMM_WORLD, status,ierr) !elseif (myid == 1) then ! call mpi_sendrecv(b,1,mpi_real,0,tag2, & !send b, get a ! a,1,mpi_real,0,tag1, & ! MPI_COMM_WORLD,status,ierr) elseif (myid==1) then call mpi_recv(a,1,mpi_real,0,tag1, MPI_COMM_WORLD, status, ierr) elseif (myid==2) then call mpi_send(b,1,mpi_real,0,tag2,MPI_COMM_WORLD, ierr) end if write(*,*)'part2: myid=',myid,' a=',a,' b=',b !--Finilize MPI call MPI_FINALIZE(irc) stop end