Actual source code: mpiutils.h
1: #ifndef MPIUTILS_H
2: #define MPIUTILS_H
4: #include <petscsys.h>
6: PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages_Private(MPI_Comm, const PetscMPIInt[], const PetscInt[], PetscMPIInt *);
7: PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths_Private(MPI_Comm, PetscMPIInt, PetscMPIInt, const PetscInt[], PetscMPIInt **, PetscInt **);
9: #if !defined(PETSC_HAVE_MPI_LARGE_COUNT) /* No matter PetscInt is 32-bit or 64-bit, without MPI large count we always do casting before MPI calls */
10: /* Cast PetscInt <a> to PetscMPIInt <b>, where <a> is likely used for the 'count' argument in MPI routines.
11: It is similar to PetscMPIIntCast() execept that here it returns an MPI error code.
12: */
13: static inline PetscMPIInt PetscMPIIntCast_Internal(PetscInt a, PetscMPIInt *b)
14: {
15: *b = (PetscMPIInt)(a);
16: if (PetscDefined(USE_64BIT_INDICIES) && PetscUnlikely(a > PETSC_MPI_INT_MAX)) return MPI_ERR_COUNT;
17: return MPI_SUCCESS;
18: }
20: static inline PetscMPIInt MPIU_Send(const void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm)
21: {
22: PetscMPIInt count2;
24: PetscMPIIntCast_Internal(count, &count2);
25: MPI_Send(buf, count2, datatype, dest, tag, comm);
26: return MPI_SUCCESS;
27: }
29: static inline PetscMPIInt MPIU_Send_init(const void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
30: {
31: PetscMPIInt count2;
33: PetscMPIIntCast_Internal(count, &count2);
34: MPI_Send_init(buf, count2, datatype, dest, tag, comm, request);
35: return MPI_SUCCESS;
36: }
38: static inline PetscMPIInt MPIU_Isend(const void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt dest, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
39: {
40: PetscMPIInt count2;
42: PetscMPIIntCast_Internal(count, &count2);
43: MPI_Isend(buf, count2, datatype, dest, tag, comm, request);
44: return MPI_SUCCESS;
45: }
47: static inline PetscMPIInt MPIU_Recv(void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Status *status)
48: {
49: PetscMPIInt count2;
51: PetscMPIIntCast_Internal(count, &count2);
52: MPI_Recv(buf, count2, datatype, source, tag, comm, status);
53: return MPI_SUCCESS;
54: }
56: static inline PetscMPIInt MPIU_Recv_init(void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
57: {
58: PetscMPIInt count2;
60: PetscMPIIntCast_Internal(count, &count2);
61: MPI_Recv_init(buf, count2, datatype, source, tag, comm, request);
62: return MPI_SUCCESS;
63: }
65: static inline PetscMPIInt MPIU_Irecv(void *buf, PetscInt count, MPI_Datatype datatype, PetscMPIInt source, PetscMPIInt tag, MPI_Comm comm, MPI_Request *request)
66: {
67: PetscMPIInt count2;
69: PetscMPIIntCast_Internal(count, &count2);
70: MPI_Irecv(buf, count2, datatype, source, tag, comm, request);
71: return MPI_SUCCESS;
72: }
73: #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
74: static inline PetscMPIInt MPIU_Reduce_local(const void *inbuf, void *inoutbuf, PetscInt count, MPI_Datatype datatype, MPI_Op op)
75: {
76: PetscMPIInt count2;
78: PetscMPIIntCast_Internal(count, &count2);
79: MPI_Reduce_local(inbuf, inoutbuf, count, datatype, op);
80: return MPI_SUCCESS;
81: }
82: #endif
84: #elif defined(PETSC_USE_64BIT_INDICES)
85: #define MPIU_Send(buf, count, datatype, dest, tag, comm) MPI_Send_c(buf, count, datatype, dest, tag, comm)
86: #define MPIU_Send_init(buf, count, datatype, dest, tag, comm, request) MPI_Send_init_c(buf, count, datatype, dest, tag, comm, request)
87: #define MPIU_Isend(buf, count, datatype, dest, tag, comm, request) MPI_Isend_c(buf, count, datatype, dest, tag, comm, request)
88: #define MPIU_Recv(buf, count, datatype, source, tag, comm, status) MPI_Recv_c(buf, count, datatype, source, tag, comm, status)
89: #define MPIU_Recv_init(buf, count, datatype, source, tag, comm, request) MPI_Recv_init_c(buf, count, datatype, source, tag, comm, request)
90: #define MPIU_Irecv(buf, count, datatype, source, tag, comm, request) MPI_Irecv_c(buf, count, datatype, source, tag, comm, request)
91: #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
92: #define MPIU_Reduce_local(inbuf, inoutbuf, count, datatype, op) MPI_Reduce_local_c(inbuf, inoutbuf, count, datatype, op)
93: #endif
94: #else
95: #define MPIU_Send(buf, count, datatype, dest, tag, comm) MPI_Send(buf, count, datatype, dest, tag, comm)
96: #define MPIU_Send_init(buf, count, datatype, dest, tag, comm, request) MPI_Send_init(buf, count, datatype, dest, tag, comm, request)
97: #define MPIU_Isend(buf, count, datatype, dest, tag, comm, request) MPI_Isend(buf, count, datatype, dest, tag, comm, request)
98: #define MPIU_Recv(buf, count, datatype, source, tag, comm, status) MPI_Recv(buf, count, datatype, source, tag, comm, status)
99: #define MPIU_Recv_init(buf, count, datatype, source, tag, comm, request) MPI_Recv_init(buf, count, datatype, source, tag, comm, request)
100: #define MPIU_Irecv(buf, count, datatype, source, tag, comm, request) MPI_Irecv(buf, count, datatype, source, tag, comm, request)
101: #if defined(PETSC_HAVE_MPI_REDUCE_LOCAL)
102: #define MPIU_Reduce_local(inbuf, inoutbuf, count, datatype, op) MPI_Reduce_local(inbuf, inoutbuf, count, datatype, op)
103: #endif
104: #endif
106: /* These APIs use arrays of MPI_Count/MPI_Aint */
107: #if defined(PETSC_HAVE_MPI_LARGE_COUNT) && defined(PETSC_USE_64BIT_INDICES)
108: #define MPIU_Neighbor_alltoallv(a, b, c, d, e, f, g, h, i) MPI_Neighbor_alltoallv_c(a, b, c, d, e, f, g, h, i)
109: #define MPIU_Ineighbor_alltoallv(a, b, c, d, e, f, g, h, i, j) MPI_Ineighbor_alltoallv_c(a, b, c, d, e, f, g, h, i, j)
110: #else
111: #define MPIU_Neighbor_alltoallv(a, b, c, d, e, f, g, h, i) MPI_Neighbor_alltoallv(a, b, c, d, e, f, g, h, i)
112: #define MPIU_Ineighbor_alltoallv(a, b, c, d, e, f, g, h, i, j) MPI_Ineighbor_alltoallv(a, b, c, d, e, f, g, h, i, j)
113: #endif
115: #endif