integer gindex, dest, bytesinbuf, reqobj, pos
integer status(MPI_STATUS_SIZE), istep
integer bufsiz
integer tbuf1(bufsiz), tbuf2(bufsiz)
parameter (bufsiz=10000)
call mpi_type_extent (MPI_INTEGER, sizeofint, ierr)
bytesinbuf = bufsiz*sizeofint
do istep=0,k-1
call mpi_irecv (tbuf2, bytesinbuf, MPI_PACKED,
MPI_ANY_SOURCE, tag, comm,
reqobj, ierr)
gindex = p*istep + myrank
PACK DATA INTO tbuf1, FIND pos
dest = gindex/k
call mpi_send (tbuf1, pos, MPI_PACKED,
dest, tag, comm, ierr)
call mpi_wait (reqobj, status)
UNPACK DATA FROM tbuf2
end do