Actual source code: mpilong.c

  1: #include <petscsys.h>

  3: /*
  4:     Allows sending/receiving larger messages then 2 gigabytes in a single call
  5: */

  7: PetscErrorCode MPIULong_Send(void *mess, PetscInt cnt, MPI_Datatype type, PetscMPIInt to, PetscMPIInt tag, MPI_Comm comm)
  8: {
  9:   static PetscInt CHUNKSIZE = 250000000; /* 250,000,000 */
 10:   PetscInt        i, numchunks;
 11:   PetscMPIInt     icnt;

 13:   PetscFunctionBegin;
 14:   numchunks = cnt / CHUNKSIZE + 1;
 15:   for (i = 0; i < numchunks; i++) {
 16:     PetscCall(PetscMPIIntCast((i < numchunks - 1) ? CHUNKSIZE : cnt - (numchunks - 1) * CHUNKSIZE, &icnt));
 17:     PetscCallMPI(MPI_Send(mess, icnt, type, to, tag, comm));
 18:     if (type == MPIU_INT) mess = (void *)(((PetscInt *)mess) + CHUNKSIZE);
 19:     else if (type == MPIU_SCALAR) mess = (void *)(((PetscScalar *)mess) + CHUNKSIZE);
 20:     else SETERRQ(comm, PETSC_ERR_SUP, "No support for this datatype");
 21:   }
 22:   PetscFunctionReturn(PETSC_SUCCESS);
 23: }

 25: PetscErrorCode MPIULong_Recv(void *mess, PetscInt cnt, MPI_Datatype type, PetscMPIInt from, PetscMPIInt tag, MPI_Comm comm)
 26: {
 27:   static PetscInt CHUNKSIZE = 250000000; /* 250,000,000 */
 28:   MPI_Status      status;
 29:   PetscInt        i, numchunks;
 30:   PetscMPIInt     icnt;

 32:   PetscFunctionBegin;
 33:   numchunks = cnt / CHUNKSIZE + 1;
 34:   for (i = 0; i < numchunks; i++) {
 35:     PetscCall(PetscMPIIntCast((i < numchunks - 1) ? CHUNKSIZE : cnt - (numchunks - 1) * CHUNKSIZE, &icnt));
 36:     PetscCallMPI(MPI_Recv(mess, icnt, type, from, tag, comm, &status));
 37:     if (type == MPIU_INT) mess = (void *)(((PetscInt *)mess) + CHUNKSIZE);
 38:     else if (type == MPIU_SCALAR) mess = (void *)(((PetscScalar *)mess) + CHUNKSIZE);
 39:     else SETERRQ(comm, PETSC_ERR_SUP, "No support for this datatype");
 40:   }
 41:   PetscFunctionReturn(PETSC_SUCCESS);
 42: }