From d54bbdb8cfc69546c54d2171cb859bf3be5465a2 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 13 Feb 2017 15:19:59 +0900 Subject: [PATCH 1/3] coll/libnbc: fix a2aw_sched_linear() with zero size datatype or zero count Signed-off-by: Gilles Gouaillardet (cherry picked from commit open-mpi/ompi@12949547f42a042c0b1c30bec357a1f4aa316937) --- ompi/mca/coll/libnbc/nbc_ialltoallw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ompi/mca/coll/libnbc/nbc_ialltoallw.c b/ompi/mca/coll/libnbc/nbc_ialltoallw.c index ec29a3a355f..9a6284dbb18 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoallw.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoallw.c @@ -193,12 +193,14 @@ static inline int a2aw_sched_linear(int rank, int p, NBC_Schedule *schedule, int res; for (int i = 0; i < p; i++) { + ptrdiff_t gap, span; if (i == rank) { continue; } /* post send */ - if (sendcounts[i] != 0) { + span = opal_datatype_span(&sendtypes[i]->super, sendcounts[i], &gap); + if (OPAL_LIKELY(0 < span)) { char *sbuf = (char *) sendbuf + sdispls[i]; res = NBC_Sched_send (sbuf, false, sendcounts[i], sendtypes[i], i, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { @@ -206,7 +208,8 @@ static inline int a2aw_sched_linear(int rank, int p, NBC_Schedule *schedule, } } /* post receive */ - if (recvcounts[i] != 0) { + span = opal_datatype_span(&recvtypes[i]->super, recvcounts[i], &gap); + if (OPAL_LIKELY(0 < span)) { char *rbuf = (char *) recvbuf + rdispls[i]; res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtypes[i], i, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { From 3e763a860a48096633d6a0a290644adce90065ce Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 13 Feb 2017 15:17:48 +0900 Subject: [PATCH 2/3] opal/datatype: correctly handle zero size datatype or zero count Signed-off-by: Gilles Gouaillardet (cherry picked from commit open-mpi/ompi@bf0fc4a84c3a4222a14efe2e8b09224eaccacc97) --- opal/datatype/opal_datatype.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/opal/datatype/opal_datatype.h b/opal/datatype/opal_datatype.h index 25f014ead0d..34c7b4e1b66 100644 --- a/opal/datatype/opal_datatype.h +++ b/opal/datatype/opal_datatype.h @@ -14,6 +14,8 @@ * reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. + * Copyright (c) 2017 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -344,6 +346,9 @@ opal_datatype_span( const opal_datatype_t* pData, int64_t count, { OPAL_PTRDIFF_TYPE extent = (pData->ub - pData->lb); OPAL_PTRDIFF_TYPE true_extent = (pData->true_ub - pData->true_lb); + if (OPAL_UNLIKELY(0 == pData->size) || (0 == count)) { + return 0; + } *gap = pData->true_lb; return true_extent + (count - 1) * extent; } From 5c74e728481c3894f7289802f0591114afa95f8e Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 13 Feb 2017 10:47:06 +0900 Subject: [PATCH 3/3] coll/libnbc: optimize zero size ialltoall{v,w} with MPI_IN_PLACE and incidentally avoids malloc(0) Thanks Lisandro Dalcin for the report Fixes open-mpi/ompi#2945 Signed-off-by: Gilles Gouaillardet (cherry picked from commit open-mpi/ompi@e70a30cca496b8def92d92477b6481b5dbd7e459) --- ompi/mca/coll/libnbc/nbc_ialltoallv.c | 24 ++++++++++++++++-------- ompi/mca/coll/libnbc/nbc_ialltoallw.c | 8 +++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ompi/mca/coll/libnbc/nbc_ialltoallv.c b/ompi/mca/coll/libnbc/nbc_ialltoallv.c index d39838124d8..64ab1621ff6 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoallv.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoallv.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -74,6 +74,11 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons } } span = opal_datatype_span(&recvtype->super, count, &gap); + if (OPAL_UNLIKELY(0 == span)) { + *request = &ompi_request_empty; + NBC_Return_handle (handle); + return MPI_SUCCESS; + } handle->tmpbuf = malloc(span); if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { NBC_Return_handle (handle); @@ -85,6 +90,7 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons res = ompi_datatype_type_extent (sendtype, &sndext); if (MPI_SUCCESS != res) { NBC_Error("MPI Error in ompi_datatype_type_extent() (%i)", res); + NBC_Return_handle (handle); return res; } if (sendcounts[rank] != 0) { @@ -336,13 +342,15 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule, if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } - res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; + if (0 != counts[peer]) { + res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } + res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } } } diff --git a/ompi/mca/coll/libnbc/nbc_ialltoallw.c b/ompi/mca/coll/libnbc/nbc_ialltoallw.c index 9a6284dbb18..43b12812317 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoallw.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoallw.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -67,6 +67,11 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons span = lspan; } } + if (OPAL_UNLIKELY(0 == span)) { + *request = &ompi_request_empty; + NBC_Return_handle (handle); + return OMPI_SUCCESS; + } handle->tmpbuf = malloc(span); if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { NBC_Return_handle (handle); @@ -80,6 +85,7 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons sbuf = (char *) sendbuf + sdispls[rank]; res = NBC_Copy(sbuf, sendcounts[rank], sendtypes[rank], rbuf, recvcounts[rank], recvtypes[rank], comm); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + NBC_Return_handle (handle); return res; } }