diff --git a/ompi/mca/coll/basic/coll_basic_gatherv.c b/ompi/mca/coll/basic/coll_basic_gatherv.c index 495a103fd9..b5266a1952 100644 --- a/ompi/mca/coll/basic/coll_basic_gatherv.c +++ b/ompi/mca/coll/basic/coll_basic_gatherv.c @@ -50,14 +50,19 @@ mca_coll_basic_gatherv_intra(void *sbuf, int scount, size = ompi_comm_size(comm); rank = ompi_comm_rank(comm); - /* Everyone but root sends data and returns. Note that we will only - * get here if scount > 0 or rank == root. */ + /* Everyone but root sends data and returns. Don't send anything + for sendcounts of 0 (even though MPI_Gatherv has a guard for 0 + counts, this routine is used elsewhere, like the implementation + of allgatherv, so it's possible to get here with a scount of + 0) */ if (rank != root) { - err = MCA_PML_CALL(send(sbuf, scount, sdtype, root, - MCA_COLL_BASE_TAG_GATHERV, - MCA_PML_BASE_SEND_STANDARD, comm)); - return err; + if (scount > 0) { + return MCA_PML_CALL(send(sbuf, scount, sdtype, root, + MCA_COLL_BASE_TAG_GATHERV, + MCA_PML_BASE_SEND_STANDARD, comm)); + } + return MPI_SUCCESS; } /* I am the root, loop receiving data. */ @@ -71,10 +76,12 @@ mca_coll_basic_gatherv_intra(void *sbuf, int scount, ptmp = ((char *) rbuf) + (extent * disps[i]); if (i == rank) { - if ((0 < scount) && (0 < rcounts[i])) /* simple optimization */ + /* simple optimization */ + if ((0 < scount) && (0 < rcounts[i])) err = ompi_ddt_sndrcv(sbuf, scount, sdtype, ptmp, rcounts[i], rdtype); } else { + /* Only receive if there is something to receive */ if (rcounts[i] > 0) { err = MCA_PML_CALL(recv(ptmp, rcounts[i], rdtype, i, MCA_COLL_BASE_TAG_GATHERV, diff --git a/ompi/mca/coll/basic/coll_basic_scatterv.c b/ompi/mca/coll/basic/coll_basic_scatterv.c index d9ea2005de..57aabd248e 100644 --- a/ompi/mca/coll/basic/coll_basic_scatterv.c +++ b/ompi/mca/coll/basic/coll_basic_scatterv.c @@ -53,14 +53,16 @@ mca_coll_basic_scatterv_intra(void *sbuf, int *scounts, rank = ompi_comm_rank(comm); size = ompi_comm_size(comm); - /* If not root, receive data. Note that we will only get here if - * rcount > 0 or rank == root. */ + /* If not root, receive data. */ if (rank != root) { - err = MCA_PML_CALL(recv(rbuf, rcount, rdtype, - root, MCA_COLL_BASE_TAG_SCATTERV, - comm, MPI_STATUS_IGNORE)); - return err; + /* Only receive if there is something to receive */ + if (rcount > 0) { + return MCA_PML_CALL(recv(rbuf, rcount, rdtype, + root, MCA_COLL_BASE_TAG_SCATTERV, + comm, MPI_STATUS_IGNORE)); + } + return MPI_SUCCESS; } /* I am the root, loop sending data. */ @@ -76,19 +78,22 @@ mca_coll_basic_scatterv_intra(void *sbuf, int *scounts, /* simple optimization */ if (i == rank) { - if (0 == scounts[i]) { /* simple optimization or a local operation */ + /* simple optimization or a local operation */ + if (0 == scounts[i]) { continue; } - err = - ompi_ddt_sndrcv(ptmp, scounts[i], sdtype, rbuf, rcount, - rdtype); + err = ompi_ddt_sndrcv(ptmp, scounts[i], sdtype, rbuf, rcount, + rdtype); } else { - err = MCA_PML_CALL(send(ptmp, scounts[i], sdtype, i, - MCA_COLL_BASE_TAG_SCATTERV, - MCA_PML_BASE_SEND_STANDARD, comm)); - } - if (MPI_SUCCESS != err) { - return err; + /* Only send if there is something to send */ + if (scounts[i] > 0) { + err = MCA_PML_CALL(send(ptmp, scounts[i], sdtype, i, + MCA_COLL_BASE_TAG_SCATTERV, + MCA_PML_BASE_SEND_STANDARD, comm)); + if (MPI_SUCCESS != err) { + return err; + } + } } }