next up previous contents
Next: Finalize Up: Collectives Previous: Alltoall

Alltoallv

int MPI_Alltoallv(void *sbuf, int *scounts, int *sdisps, MPI_Datatype sdtype, 
              void *rbuf, int *rcounts, int *rdisps, MPI_Datatype rdtype, 
              MPI_Comm comm)
{
  MPI_Request *reqs;
  MPI_Status  *stats;
  MPI_Aint    sextent, rextent;
  int         i, nprocs;

  MPI_Comm_size(comm, &nprocs);
  MPI_Type_extent(sdtype, &sextent);
  MPI_Type_extent(rdtype, &rextent);

  reqs = (MPI_Request *) malloc(2 * nprocs * sizeof(MPI_Request));
  stats = (MPI_Status *) malloc(2 * nprocs * sizeof(MPI_Status));

  for (i = 0; i < nprocs; i++) { 
    MPI_Irecv((char *) rbuf + rdisps[i] * rextent, rcounts[i], 
              rdtype, i, IMPI_ALLTOALLV_TAG, comm, &reqs[2*i]);
    MPI_Isend((char *) sbuf + sdisps[i] * sextent, scounts[i],
              sdtype, i, IMPI_ALLTOALLV_TAG, comm, &reqs[2*i + 1]);
  }

  MPI_Waitall(2 * nprocs, reqs, stats);

  free(reqs);
  free(stats);
  return(MPI_SUCCESS);
}



IMPI Protocol ver 0.0
DRAFT March 22, 1999