Skip to content

Commit 331650c

Browse files
committed
topo: do not cast way the const modifier when this is not necessary
update the topo framework and mpi c bindings (back-ported from commit open-mpi/ompi@43ef261)
1 parent 3e54a95 commit 331650c

18 files changed

+98
-93
lines changed

ompi/mca/topo/base/base.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1414
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
1515
* Copyright (c) 2012-2013 Inria. All rights reserved.
16-
* Copyright (c) 2014 Research Organization for Information Science
16+
* Copyright (c) 2014-2015 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -73,8 +73,8 @@ OMPI_DECLSPEC int
7373
mca_topo_base_cart_create(mca_topo_base_module_t *topo_module,
7474
ompi_communicator_t* old_comm,
7575
int ndims,
76-
int *dims,
77-
int *periods,
76+
const int *dims,
77+
const int *periods,
7878
bool reorder,
7979
ompi_communicator_t** comm_topo);
8080

@@ -98,11 +98,11 @@ mca_topo_base_cart_get(ompi_communicator_t *comm,
9898
OMPI_DECLSPEC int
9999
mca_topo_base_cart_map(ompi_communicator_t * comm,
100100
int ndims,
101-
int *dims, int *periods, int *newrank);
101+
const int *dims, const int *periods, int *newrank);
102102

103103
OMPI_DECLSPEC int
104104
mca_topo_base_cart_rank(ompi_communicator_t *comm,
105-
int *coords,
105+
const int *coords,
106106
int *rank);
107107

