1 /*
2 * Copyright 1997, Regents of the University of Minnesota
3 *
4 * gkmpi.c
5 *
6 * This function contains wrappers around MPI calls to allow
7 * future de-coupling of sizes from 'int' datatypes.
8 *
9 * Started 5/30/11
10 * George
11 *
12 * $Id: gkmpi.c 10022 2011-05-30 20:18:42Z karypis $
13 */
14
15 #include <parmetislib.h>
16
gkMPI_Comm_size(MPI_Comm comm,idx_t * size)17 int gkMPI_Comm_size(MPI_Comm comm, idx_t *size)
18 {
19 int status, lsize;
20
21 status = MPI_Comm_size(comm, &lsize);
22 *size = lsize;
23
24 return status;
25 }
26
gkMPI_Comm_rank(MPI_Comm comm,idx_t * rank)27 int gkMPI_Comm_rank(MPI_Comm comm, idx_t *rank)
28 {
29 int status, lrank;
30
31 status = MPI_Comm_rank(comm, &lrank);
32 *rank = lrank;
33
34 return status;
35 }
36
gkMPI_Get_count(MPI_Status * status,MPI_Datatype datatype,idx_t * count)37 int gkMPI_Get_count(MPI_Status *status, MPI_Datatype datatype,
38 idx_t *count)
39 {
40 int rstatus, lcount;
41
42 rstatus = MPI_Get_count(status, datatype, &lcount);
43 *count = lcount;
44
45 return rstatus;
46 }
47
gkMPI_Send(void * buf,idx_t count,MPI_Datatype datatype,idx_t dest,idx_t tag,MPI_Comm comm)48 int gkMPI_Send(void *buf, idx_t count, MPI_Datatype datatype, idx_t dest,
49 idx_t tag, MPI_Comm comm)
50 {
51 return MPI_Send(buf, count, datatype, dest, tag, comm);
52 }
53
gkMPI_Recv(void * buf,idx_t count,MPI_Datatype datatype,idx_t source,idx_t tag,MPI_Comm comm,MPI_Status * status)54 int gkMPI_Recv(void *buf, idx_t count, MPI_Datatype datatype,
55 idx_t source, idx_t tag, MPI_Comm comm, MPI_Status *status)
56 {
57 return MPI_Recv(buf, count, datatype, source, tag, comm, status);
58 }
59
gkMPI_Isend(void * buf,idx_t count,MPI_Datatype datatype,idx_t dest,idx_t tag,MPI_Comm comm,MPI_Request * request)60 int gkMPI_Isend(void *buf, idx_t count, MPI_Datatype datatype, idx_t dest,
61 idx_t tag, MPI_Comm comm, MPI_Request *request)
62 {
63 return MPI_Isend(buf, count, datatype, dest, tag, comm, request);
64 }
65
gkMPI_Irecv(void * buf,idx_t count,MPI_Datatype datatype,idx_t source,idx_t tag,MPI_Comm comm,MPI_Request * request)66 int gkMPI_Irecv(void *buf, idx_t count, MPI_Datatype datatype,
67 idx_t source, idx_t tag, MPI_Comm comm, MPI_Request *request)
68 {
69 return MPI_Irecv(buf, count, datatype, source, tag, comm, request);
70 }
71
gkMPI_Wait(MPI_Request * request,MPI_Status * status)72 int gkMPI_Wait(MPI_Request *request, MPI_Status *status)
73 {
74 return MPI_Wait(request, status);
75 }
76
gkMPI_Waitall(idx_t count,MPI_Request * array_of_requests,MPI_Status * array_of_statuses)77 int gkMPI_Waitall(idx_t count, MPI_Request *array_of_requests,
78 MPI_Status *array_of_statuses)
79 {
80 return MPI_Waitall(count, array_of_requests, array_of_statuses);
81 }
82
gkMPI_Barrier(MPI_Comm comm)83 int gkMPI_Barrier(MPI_Comm comm)
84 {
85 return MPI_Barrier(comm);
86 }
87
gkMPI_Bcast(void * buffer,idx_t count,MPI_Datatype datatype,idx_t root,MPI_Comm comm)88 int gkMPI_Bcast(void *buffer, idx_t count, MPI_Datatype datatype,
89 idx_t root, MPI_Comm comm)
90 {
91 return MPI_Bcast(buffer, count, datatype, root, comm);
92 }
93
gkMPI_Reduce(void * sendbuf,void * recvbuf,idx_t count,MPI_Datatype datatype,MPI_Op op,idx_t root,MPI_Comm comm)94 int gkMPI_Reduce(void *sendbuf, void *recvbuf, idx_t count,
95 MPI_Datatype datatype, MPI_Op op, idx_t root, MPI_Comm comm)
96 {
97 return MPI_Reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
98 }
99
gkMPI_Allreduce(void * sendbuf,void * recvbuf,idx_t count,MPI_Datatype datatype,MPI_Op op,MPI_Comm comm)100 int gkMPI_Allreduce(void *sendbuf, void *recvbuf, idx_t count,
101 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
102 {
103 return MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm);
104 }
105
gkMPI_Scan(void * sendbuf,void * recvbuf,idx_t count,MPI_Datatype datatype,MPI_Op op,MPI_Comm comm)106 int gkMPI_Scan(void *sendbuf, void *recvbuf, idx_t count,
107 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
108 {
109 return MPI_Scan(sendbuf, recvbuf, count, datatype, op, comm);
110 }
111
gkMPI_Allgather(void * sendbuf,idx_t sendcount,MPI_Datatype sendtype,void * recvbuf,idx_t recvcount,MPI_Datatype recvtype,MPI_Comm comm)112 int gkMPI_Allgather(void *sendbuf, idx_t sendcount,
113 MPI_Datatype sendtype, void *recvbuf, idx_t recvcount,
114 MPI_Datatype recvtype, MPI_Comm comm)
115 {
116 return MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf,
117 recvcount, recvtype, comm);
118 }
119
gkMPI_Alltoall(void * sendbuf,idx_t sendcount,MPI_Datatype sendtype,void * recvbuf,idx_t recvcount,MPI_Datatype recvtype,MPI_Comm comm)120 int gkMPI_Alltoall(void *sendbuf, idx_t sendcount,
121 MPI_Datatype sendtype, void *recvbuf, idx_t recvcount,
122 MPI_Datatype recvtype, MPI_Comm comm)
123 {
124 return MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
125 recvtype, comm);
126 }
127
gkMPI_Alltoallv(void * sendbuf,idx_t * sendcounts,idx_t * sdispls,MPI_Datatype sendtype,void * recvbuf,idx_t * recvcounts,idx_t * rdispls,MPI_Datatype recvtype,MPI_Comm comm)128 int gkMPI_Alltoallv(void *sendbuf, idx_t *sendcounts,
129 idx_t *sdispls, MPI_Datatype sendtype, void *recvbuf,
130 idx_t *recvcounts, idx_t *rdispls, MPI_Datatype recvtype,
131 MPI_Comm comm)
132 {
133 #if IDXTYPEWIDTH == 32
134 return MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype,
135 recvbuf, recvcounts, rdispls, recvtype, comm);
136 #else
137 idx_t i;
138 int status, npes, *lsendcounts, *lsdispls, *lrecvcounts, *lrdispls;
139
140 MPI_Comm_size(comm, &npes);
141
142 lsendcounts = gk_imalloc(npes, "lsendcounts");
143 lsdispls = gk_imalloc(npes, "lsdispls");
144 lrecvcounts = gk_imalloc(npes, "lrecvcounts");
145 lrdispls = gk_imalloc(npes, "lrdispls");
146
147 for (i=0; i<npes; i++) {
148 lsendcounts[i] = sendcounts[i];
149 lsdispls[i] = sdispls[i];
150 lrecvcounts[i] = recvcounts[i];
151 lrdispls[i] = rdispls[i];
152 }
153
154 status = MPI_Alltoallv(sendbuf, lsendcounts, lsdispls, sendtype,
155 recvbuf, lrecvcounts, lrdispls, recvtype, comm);
156
157 for (i=0; i<npes; i++) {
158 sendcounts[i] = lsendcounts[i];
159 sdispls[i] = lsdispls[i];
160 recvcounts[i] = lrecvcounts[i];
161 rdispls[i] = lrdispls[i];
162 }
163
164 gk_free((void **)&lsendcounts, &lrecvcounts, &lsdispls, &lrdispls, LTERM);
165
166 return status;
167 #endif
168 }
169
gkMPI_Allgatherv(void * sendbuf,idx_t sendcount,MPI_Datatype sendtype,void * recvbuf,idx_t * recvcounts,idx_t * rdispls,MPI_Datatype recvtype,MPI_Comm comm)170 int gkMPI_Allgatherv(void *sendbuf, idx_t sendcount, MPI_Datatype sendtype,
171 void *recvbuf, idx_t *recvcounts, idx_t *rdispls,
172 MPI_Datatype recvtype, MPI_Comm comm)
173 {
174 #if IDXTYPEWIDTH == 32
175 return MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
176 recvcounts, rdispls, recvtype, comm);
177 #else
178 idx_t i;
179 int status, npes, *lrecvcounts, *lrdispls;
180
181 MPI_Comm_size(comm, &npes);
182
183 lrecvcounts = gk_imalloc(npes, "lrecvcounts");
184 lrdispls = gk_imalloc(npes, "lrdispls");
185
186 for (i=0; i<npes; i++) {
187 lrecvcounts[i] = recvcounts[i];
188 lrdispls[i] = rdispls[i];
189 }
190
191 status = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
192 lrecvcounts, lrdispls, recvtype, comm);
193
194 for (i=0; i<npes; i++) {
195 recvcounts[i] = lrecvcounts[i];
196 rdispls[i] = lrdispls[i];
197 }
198
199 gk_free((void **)&lrecvcounts, &lrdispls, LTERM);
200
201 return status;
202 #endif
203 }
204
gkMPI_Scatterv(void * sendbuf,idx_t * sendcounts,idx_t * sdispls,MPI_Datatype sendtype,void * recvbuf,idx_t recvcount,MPI_Datatype recvtype,idx_t root,MPI_Comm comm)205 int gkMPI_Scatterv(void *sendbuf, idx_t *sendcounts, idx_t *sdispls,
206 MPI_Datatype sendtype, void *recvbuf, idx_t recvcount,
207 MPI_Datatype recvtype, idx_t root, MPI_Comm comm)
208 {
209 #if IDXTYPEWIDTH == 32
210 return MPI_Scatterv(sendbuf, sendcounts, sdispls, sendtype,
211 recvbuf, recvcount, recvtype, root, comm);
212 #else
213 idx_t i;
214 int status, npes, *lsendcounts, *lsdispls;
215
216 MPI_Comm_size(comm, &npes);
217
218 lsendcounts = gk_imalloc(npes, "lsendcounts");
219 lsdispls = gk_imalloc(npes, "lsdispls");
220
221 for (i=0; i<npes; i++) {
222 lsendcounts[i] = sendcounts[i];
223 lsdispls[i] = sdispls[i];
224 }
225
226 status = MPI_Scatterv(sendbuf, lsendcounts, lsdispls, sendtype,
227 recvbuf, recvcount, recvtype, root, comm);
228
229 for (i=0; i<npes; i++) {
230 sendcounts[i] = lsendcounts[i];
231 sdispls[i] = lsdispls[i];
232 }
233
234 gk_free((void **)&lsendcounts, &lsdispls, LTERM);
235
236 return status;
237 #endif
238 }
239
gkMPI_Gatherv(void * sendbuf,idx_t sendcount,MPI_Datatype sendtype,void * recvbuf,idx_t * recvcounts,idx_t * rdispls,MPI_Datatype recvtype,idx_t root,MPI_Comm comm)240 int gkMPI_Gatherv(void *sendbuf, idx_t sendcount, MPI_Datatype sendtype,
241 void *recvbuf, idx_t *recvcounts, idx_t *rdispls, MPI_Datatype recvtype,
242 idx_t root, MPI_Comm comm)
243 {
244 #if IDXTYPEWIDTH == 32
245 return MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf,
246 recvcounts, rdispls, recvtype, root, comm);
247 #else
248 idx_t i;
249 int status, npes, *lrecvcounts, *lrdispls;
250
251 MPI_Comm_size(comm, &npes);
252
253 lrecvcounts = gk_imalloc(npes, "lrecvcounts");
254 lrdispls = gk_imalloc(npes, "lrdispls");
255
256 for (i=0; i<npes; i++) {
257 lrecvcounts[i] = recvcounts[i];
258 lrdispls[i] = rdispls[i];
259 }
260
261 status = MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf,
262 lrecvcounts, lrdispls, recvtype, root, comm);
263
264 for (i=0; i<npes; i++) {
265 recvcounts[i] = lrecvcounts[i];
266 rdispls[i] = lrdispls[i];
267 }
268
269 gk_free((void **)&lrecvcounts, &lrdispls, LTERM);
270
271 return status;
272 #endif
273 }
274
gkMPI_Comm_split(MPI_Comm comm,idx_t color,idx_t key,MPI_Comm * newcomm)275 int gkMPI_Comm_split(MPI_Comm comm, idx_t color, idx_t key,
276 MPI_Comm *newcomm)
277 {
278 return MPI_Comm_split(comm, color, key, newcomm);
279 }
280
gkMPI_Comm_free(MPI_Comm * comm)281 int gkMPI_Comm_free(MPI_Comm *comm)
282 {
283 return MPI_Comm_free(comm);
284 }
285
gkMPI_Finalize()286 int gkMPI_Finalize()
287 {
288 return MPI_Finalize();
289 }
290