Skip to content

Commit 81ce89c

Browse files
authored
Merge pull request #3864 from hjelmn/v2.x_neighbor_fix
mpi/neighbor_allgatherv: fix copy&paste error and add helpers
2 parents 7e9bd8a + 132e3c4 commit 81ce89c

10 files changed

+54
-186
lines changed

ompi/communicator/Makefile.am

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# University of Stuttgart. All rights reserved.
1111
# Copyright (c) 2004-2005 The Regents of the University of California.
1212
# All rights reserved.
13-
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights
13+
# Copyright (c) 2013-2017 Los Alamos National Security, LLC. All rights
1414
# reserved.
1515
# Copyright (c) 2014 Research Organization for Information Science
1616
# and Technology (RIST). All rights reserved.
@@ -26,13 +26,11 @@
2626

2727
headers += \
2828
communicator/communicator.h \
29-
communicator/comm_request.h \
30-
communicator/comm_helpers.h
29+
communicator/comm_request.h
3130

3231
lib@OMPI_LIBMPI_NAME@_la_SOURCES += \
3332
communicator/comm_init.c \
3433
communicator/comm.c \
3534
communicator/comm_cid.c \
36-
communicator/comm_request.c \
37-
communicator/comm_helpers.c
35+
communicator/comm_request.c
3836

ompi/communicator/comm_helpers.c

-92
This file was deleted.

ompi/communicator/comm_helpers.h

-41
This file was deleted.

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

+25
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ 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_CART(comm)) {
76+
/* cartesian */
77+
/* outdegree is always 2*ndims because we need to iterate over
78+
empty buffers for MPI_PROC_NULL */
79+
*outdegree = *indegree = 2 * comm->c_topo->mtc.cart->ndims;
80+
} else if (OMPI_COMM_IS_GRAPH(comm)) {
81+
/* graph */
82+
int rank, nneighbors;
83+
84+
rank = ompi_comm_rank (comm);
85+
mca_topo_base_graph_neighbors_count (comm, rank, &nneighbors);
86+
87+
*outdegree = *indegree = nneighbors;
88+
} else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
89+
/* graph */
90+
*indegree = comm->c_topo->mtc.dist_graph->indegree;
91+
*outdegree = comm->c_topo->mtc.dist_graph->outdegree;
92+
} else {
93+
return OMPI_ERR_BAD_PARAM;
94+
}
95+
96+
return OMPI_SUCCESS;
97+
}
98+
7499
MCA_BASE_FRAMEWORK_DECLARE(ompi, topo, "OMPI Topo", NULL,
75100
mca_topo_base_open, mca_topo_base_close,
76101
mca_topo_base_static_components, 0);

ompi/mpi/c/ineighbor_alltoallv.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2014-2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
@@ -29,7 +29,6 @@
2929
#include "ompi/mpi/c/bindings.h"
3030
#include "ompi/runtime/params.h"
3131
#include "ompi/communicator/communicator.h"
32-
#include "ompi/communicator/comm_helpers.h"
3332
#include "ompi/errhandler/errhandler.h"
3433
#include "ompi/datatype/ompi_datatype.h"
3534
#include "ompi/memchecker.h"
@@ -52,7 +51,7 @@ int MPI_Ineighbor_alltoallv(const void *sendbuf, const int sendcounts[], const i
5251
MPI_Request *request)
5352
{
5453
int i, err;
55-
int indegree, outdegree, weighted;
54+
int indegree, outdegree;
5655

5756
MEMCHECKER(
5857
ptrdiff_t recv_ext;
@@ -68,7 +67,7 @@ int MPI_Ineighbor_alltoallv(const void *sendbuf, const int sendcounts[], const i
6867
memchecker_datatype(recvtype);
6968
ompi_datatype_type_extent(sendtype, &send_ext);
7069

71-
err = ompi_comm_neighbors_count(comm, &indegree, &outdegree, &weighted);
70+
err = mca_topo_base_neighbor_count (comm, &indegree, &outdegree);
7271
if (MPI_SUCCESS == err) {
7372
if (MPI_IN_PLACE != sendbuf) {
7473
for ( i = 0; i < outdegree; i++ ) {
@@ -105,7 +104,7 @@ int MPI_Ineighbor_alltoallv(const void *sendbuf, const int sendcounts[], const i
105104
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
106105
}
107106

108-
err = ompi_comm_neighbors_count(comm, &indegree, &outdegree, &weighted);
107+
err = mca_topo_base_neighbor_count (comm, &indegree, &outdegree);
109108
OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
110109
for (i = 0; i < outdegree; ++i) {
111110
OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtype, sendcounts[i]);

ompi/mpi/c/ineighbor_alltoallw.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2014-2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
@@ -29,7 +29,6 @@
2929
#include "ompi/mpi/c/bindings.h"
3030
#include "ompi/runtime/params.h"
3131
#include "ompi/communicator/communicator.h"
32-
#include "ompi/communicator/comm_helpers.h"
3332
#include "ompi/errhandler/errhandler.h"
3433
#include "ompi/datatype/ompi_datatype.h"
3534
#include "ompi/memchecker.h"
@@ -52,15 +51,15 @@ int MPI_Ineighbor_alltoallw(const void *sendbuf, const int sendcounts[], const M
5251
MPI_Request *request)
5352
{
5453
int i, err;
55-
int indegree, outdegree, weighted;
54+
int indegree, outdegree;
5655

5756
MEMCHECKER(
5857
ptrdiff_t recv_ext;
5958
ptrdiff_t send_ext;
6059

6160
memchecker_comm(comm);
6261

63-
err = ompi_comm_neighbors_count(comm, &indegree, &outdegree, &weighted);
62+
err = mca_topo_base_neighbor_count (comm, &indegree, &outdegree);
6463
if (MPI_SUCCESS == err) {
6564
if (MPI_IN_PLACE != sendbuf) {
6665
for ( i = 0; i < outdegree; i++ ) {
@@ -103,7 +102,7 @@ int MPI_Ineighbor_alltoallw(const void *sendbuf, const int sendcounts[], const M
103102
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
104103
}
105104

106-
err = ompi_comm_neighbors_count(comm, &indegree, &outdegree, &weighted);
105+
err = mca_topo_base_neighbor_count (comm, &indegree, &outdegree);
107106
OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
108107
for (i = 0; i < outdegree; ++i) {
109108
OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtypes[i], sendcounts[i]);

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,31 +142,9 @@ 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
/* Invoke the coll component to perform the back-end operation */
166146
err = comm->c_coll.coll_neighbor_allgatherv(sendbuf, sendcount, sendtype,
167147
recvbuf, recvcounts, displs,
168148
recvtype, comm, comm->c_coll.coll_neighbor_allgatherv_module);
169149
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
170150
}
171-

0 commit comments

Comments
 (0)