Skip to content

Commit 9ea7439

Browse files
Merge pull request #2953 from ggouaillardet/topic/libnbc_ialltoallvw_zero
coll/libnbc: fix and optimize zero size ialltoall{v,w}
2 parents 81e57bb + e70a30c commit 9ea7439

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

ompi/mca/coll/libnbc/nbc_ialltoallv.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Corporation. All rights reserved.
66
* Copyright (c) 2006 The Technical University of Chemnitz. All
77
* rights reserved.
8-
* Copyright (c) 2014-2016 Research Organization for Information Science
8+
* Copyright (c) 2014-2017 Research Organization for Information Science
99
* and Technology (RIST). All rights reserved.
1010
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
1111
* reserved.
@@ -74,6 +74,11 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons
7474
}
7575
}
7676
span = opal_datatype_span(&recvtype->super, count, &gap);
77+
if (OPAL_UNLIKELY(0 == span)) {
78+
*request = &ompi_request_empty;
79+
NBC_Return_handle (handle);
80+
return MPI_SUCCESS;
81+
}
7782
handle->tmpbuf = malloc(span);
7883
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
7984
NBC_Return_handle (handle);
@@ -85,6 +90,7 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons
8590
res = ompi_datatype_type_extent (sendtype, &sndext);
8691
if (MPI_SUCCESS != res) {
8792
NBC_Error("MPI Error in ompi_datatype_type_extent() (%i)", res);
93+
NBC_Return_handle (handle);
8894
return res;
8995
}
9096
if (sendcounts[rank] != 0) {
@@ -338,13 +344,15 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule,
338344
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
339345
return res;
340346
}
341-
res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false);
342-
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
343-
return res;
344-
}
345-
res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true);
346-
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
347-
return res;
347+
if (0 != counts[peer]) {
348+
res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false);
349+
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
350+
return res;
351+
}
352+
res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true);
353+
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
354+
return res;
355+
}
348356
}
349357
}
350358

ompi/mca/coll/libnbc/nbc_ialltoallw.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Corporation. All rights reserved.
66
* Copyright (c) 2006 The Technical University of Chemnitz. All
77
* rights reserved.
8-
* Copyright (c) 2014-2016 Research Organization for Information Science
8+
* Copyright (c) 2014-2017 Research Organization for Information Science
99
* and Technology (RIST). All rights reserved.
1010
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
1111
* reserved.
@@ -67,6 +67,11 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons
6767
span = lspan;
6868
}
6969
}
70+
if (OPAL_UNLIKELY(0 == span)) {
71+
*request = &ompi_request_empty;
72+
NBC_Return_handle (handle);
73+
return OMPI_SUCCESS;
74+
}
7075
handle->tmpbuf = malloc(span);
7176
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
7277
NBC_Return_handle (handle);
@@ -80,6 +85,7 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons
8085
sbuf = (char *) sendbuf + sdispls[rank];
8186
res = NBC_Copy(sbuf, sendcounts[rank], sendtypes[rank], rbuf, recvcounts[rank], recvtypes[rank], comm);
8287
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
88+
NBC_Return_handle (handle);
8389
return res;
8490
}
8591
}
@@ -193,20 +199,23 @@ static inline int a2aw_sched_linear(int rank, int p, NBC_Schedule *schedule,
193199
int res;
194200

195201
for (int i = 0; i < p; i++) {
202+
ptrdiff_t gap, span;
196203
if (i == rank) {
197204
continue;
198205
}
199206

200207
/* post send */
201-
if (sendcounts[i] != 0) {
208+
span = opal_datatype_span(&sendtypes[i]->super, sendcounts[i], &gap);
209+
if (OPAL_LIKELY(0 < span)) {
202210
char *sbuf = (char *) sendbuf + sdispls[i];
203211
res = NBC_Sched_send (sbuf, false, sendcounts[i], sendtypes[i], i, schedule, false);
204212
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
205213
return res;
206214
}
207215
}
208216
/* post receive */
209-
if (recvcounts[i] != 0) {
217+
span = opal_datatype_span(&recvtypes[i]->super, recvcounts[i], &gap);
218+
if (OPAL_LIKELY(0 < span)) {
210219
char *rbuf = (char *) recvbuf + rdispls[i];
211220
res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtypes[i], i, schedule, false);
212221
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {

opal/datatype/opal_datatype.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* reserved.
1515
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
17+
* Copyright (c) 2017 Research Organization for Information Science
18+
* and Technology (RIST). All rights reserved.
1719
* $COPYRIGHT$
1820
*
1921
* Additional copyrights may follow
@@ -344,6 +346,9 @@ opal_datatype_span( const opal_datatype_t* pData, int64_t count,
344346
{
345347
OPAL_PTRDIFF_TYPE extent = (pData->ub - pData->lb);
346348
OPAL_PTRDIFF_TYPE true_extent = (pData->true_ub - pData->true_lb);
349+
if (OPAL_UNLIKELY(0 == pData->size) || (0 == count)) {
350+
return 0;
351+
}
347352
*gap = pData->true_lb;
348353
return true_extent + (count - 1) * extent;
349354
}

0 commit comments

Comments
 (0)