Date: 2022-03-31T04:46:11+00:00

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:   static PetscInt CHUNKSIZE = 250000000; /* 250,000,000 */
     11:   PetscInt        i,numchunks;
     12:   PetscMPIInt     icnt;

     14:   numchunks = cnt/CHUNKSIZE + 1;
     15:   for (i=0; i<numchunks; i++) {
     16:     PetscMPIIntCast((i < numchunks-1) ? CHUNKSIZE : cnt - (numchunks-1)*CHUNKSIZE,&icnt);
     17:     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:   return 0;
     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:   numchunks = cnt/CHUNKSIZE + 1;
     33:   for (i=0; i<numchunks; i++) {
     34:     PetscMPIIntCast((i < numchunks-1) ? CHUNKSIZE : cnt - (numchunks-1)*CHUNKSIZE,&icnt);
     35:     MPI_Recv(mess,icnt,type,from,tag,comm,&status);
     36:     if (type == MPIU_INT)         mess = (void*) (((PetscInt*)mess) + CHUNKSIZE);
     37:     else if (type == MPIU_SCALAR) mess = (void*) (((PetscScalar*)mess) + CHUNKSIZE);
     38:     else SETERRQ(comm,PETSC_ERR_SUP,"No support for this datatype");
     39:   }
     40:   return 0;
     41: }