Skip to content

Commit 24cf097

Browse files
committed
mpi/neighbor_allgatherv: fix copy&paste error and add helpers
This commit adds a helper function to get the inbound and outbound neighbor count and updates the neighbor_allgatherv bindings to use the correct count when checking the input parameters. Fixes #2324 Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov> (cherry picked from commit 3c0e94a) Signed-off-by: Nathan Hjelm <hjelmn@me.com>
1 parent 25a3465 commit 24cf097

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

ompi/mca/topo/base/base.h

+3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ OMPI_DECLSPEC int
194194
mca_topo_base_dist_graph_neighbors_count(ompi_communicator_t *comm,
195195
int *inneighbors, int *outneighbors, int *weighted);
196196

197+
198+
int mca_topo_base_neighbor_count (ompi_communicator_t *comm, int *indegree, int *outdegree);
199+
197200
END_C_DECLS
198201

199202
#endif /* MCA_BASE_TOPO_H */

ompi/mca/topo/base/topo_base_frame.c

+27
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ static int mca_topo_base_open(mca_base_open_flag_t flags)
7171
return mca_base_framework_components_open(&ompi_topo_base_framework, flags);
7272
}
7373

74+
int mca_topo_base_neighbor_count (ompi_communicator_t *comm, int *indegree, int *outdegree) {
75+
if (!OMPI_COMM_IS_TOPO(comm)) {
76+
return OMPI_ERR_BAD_PARAM;
77+
}
78+
79+
if (OMPI_COMM_IS_CART(comm)) {
80+
/* cartesian */
81+
/* outdegree is always 2*ndims because we need to iterate over
82+
empty buffers for MPI_PROC_NULL */
83+
*outdegree = *indegree = 2 * comm->c_topo->mtc.cart->ndims;
84+
} else if (OMPI_COMM_IS_GRAPH(comm)) {
85+
/* graph */
86+
int rank, nneighbors;
87+
88+
rank = ompi_comm_rank (comm);
89+
mca_topo_base_graph_neighbors_count (comm, rank, &nneighbors);
90+
91+
*outdegree = *indegree = nneighbors;
92+
} else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
93+
/* graph */
94+
*indegree = comm->c_topo->mtc.dist_graph->indegree;
95+
*outdegree = comm->c_topo->mtc.dist_graph->outdegree;
96+
}
97+
98+
return OMPI_SUCCESS;
99+
}
100+
74101
MCA_BASE_FRAMEWORK_DECLARE(ompi, topo, "OMPI Topo", NULL,
75102
mca_topo_base_open, mca_topo_base_close,
76103
mca_topo_base_static_components, 0);

ompi/mpi/c/neighbor_allgatherv.c

+7-28
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2010 University of Houston. All rights reserved.
1414
* Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
15-
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
15+
* Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2015 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
@@ -32,6 +32,7 @@
3232
#include "ompi/communicator/communicator.h"
3333
#include "ompi/errhandler/errhandler.h"
3434
#include "ompi/datatype/ompi_datatype.h"
35+
#include "ompi/mca/topo/base/base.h"
3536
#include "ompi/memchecker.h"
3637
#include "ompi/mca/topo/topo.h"
3738
#include "ompi/mca/topo/base/base.h"
@@ -50,20 +51,20 @@ int MPI_Neighbor_allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sen
5051
void *recvbuf, const int recvcounts[], const int displs[],
5152
MPI_Datatype recvtype, MPI_Comm comm)
5253
{
53-
int i, size, err;
54+
int in_size, out_size, err;
5455

5556
MEMCHECKER(
5657
int rank;
5758
ptrdiff_t ext;
5859

5960
rank = ompi_comm_rank(comm);
60-
size = ompi_comm_size(comm);
61+
mca_topo_base_neighbor_count (comm, &in_size, &out_size);
6162
ompi_datatype_type_extent(recvtype, &ext);
6263

6364
memchecker_datatype(recvtype);
6465
memchecker_comm (comm);
6566
/* check whether the receive buffer is addressable. */
66-
for (i = 0; i < size; i++) {
67+
for (int i = 0; i < in_size; ++i) {
6768
memchecker_call(&opal_memchecker_base_isaddressable,
6869
(char *)(recvbuf)+displs[i]*ext,
6970
recvcounts[i], recvtype);
@@ -107,8 +108,8 @@ int MPI_Neighbor_allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sen
107108
get the size of the remote group here for both intra- and
108109
intercommunicators */
109110

110-
size = ompi_comm_remote_size(comm);
111-
for (i = 0; i < size; ++i) {
111+
mca_topo_base_neighbor_count (comm, &in_size, &out_size);
112+
for (int i = 0; i < in_size; ++i) {
112113
if (recvcounts[i] < 0) {
113114
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
114115
}
@@ -141,27 +142,6 @@ int MPI_Neighbor_allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sen
141142
}
142143
}
143144

144-
/* Do we need to do anything? Everyone had to give the same
145-
signature, which means that everyone must have given a
146-
sum(recvounts) > 0 if there's anything to do. */
147-
148-
if ( OMPI_COMM_IS_INTRA( comm) ) {
149-
for (i = 0; i < ompi_comm_size(comm); ++i) {
150-
if (0 != recvcounts[i]) {
151-
break;
152-
}
153-
}
154-
if (i >= ompi_comm_size(comm)) {
155-
return MPI_SUCCESS;
156-
}
157-
}
158-
/* There is no rule that can be applied for inter-communicators, since
159-
recvcount(s)=0 only indicates that the processes in the other group
160-
do not send anything, sendcount=0 only indicates that I do not send
161-
anything. However, other processes in my group might very well send
162-
something */
163-
164-
165145
OPAL_CR_ENTER_LIBRARY();
166146

167147
/* Invoke the coll component to perform the back-end operation */
@@ -170,4 +150,3 @@ int MPI_Neighbor_allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sen
170150
recvtype, comm, comm->c_coll->coll_neighbor_allgatherv_module);
171151
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
172152
}
173-

0 commit comments

Comments
 (0)