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: PetscFunctionBegin;
15: numchunks = cnt / CHUNKSIZE + 1;
16: for (i = 0; i < numchunks; i++) {
17: PetscCall(PetscMPIIntCast((i < numchunks - 1) ? CHUNKSIZE : cnt - (numchunks - 1) * CHUNKSIZE, &icnt));
18: PetscCallMPI(MPI_Send(mess, icnt, type, to, tag, comm));
19: if (type == MPIU_INT) mess = (void *)(((PetscInt *)mess) + CHUNKSIZE);
20: else if (type == MPIU_SCALAR) mess = (void *)(((PetscScalar *)mess) + CHUNKSIZE);
21: else SETERRQ(comm, PETSC_ERR_SUP, "No support for this datatype");
22: }
23: PetscFunctionReturn(PETSC_SUCCESS);
24: }
26: PetscErrorCode MPIULong_Recv(void *mess, PetscInt cnt, MPI_Datatype type, PetscMPIInt from, PetscMPIInt tag, MPI_Comm comm)
27: {
28: static PetscInt CHUNKSIZE = 250000000; /* 250,000,000 */
29: MPI_Status status;
30: PetscInt i, numchunks;
31: PetscMPIInt icnt;
33: PetscFunctionBegin;
34: numchunks = cnt / CHUNKSIZE + 1;
35: for (i = 0; i < numchunks; i++) {
36: PetscCall(PetscMPIIntCast((i < numchunks - 1) ? CHUNKSIZE : cnt - (numchunks - 1) * CHUNKSIZE, &icnt));
37: PetscCallMPI(MPI_Recv(mess, icnt, type, from, tag, comm, &status));
38: if (type == MPIU_INT) mess = (void *)(((PetscInt *)mess) + CHUNKSIZE);
39: else if (type == MPIU_SCALAR) mess = (void *)(((PetscScalar *)mess) + CHUNKSIZE);
40: else SETERRQ(comm, PETSC_ERR_SUP, "No support for this datatype");
41: }
42: PetscFunctionReturn(PETSC_SUCCESS);
43: }