Actual source code: mpilong.c

      2: #include <petscsys.h>

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

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

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

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

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