From db0414715446cf6620656cce75ba997c3cc5a320 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Thu, 30 Sep 2004 15:56:08 +0000 Subject: [PATCH] Don't invoke back-end coll functions if the count is zero (ddt functions don't behave well when called with 0 counts) This commit was SVN r2889. --- src/mpi/c/allgather.c | 8 ++++++++ src/mpi/c/gatherv.c | 6 ++++++ src/mpi/c/scatter.c | 7 +++++++ src/mpi/c/scatterv.c | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/src/mpi/c/allgather.c b/src/mpi/c/allgather.c index a33d215f57..962d7db0aa 100644 --- a/src/mpi/c/allgather.c +++ b/src/mpi/c/allgather.c @@ -46,6 +46,14 @@ int MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype, OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME); } + /* Can we optimize? Everyone had to give the same send signature, + which means that everyone must have given a sendcount > 0 if + there's anything to send. */ + + if (sendcount == 0) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_allgather(sendbuf, sendcount, sendtype, diff --git a/src/mpi/c/gatherv.c b/src/mpi/c/gatherv.c index 0db2a8a6fb..49474adb95 100644 --- a/src/mpi/c/gatherv.c +++ b/src/mpi/c/gatherv.c @@ -114,6 +114,12 @@ int MPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, } } + /* If we have nothing to do, just return */ + + if (0 == sendcount && ompi_comm_rank(comm) != root) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_gatherv(sendbuf, sendcount, sendtype, recvbuf, diff --git a/src/mpi/c/scatter.c b/src/mpi/c/scatter.c index c5f69a9f2d..e00987969b 100644 --- a/src/mpi/c/scatter.c +++ b/src/mpi/c/scatter.c @@ -90,6 +90,13 @@ int MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, } } + /* If we have nothing to receive, return success (everyone must + have given the same recvcount) */ + + if (0 == recvcount) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_scatter(sendbuf, sendcount, sendtype, recvbuf, diff --git a/src/mpi/c/scatterv.c b/src/mpi/c/scatterv.c index dad40dbe2a..8d8eec60a9 100644 --- a/src/mpi/c/scatterv.c +++ b/src/mpi/c/scatterv.c @@ -118,6 +118,12 @@ int MPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, } } + /* If we have nothing to do, just return */ + + if (0 == recvcount && ompi_comm_rank(comm) != root) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_scatterv(sendbuf, sendcounts, displs, sendtype,