      program example7b
      include 'mpif.h'
      integer ierr, size, rank, next, prev, rbuf;
      integer status(MPI_STATUS_SIZE)
      call MPI_INIT(ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
      next = rank+1
      if(next .eq. size) next = MPI_PROC_NULL
      call MPI_SEND(rank, 1, MPI_INTEGER, next,
     &              5, MPI_COMM_WORLD, ierr)
      prev = rank-1
      if(prev .eq. -1) prev = MPI_PROC_NULL
      rbuf = -1
      call MPI_RECV(rbuf, 1, MPI_INTEGER, prev,
     &              5, MPI_COMM_WORLD, status, ierr)
      print *, 'process ', rank,' rbuf = ', rbuf
      call MPI_FINALIZE(ierr)
      end
