      program example19b
      include 'mpif.h'
      integer ierr, rank, i, size, size1, n
      integer status(MPI_STATUS_SIZE)
      integer group, group1, group2
      integer ranks(128), rank1, rank2, rank3
      call MPI_INIT(ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
      call MPI_COMM_GROUP(MPI_COMM_WORLD, group, ierr)
      size1 = size/2
      do i = 1, size1
         ranks(i) = i-1
      enddo 
      call MPI_GROUP_INCL(group, size1, ranks, group1, ierr)
      call MPI_GROUP_EXCL(group, size1, ranks, group2, ierr)
      call MPI_GROUP_RANK(group1, rank1, ierr)
      call MPI_GROUP_RANK(group2, rank2, ierr)
      if(rank1 .eq. MPI_UNDEFINED) then
         if(2*size1 .eq. size .or. rank .ne. size -1) then
            call MPI_GROUP_TRANSLATE_RANKS(group1, 1, rank2,
     &                                     group, rank3, ierr)
         else
            rank3 = MPI_ PROC_NULL
         end if
      else
         call MPI_GROUP_TRANSLATE_RANKS(group2, 1, rank1,
     &                                  group, rank3, ierr)
      end if      
      call MPI_SENDRECV(rank, 1, MPI_INTEGER, rank3, 1,
     &                  n, 1, MPI_INTEGER, rank3, 1,
     &                  MPI_COMM_WORLD, status, ierr)
      call MPI_GROUP_FREE(group, ierr)
      call MPI_GROUP_FREE(group1, ierr)
      call MPI_GROUP_FREE(group2, ierr)
      print *, 'process ', rank, ' n=', n
      call MPI_FINALIZE(ierr)
      end