108108
OMPI_DECLSPEC int
@@ -114,7 +114,7 @@ mca_topo_base_cart_shift(ompi_communicator_t *comm,
114114

115115
OMPI_DECLSPEC int
116116
mca_topo_base_cart_sub(ompi_communicator_t *comm,
117-
int *remain_dims,
117+
const int *remain_dims,
118118
ompi_communicator_t **new_comm);
119119

120120
OMPI_DECLSPEC int
@@ -126,8 +126,8 @@ OMPI_DECLSPEC int
126126
mca_topo_base_graph_create(mca_topo_base_module_t *topo_module,
127127
ompi_communicator_t* old_comm,
128128
int nnodes,
129-
int *index,
130-
int *edges,
129+
const int *index,
130+
const int *edges,
131131
bool reorder,
132132
ompi_communicator_t** new_comm);
133133

@@ -141,7 +141,7 @@ mca_topo_base_graph_get(ompi_communicator_t *comm,
141141
OMPI_DECLSPEC int
142142
mca_topo_base_graph_map(ompi_communicator_t * comm,
143143
int nnodes,
144-
int *index, int *edges, int *newrank);
144+
const int *index, const int *edges, int *newrank);
145145

146146
OMPI_DECLSPEC int
147147
mca_topo_base_graph_neighbors(ompi_communicator_t *comm,
@@ -161,25 +161,25 @@ mca_topo_base_graph_neighbors_count(ompi_communicator_t *comm,
161161
OMPI_DECLSPEC int
162162
mca_topo_base_dist_graph_distribute(mca_topo_base_module_t* module,
163163
ompi_communicator_t *comm,
164-
int n, int nodes[],
165-
int degrees[], int targets[],
166-
int weights[],
164+
int n, const int nodes[],
165+
const int degrees[], const int targets[],
166+
const int weights[],
167167
mca_topo_base_comm_dist_graph_2_2_0_t** ptopo);
168168

169169
OMPI_DECLSPEC int
170170
mca_topo_base_dist_graph_create(mca_topo_base_module_t* module,
171171
ompi_communicator_t *old_comm,
172-
int n, int nodes[],
173-
int degrees[], int targets[], int weights[],
172+
int n, const int nodes[],
173+
const int degrees[], const int targets[], const int weights[],
174174
ompi_info_t *info, int reorder,
175175
ompi_communicator_t **new_comm);
176176

177177
OMPI_DECLSPEC int
178178
mca_topo_base_dist_graph_create_adjacent(mca_topo_base_module_t* module,
179179
ompi_communicator_t *old_comm,
180-
int indegree, int sources[],
181-
int sourceweights[], int outdegree,
182-
int destinations[], int destweights[],
180+
int indegree, const int sources[],
181+
const int sourceweights[], int outdegree,
182+
const int destinations[], const int destweights[],
183183
ompi_info_t *info, int reorder,
184184
ompi_communicator_t **comm_dist_graph);
185185

ompi/mca/topo/base/topo_base_cart_create.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
int mca_topo_base_cart_create(mca_topo_base_module_t *topo,
5151
ompi_communicator_t* old_comm,
5252
int ndims,
53-
int *dims,
54-
int *periods,
53+
const int *dims,
54+
const int *periods,
5555
bool reorder,
5656
ompi_communicator_t** comm_topo)
5757
{
58-
int nprocs = 1, i, *p, new_rank, num_procs, ret;
58+
int nprocs = 1, i, new_rank, num_procs, ret;
5959
ompi_communicator_t *new_comm;
6060
ompi_proc_t **topo_procs = NULL;
6161
mca_topo_base_comm_cart_2_2_0_t* cart;
@@ -65,12 +65,11 @@ int mca_topo_base_cart_create(mca_topo_base_module_t *topo,
6565
assert(topo->type == OMPI_COMM_CART);
6666

6767
/* Calculate the number of processes in this grid */
68-
p = dims;
69-
for (i = 0; i < ndims; ++i, ++p) {
70-
if(*p <= 0) {
68+
for (i = 0; i < ndims; ++i) {
69+
if(dims[i] <= 0) {
7170
return OMPI_ERROR;
7271
}
73-
nprocs *= *p;
72+
nprocs *= dims[i];
7473
}
7574

7675
/* check for the error condition */

ompi/mca/topo/base/topo_base_cart_map.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12+
* Copyright (c) 2015 Research Organization for Information Science
13+
* and Technology (RIST). All rights reserved.
1214
* $COPYRIGHT$
1315
*
1416
* Additional copyrights may follow
@@ -38,19 +40,19 @@
3840

3941
int mca_topo_base_cart_map(ompi_communicator_t* comm,
4042
int ndims,
41-
int *dims, int *periods, int *newrank)
43+
const int *dims, const int *periods, int *newrank)
4244
{
43-
int nprocs, rank, size, i, *p;
45+
int nprocs, rank, size, i;
4446

4547
/*
4648
* Compute the # of processes in the grid.
4749
*/
4850
nprocs = 1;
49-
for (i = 0, p = dims; i < ndims; ++i, ++p) {
50-
if (*p <= 0) {
51+
for (i = 0 ; i < ndims; ++i) {
52+
if (dims[i] <= 0) {
5153
return MPI_ERR_DIMS;
5254
}
53-
nprocs *= *p;
55+
nprocs *= dims[i];
5456
}
5557
/*
5658
* Check that number of processes <= size of communicator.

ompi/mca/topo/base/topo_base_cart_rank.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* All rights reserved.
1212
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2012-2013 Inria. All rights reserved.
14+
* Copyright (c) 2015 Research Organization for Information Science
15+
* and Technology (RIST). All rights reserved.
1416
* $COPYRIGHT$
1517
*
1618
* Additional copyrights may follow
@@ -38,7 +40,7 @@
3840
*/
3941

4042
int mca_topo_base_cart_rank(ompi_communicator_t* comm,
41-
int *coords,
43+
const int *coords,
4244
int *rank)
4345
{
4446
int prank;
@@ -47,7 +49,6 @@ int mca_topo_base_cart_rank(ompi_communicator_t* comm,
4749
int factor;
4850
int i;
4951
int *d;
50-
int *c;
5152

5253
/*
5354
* Loop over coordinates computing the rank.
@@ -57,11 +58,10 @@ int mca_topo_base_cart_rank(ompi_communicator_t* comm,
5758

5859
i = comm->c_topo->mtc.cart->ndims - 1;
5960
d = comm->c_topo->mtc.cart->dims + i;
60-
c = coords + i;
6161

62-
for (; i >= 0; --i, --c, --d) {
62+
for (; i >= 0; --i, --d) {
6363
dim = *d;
64-
ord = *c;
64+
ord = coords[i];
6565
/* Per MPI-2.1 7.5.4 (description of MPI_CART_RANK), if the
6666
dimension is periodic and the coordinate is outside of 0 <=
6767
coord(i) < dim, then normalize it. If the dimension is not

ompi/mca/topo/base/topo_base_cart_sub.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
* @retval MPI_ERR_COMM
4444
*/
4545
int mca_topo_base_cart_sub (ompi_communicator_t* comm,
46-
int *remain_dims,
46+
const int *remain_dims,
4747
ompi_communicator_t** new_comm)
4848
{
4949
struct ompi_communicator_t *temp_comm;
5050
mca_topo_base_comm_cart_2_2_0_t *old_cart;
5151
int errcode, colour, key, colfactor, keyfactor;
5252
int ndim, dim, i;
53-
int *d, *dorig = NULL, *dold, *c, *r, *p, *porig = NULL, *pold;
53+
int *d, *dorig = NULL, *dold, *c, *p, *porig = NULL, *pold;
5454
mca_topo_base_module_t* topo;
5555
mca_topo_base_comm_cart_2_2_0_t* cart;
5656

@@ -67,11 +67,10 @@ int mca_topo_base_cart_sub (ompi_communicator_t* comm,
6767
i = old_cart->ndims - 1;
6868
d = old_cart->dims + i;
6969
c = comm->c_topo->mtc.cart->coords + i;
70-
r = remain_dims + i;
7170

72-
for (; i >= 0; --i, --d, --c, --r) {
71+
for (; i >= 0; --i, --d, --c) {
7372
dim = *d;
74-
if (*r == 0) {
73+
if (remain_dims[i] == 0) {
7574
colour += colfactor * (*c);
7675
colfactor *= dim;
7776
} else {
@@ -110,9 +109,8 @@ int mca_topo_base_cart_sub (ompi_communicator_t* comm,
110109
/* Copy the periods */
111110
porig = p = (int*)malloc(ndim * sizeof(int));
112111
pold = old_cart->periods;
113-
r = remain_dims;
114-
for (i = 0; i < old_cart->ndims; ++i, ++dold, ++pold, ++r) {
115-
if (*r) {
112+
for (i = 0; i < old_cart->ndims; ++i, ++dold, ++pold) {
113+
if (remain_dims[i]) {
116114
*d++ = *dold;
117115
*p++ = *pold;
118116
}

ompi/mca/topo/base/topo_base_dist_graph_create.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ typedef struct _dist_graph_elem {
3333

3434
int mca_topo_base_dist_graph_distribute(mca_topo_base_module_t* module,
3535
ompi_communicator_t *comm,
36-
int n, int nodes[],
37-
int degrees[], int targets[],
38-
int weights[],
36+
int n, const int nodes[],
37+
const int degrees[], const int targets[],
38+
const int weights[],
3939
mca_topo_base_comm_dist_graph_2_2_0_t** ptopo)
4040
{
4141
int i, j, err, count, left_over, pending_reqs, current_pos, index, csize;
@@ -280,9 +280,9 @@ int mca_topo_base_dist_graph_distribute(mca_topo_base_module_t* module,
280280

281281
int mca_topo_base_dist_graph_create(mca_topo_base_module_t* module,
282282
ompi_communicator_t *comm_old,
283-
int n, int nodes[],
284-
int degrees[], int targets[],
285-
int weights[],
283+
int n, const int nodes[],
284+
const int degrees[], const int targets[],
285+
const int weights[],
286286
ompi_info_t *info, int reorder,
287287
ompi_communicator_t **newcomm)
288288
{

ompi/mca/topo/base/topo_base_dist_graph_create_adjacent.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
int mca_topo_base_dist_graph_create_adjacent(mca_topo_base_module_t* module,
2323
ompi_communicator_t *comm_old,
24-
int indegree, int sources[],
25-
int sourceweights[],
24+
int indegree, const int sources[],
25+
const int sourceweights[],
2626
int outdegree,
27-
int destinations[],
28-
int destweights[],
27+
const int destinations[],
28+
const int destweights[],
2929
ompi_info_t *info, int reorder,
3030
ompi_communicator_t **newcomm)
3131
{

ompi/mca/topo/base/topo_base_graph_create.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
int mca_topo_base_graph_create(mca_topo_base_module_t *topo,
4444
ompi_communicator_t* old_comm,
4545
int nnodes,
46-
int *index,
47-
int *edges,
46+
const int *index,
47+
const int *edges,
4848
bool reorder,
4949
ompi_communicator_t** comm_topo)
5050
{

ompi/mca/topo/base/topo_base_graph_map.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2012-2013 Inria. All rights reserved.
13+
* Copyright (c) 2015 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -38,7 +40,7 @@
3840

3941
int mca_topo_base_graph_map(ompi_communicator_t * comm,
4042
int nnodes,
41-
int *index, int *edges, int *newrank)
43+
const int *index, const int *edges, int *newrank)
4244
{
4345
int myrank;
4446

0 commit comments

Comments
 (0)