      program example30b
      include 'mpif.h'
      integer ierr, rank, size, prev, next, buf(2), win
      integer (KIND=MPI_ADDRESS_KIND) lb, extent
      call MPI_INIT(ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
      prev = rank - 1
      next = rank + 1
      if (rank .eq. 0) prev = size - 1
      if (rank .eq. size - 1) next = 0
      call MPI_TYPE_GET_EXTENT(MPI_INTEGER, lb, extent, ierr)
      call MPI_WIN_CREATE(buf, 2*extent, extent, MPI_INFO_NULL,
     &                    MPI_COMM_WORLD, win, ierr)
      call MPI_WIN_LOCK(MPI_LOCK_EXCLUSIVE, prev, 0, win, ierr)
      call MPI_PUT(rank, 1, MPI_INTEGER, prev, 1, 1,
     &             MPI_INTEGER, win, ierr)
      call MPI_WIN_UNLOCK(prev, win, ierr)
      call MPI_WIN_LOCK(MPI_LOCK_EXCLUSIVE, next, 0, win, ierr)
      call MPI_PUT(rank, 1, MPI_INTEGER, next, 0, 1,
     &             MPI_INTEGER, win, ierr)
      call MPI_WIN_UNLOCK(next, win, ierr)
      call MPI_WIN_FREE(win, ierr)
      print *, 'process ', rank,
     &         ' prev=', buf(1), ' next=', buf(2)
      call MPI_FINALIZE(ierr)
      end
