Skip to content

Commit af0c640

Browse files
authored
Merge pull request #12198 from wenduwan/alltoallv_skip_0_byte
coll/alltoallv,ialltoallv: skip send/recv 0-byte data
2 parents ae3356f + a3a4787 commit af0c640

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

ompi/mca/coll/base/coll_base_alltoallv.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ ompi_coll_base_alltoallv_intra_pairwise(const void *sbuf, const int *scounts, co
199199
mca_coll_base_module_t *module)
200200
{
201201
int line = -1, err = 0, rank, size, step = 0, sendto, recvfrom;
202+
size_t sdtype_size, rdtype_size;
202203
void *psnd, *prcv;
203204
ptrdiff_t sext, rext;
204205

@@ -213,6 +214,14 @@ ompi_coll_base_alltoallv_intra_pairwise(const void *sbuf, const int *scounts, co
213214
OPAL_OUTPUT((ompi_coll_base_framework.framework_output,
214215
"coll:base:alltoallv_intra_pairwise rank %d", rank));
215216

217+
ompi_datatype_type_size(sdtype, &sdtype_size);
218+
ompi_datatype_type_size(rdtype, &rdtype_size);
219+
220+
if (0 == sdtype_size || 0 == rdtype_size) {
221+
/* Nothing to exchange */
222+
return MPI_SUCCESS;
223+
}
224+
216225
ompi_datatype_type_extent(sdtype, &sext);
217226
ompi_datatype_type_extent(rdtype, &rext);
218227

@@ -263,6 +272,7 @@ ompi_coll_base_alltoallv_intra_basic_linear(const void *sbuf, const int *scounts
263272
mca_coll_base_module_t *module)
264273
{
265274
int i, size, rank, err, nreqs;
275+
size_t sdtype_size = 0, rdtype_size = 0;
266276
char *psnd, *prcv;
267277
ptrdiff_t sext, rext;
268278
ompi_request_t **preq, **reqs;
@@ -280,13 +290,21 @@ ompi_coll_base_alltoallv_intra_basic_linear(const void *sbuf, const int *scounts
280290
OPAL_OUTPUT((ompi_coll_base_framework.framework_output,
281291
"coll:base:alltoallv_intra_basic_linear rank %d", rank));
282292

293+
ompi_datatype_type_size(rdtype, &rdtype_size);
294+
ompi_datatype_type_size(sdtype, &sdtype_size);
295+
296+
if (0 == rdtype_size || 0 == sdtype_size) {
297+
/* Nothing to exchange */
298+
return MPI_SUCCESS;
299+
}
300+
283301
ompi_datatype_type_extent(sdtype, &sext);
284302
ompi_datatype_type_extent(rdtype, &rext);
285303

286304
/* Simple optimization - handle send to self first */
287305
psnd = ((char *) sbuf) + (ptrdiff_t)sdisps[rank] * sext;
288306
prcv = ((char *) rbuf) + (ptrdiff_t)rdisps[rank] * rext;
289-
if (0 != scounts[rank]) {
307+
if (0 < scounts[rank]) {
290308
err = ompi_datatype_sndrcv(psnd, scounts[rank], sdtype,
291309
prcv, rcounts[rank], rdtype);
292310
if (MPI_SUCCESS != err) {
@@ -310,7 +328,7 @@ ompi_coll_base_alltoallv_intra_basic_linear(const void *sbuf, const int *scounts
310328
continue;
311329
}
312330

313-
if (rcounts[i] > 0) {
331+
if (0 < rcounts[i]) {
314332
++nreqs;
315333
prcv = ((char *) rbuf) + (ptrdiff_t)rdisps[i] * rext;
316334
err = MCA_PML_CALL(irecv_init(prcv, rcounts[i], rdtype,
@@ -326,7 +344,7 @@ ompi_coll_base_alltoallv_intra_basic_linear(const void *sbuf, const int *scounts
326344
continue;
327345
}
328346

329-
if (scounts[i] > 0) {
347+
if (0 < scounts[i]) {
330348
++nreqs;
331349
psnd = ((char *) sbuf) + (ptrdiff_t)sdisps[i] * sext;
332350
err = MCA_PML_CALL(isend_init(psnd, scounts[i], sdtype,

ompi/mca/coll/libnbc/nbc_ialltoallv.c

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
4848
mca_coll_base_module_t *module, bool persistent)
4949
{
5050
int rank, p, res;
51+
size_t sdtype_size, rdtype_size;
5152
MPI_Aint sndext, rcvext;
5253
NBC_Schedule *schedule;
5354
char *rbuf, *sbuf, inplace;
@@ -60,6 +61,7 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
6061
rank = ompi_comm_rank (comm);
6162
p = ompi_comm_size (comm);
6263

64+
ompi_datatype_type_size(recvtype, &rdtype_size);
6365
res = ompi_datatype_type_extent (recvtype, &rcvext);
6466
if (MPI_SUCCESS != res) {
6567
NBC_Error("MPI Error in ompi_datatype_type_extent() (%i)", res);
@@ -92,22 +94,29 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
9294
sendcounts = recvcounts;
9395
sdispls = rdispls;
9496
sndext = rcvext;
97+
sdtype_size = rdtype_size;
9598
} else {
99+
ompi_datatype_type_size(sendtype, &sdtype_size);
96100
res = ompi_datatype_type_extent (sendtype, &sndext);
97101
if (MPI_SUCCESS != res) {
98102
NBC_Error("MPI Error in ompi_datatype_type_extent() (%i)", res);
99103
return res;
100104
}
101105
}
102106

107+
if (0 == sdtype_size || 0 == rdtype_size) {
108+
/* Nothing to exchange */
109+
ompi_coll_base_nbc_reserve_tags(comm, 1);
110+
return nbc_get_noop_request(persistent, request);
111+
}
112+
103113
schedule = OBJ_NEW(NBC_Schedule);
104114
if (OPAL_UNLIKELY(NULL == schedule)) {
105115
free(tmpbuf);
106116
return OMPI_ERR_OUT_OF_RESOURCE;
107117
}
108118

109-
110-
if (!inplace && sendcounts[rank] != 0) {
119+
if (!inplace && 0 < sendcounts[rank]) {
111120
rbuf = (char *) recvbuf + rdispls[rank] * rcvext;
112121
sbuf = (char *) sendbuf + sdispls[rank] * sndext;
113122
res = NBC_Sched_copy (sbuf, false, sendcounts[rank], sendtype,
@@ -177,10 +186,18 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
177186
mca_coll_base_module_t *module, bool persistent)
178187
{
179188
int res, rsize;
189+
size_t sdtype_size, rdtype_size;
180190
MPI_Aint sndext, rcvext;
181191
NBC_Schedule *schedule;
182192
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
183193

194+
ompi_datatype_type_size(sendtype, &sdtype_size);
195+
ompi_datatype_type_size(recvtype, &rdtype_size);
196+
if (0 == sdtype_size || 0 == rdtype_size) {
197+
/* Nothing to exchange */
198+
ompi_coll_base_nbc_reserve_tags(comm, 1);
199+
return nbc_get_noop_request(persistent, request);
200+
}
184201

185202
res = ompi_datatype_type_extent(sendtype, &sndext);
186203
if (MPI_SUCCESS != res) {
@@ -203,7 +220,7 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
203220

204221
for (int i = 0; i < rsize; i++) {
205222
/* post all sends */
206-
if (sendcounts[i] != 0) {
223+
if (0 < sendcounts[i]) {
207224
char *sbuf = (char *) sendbuf + sdispls[i] * sndext;
208225
res = NBC_Sched_send (sbuf, false, sendcounts[i], sendtype, i, schedule, false);
209226
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -212,7 +229,7 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
212229
}
213230
}
214231
/* post all receives */
215-
if (recvcounts[i] != 0) {
232+
if (0 < recvcounts[i]) {
216233
char *rbuf = (char *) recvbuf + rdispls[i] * rcvext;
217234
res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtype, i, schedule, false);
218235
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -272,7 +289,7 @@ static inline int a2av_sched_linear(int rank, int p, NBC_Schedule *schedule,
272289
}
273290

274291
/* post send */
275-
if (sendcounts[i] != 0) {
292+
if (0 < sendcounts[i]) {
276293
char *sbuf = ((char *) sendbuf) + (sdispls[i] * sndext);
277294
res = NBC_Sched_send(sbuf, false, sendcounts[i], sendtype, i, schedule, false);
278295
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -281,7 +298,7 @@ static inline int a2av_sched_linear(int rank, int p, NBC_Schedule *schedule,
281298
}
282299

283300
/* post receive */
284-
if (recvcounts[i] != 0) {
301+
if (0 < recvcounts[i]) {
285302
char *rbuf = ((char *) recvbuf) + (rdispls[i] * rcvext);
286303
res = NBC_Sched_recv(rbuf, false, recvcounts[i], recvtype, i, schedule, false);
287304
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -306,7 +323,7 @@ static inline int a2av_sched_pairwise(int rank, int p, NBC_Schedule *schedule,
306323
int rcvpeer = (rank + p - i) %p;
307324

308325
/* post send */
309-
if (sendcounts[sndpeer] != 0) {
326+
if (0 < sendcounts[sndpeer]) {
310327
char *sbuf = ((char *) sendbuf) + (sdispls[sndpeer] * sndext);
311328
res = NBC_Sched_send(sbuf, false, sendcounts[sndpeer], sendtype, sndpeer, schedule, false);
312329
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -315,7 +332,7 @@ static inline int a2av_sched_pairwise(int rank, int p, NBC_Schedule *schedule,
315332
}
316333

317334
/* post receive */
318-
if (recvcounts[rcvpeer] != 0) {
335+
if (0 < recvcounts[rcvpeer]) {
319336
char *rbuf = ((char *) recvbuf) + (rdispls[rcvpeer] * rcvext);
320337
res = NBC_Sched_recv(rbuf, false, recvcounts[rcvpeer], recvtype, rcvpeer, schedule, true);
321338
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -338,34 +355,34 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule,
338355
char *sbuf = (char *) buf + displs[speer] * ext;
339356
char *rbuf = (char *) buf + displs[rpeer] * ext;
340357

341-
if (0 != counts[rpeer]) {
358+
if (0 < counts[rpeer]) {
342359
res = NBC_Sched_copy (rbuf, false, counts[rpeer], type,
343360
(void *)(-gap), true, counts[rpeer], type,
344361
schedule, true);
345362
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
346363
return res;
347364
}
348365
}
349-
if (0 != counts[speer]) {
366+
if (0 < counts[speer]) {
350367
res = NBC_Sched_send (sbuf, false , counts[speer], type, speer, schedule, false);
351368
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
352369
return res;
353370
}
354371
}
355-
if (0 != counts[rpeer]) {
372+
if (0 < counts[rpeer]) {
356373
res = NBC_Sched_recv (rbuf, false , counts[rpeer], type, rpeer, schedule, true);
357374
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
358375
return res;
359376
}
360377
}
361378

362-
if (0 != counts[rpeer]) {
379+
if (0 < counts[rpeer]) {
363380
res = NBC_Sched_send ((void *)(-gap), true, counts[rpeer], type, rpeer, schedule, false);
364381
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
365382
return res;
366383
}
367384
}
368-
if (0 != counts[speer]) {
385+
if (0 < counts[speer]) {
369386
res = NBC_Sched_recv (sbuf, false, counts[speer], type, speer, schedule, true);
370387
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
371388
return res;
@@ -374,15 +391,17 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule,
374391
}
375392
if (0 == (p%2)) {
376393
int peer = (rank + p/2) % p;
377-
378394
char *tbuf = (char *) buf + displs[peer] * ext;
379-
res = NBC_Sched_copy (tbuf, false, counts[peer], type,
380-
(void *)(-gap), true, counts[peer], type,
381-
schedule, true);
382-
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
383-
return res;
395+
396+
if (0 < counts[peer]) {
397+
res = NBC_Sched_copy(tbuf, false, counts[peer], type, (void *) (-gap), true, counts[peer],
398+
type, schedule, true);
399+
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
400+
return res;
401+
}
384402
}
385-
if (0 != counts[peer]) {
403+
404+
if (0 < counts[peer]) {
386405
res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false);
387406
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
388407
return res;

0 commit comments

Comments
 (0)