Skip to content

Commit e8c103a

Browse files
committed
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.
1 parent 6a7bd04 commit e8c103a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ompi/mpi/c/reduce.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ int MPI_Reduce(void *sendbuf, void *recvbuf, int count,
7171
}
7272
}
7373

74+
/* MPI-1, p114, says that each process must supply at least
75+
one element. But at least the Pallas benchmarks call
76+
MPI_REDUCE with a count of 0. So be sure to handle it. */
77+
78+
if (0 == count) {
79+
return MPI_SUCCESS;
80+
}
81+
7482
/* Invoke the coll component to perform the back-end operation */
7583

7684
err = comm->c_coll.coll_reduce(sendbuf, recvbuf, count,

ompi/mpi/c/reduce_scatter.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const char FUNC_NAME[] = "MPI_Reduce_scatter";
3838
int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
3939
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
4040
{
41-
int i, err, size;
41+
int i, err, size, count;
4242

4343
if (MPI_PARAM_CHECK) {
4444
err = MPI_SUCCESS;
@@ -67,13 +67,27 @@ int MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
6767
get the size of the remote group here for both intra- and
6868
intercommunicators */
6969

70-
size = ompi_comm_remote_size(comm);
70+
size = ompi_comm_size(comm);
7171
for (i = 0; i < size; ++i) {
7272
OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, recvcounts[i]);
7373
OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
7474
}
7575
}
7676

77+
/* MPI-1, p114, says that each process must supply at least one
78+
element. But at least the Pallas benchmarks call MPI_REDUCE
79+
with a count of 0. So be sure to handle it. Grrr... */
80+
81+
size = ompi_comm_size(comm);
82+
for (count = i = 0; i < size; ++i) {
83+
if (0 == recvcounts[i]) {
84+
++count;
85+
}
86+
}
87+
if (size == count) {
88+
return MPI_SUCCESS;
89+
}
90+
7791
/* Invoke the coll component to perform the back-end operation */
7892

7993
err = comm->c_coll.coll_reduce_scatter(sendbuf, recvbuf, recvcounts,

0 commit comments

Comments
 (0)