program pingpong !!! 10-June-2005 c....... This program send the own processor number to the other processor c....... (run with only 2 processors!) include 'mpif.h' integer status(MPI_STATUS_SIZE) c........initialize MPI call mpi_init(ierr) call mpi_comm_rank(mpi_comm_world,iam,ierr) call mpi_comm_size(mpi_comm_world,nproc,ierr) c........set an ID value for the message tag itag=99 c........have the first task [task zero] send then receive if (iam.eq.0) then c........set values for the send command c........idest is where the message is going c........icount is the number of items being sent idest=1 icount=1 c........set values for the recv command c........source is where to expect a message from isource=1 c........send a message containing the task number to task 1 c........place the task ID in the variable sbuf isbuf = iam CALL MPI_SEND(isbuf, icount, MPI_INTEGER, idest, itag, 1 MPI_COMM_WORLD, ierr) c........receive the message from task 1 into irbuf CALL MPI_RECV(irbuf, icount, MPI_INTEGER, isource, itag, 1 MPI_COMM_WORLD, status, ierr) endif c........have the second task [task one] receive then send. This constitutes c........"blocking" message passing. if (iam.eq.1) then c........set values for the send command c........idest is where the message is going c........icount is the number of items being sent idest=0 icount=1 c........set values for the recv command c........isource is where to expect a message from isource=0 c........Receive the message from task 0 into irbuf CALL MPI_RECV(irbuf, icount, MPI_INTEGER, isource, itag, 1 MPI_COMM_WORLD, status, ierr) c........Send a message containing the task number to task 0 c........place the task ID in the variable sbuf isbuf = iam CALL MPI_SEND(isbuf, icount, MPI_INTEGER, idest, itag, 1 MPI_COMM_WORLD, ierr) endif c........have each task print both what it sent and received PRINT*, "TASK #", iam, " sent ", isbuf PRINT*, "TASK #", iam, " received ", irbuf c........close out MPI call mpi_finalize(ierr) stop end