From e8c103ac1f3f7248ff5ba9ecf60fb32375b6e320 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 17 Aug 2005 15:34:33 +0000 Subject: [PATCH] Make MPI_REDUCE and MPI_REDUCE_SCATTER return MPI_SUCCESS immediately if the count/sum of counts is 0. This is technically in violation of the MPI-1 standard, but... :-( This commit was SVN r6914. --- ompi/mpi/c/reduce.c | 8 ++++++++ ompi/mpi/c/reduce_scatter.c | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ompi/mpi/c/reduce.c b/ompi/mpi/c/reduce.c index f9592e187f..dc32d28d0e 100644 --- a/ompi/mpi/c/reduce.c +++ b/ompi/mpi/c/reduce.c @@ -71,6 +71,14 @@ int MPI_Reduce(void *sendbuf, void *recvbuf, int count, } } + /* MPI-1, p114, says that each process must supply at least + one element. But at least the Pallas benchmarks call + MPI_REDUCE with a count of 0. So be sure to handle it. */ + + if (0 == count) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_reduce(sendbuf, recvbuf, count, diff --git a/ompi/mpi/c/reduce_scatter.c b/ompi/mpi/c/reduce_scatter.c index 9d8740e7de..e8e009fc60 100644 --- a/ompi/mpi/c/reduce_scatter.c +++ b/ompi/mpi/c/reduce_scatter.c @@ -38,7 +38,7 @@ static const char FUNC_NAME[] = "MPI_Reduce_scatter"; int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { - int i, err, size; + int i, err, size, count; if (MPI_PARAM_CHECK) { err = MPI_SUCCESS; @@ -67,13 +67,27 @@ int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, get the size of the remote group here for both intra- and intercommunicators */ - size = ompi_comm_remote_size(comm); + size = ompi_comm_size(comm); for (i = 0; i < size; ++i) { OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, recvcounts[i]); OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME); } } + /* MPI-1, p114, says that each process must supply at least one + element. But at least the Pallas benchmarks call MPI_REDUCE + with a count of 0. So be sure to handle it. Grrr... */ + + size = ompi_comm_size(comm); + for (count = i = 0; i < size; ++i) { + if (0 == recvcounts[i]) { + ++count; + } + } + if (size == count) { + return MPI_SUCCESS; + } + /* Invoke the coll component to perform the back-end operation */ err = comm->c_coll.coll_reduce_scatter(sendbuf, recvbuf, recvcounts,