      program example29b
      include 'mpif.h'
      integer ierr, rank, size, prev, next, buf(2), win
      integer ranks(2), group, commgroup
      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_COMM_GROUP(MPI_COMM_WORLD, group)
      ranks(1)=prev
      ranks(2)=next
      call MPI_GROUP_INCL(group, 2, ranks, commgroup, ierr)
      call MPI_WIN_POST(commgroup, 0, win, ierr)
      call MPI_WIN_START(commgroup, 0, win, ierr)
      call MPI_PUT(rank, 1, MPI_INTEGER, prev, 1, 1,
     &             MPI_INTEGER, win, ierr)
      call MPI_PUT(rank, 1, MPI_INTEGER, next, 0, 1,
     &             MPI_INTEGER, win, ierr)
      call MPI_WIN_COMPLETE(win, ierr)
      call MPI_WIN_WAIT(win, ierr)
      call MPI_WIN_FREE(win, ierr)
      call MPI_GROUP_FREE(group, ierr)
      call MPI_GROUP_FREE(commgroup, ierr)
      print *, 'process ', rank,
     &         ' prev=', buf(1), ' next=', buf(2)
      call MPI_FINALIZE(ierr)
      end
