From 9a98423bbc97c725a1e977691d8bd103a73200d9 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 3 Sep 2008 08:24:27 +0000 Subject: [PATCH] [Re-]Fix #1463 with a little thing that I like to call "the right way". Don't modify coords in the top-level API function because coords is an IN variable. Instead, as Nysal noted, the real cause of the problem was a missing ! down in topo_base_cart_rank.c. Put a comment down in topo_base_cart_rank.c explaining what's going on so that the code is not so cryptic. Refs trac:1363. This commit was SVN r19487. The following Trac tickets were found above: Ticket 1363 --> https://svn.open-mpi.org/trac/ompi/ticket/1363 --- ompi/mca/topo/base/topo_base_cart_rank.c | 20 ++++++++++++-------- ompi/mpi/c/cart_rank.c | 16 ---------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/ompi/mca/topo/base/topo_base_cart_rank.c b/ompi/mca/topo/base/topo_base_cart_rank.c index 5934960f27..89e270036c 100644 --- a/ompi/mca/topo/base/topo_base_cart_rank.c +++ b/ompi/mca/topo/base/topo_base_cart_rank.c @@ -63,14 +63,18 @@ int mca_topo_base_cart_rank (MPI_Comm comm, for (; i >= 0; --i, --c, --d, --p) { dim = *d; ord = *c; - if ((ord < 0) || (ord >= dim)) { - if (*p) { - return MPI_ERR_ARG; - } - ord %= dim; - if (ord < 0) { - ord += dim; - } + /* Per MPI-2.1 7.5.4 (description of MPI_CART_RANK), if the + dimension is periodic and the coordinate is outside of 0 <= + coord(i) < dim, then normalize it. If the dimension is not + periodic, it's an error. */ + if ((ord < 0) || (ord >= dim)) { + if (!*p) { + return MPI_ERR_ARG; + } + ord %= dim; + if (ord < 0) { + ord += dim; + } } prank += factor * ord; factor *= dim; diff --git a/ompi/mpi/c/cart_rank.c b/ompi/mpi/c/cart_rank.c index 8e82724d67..63c1369c38 100644 --- a/ompi/mpi/c/cart_rank.c +++ b/ompi/mpi/c/cart_rank.c @@ -79,22 +79,6 @@ int MPI_Cart_rank(MPI_Comm comm, int *coords, int *rank) OPAL_CR_ENTER_LIBRARY(); - /* Normalize any coords[i] that is outside the appropriate range - for dimensions that are periodic */ - for (i = 0; i < comm->c_topo_comm->mtc_ndims_or_nnodes; ++i) { - if (comm->c_topo_comm->mtc_periods_or_edges[i] && - (coords[i] < 0 || - coords[i] >= comm->c_topo_comm->mtc_dims_or_index[i])) { - if (coords[i] < 0) { - coords[i] = (-coords[i]) % - comm->c_topo_comm->mtc_dims_or_index[i]; - coords[i] = comm->c_topo_comm->mtc_dims_or_index[i] - coords[i]; - } else { - coords[i] = coords[i] % comm->c_topo_comm->mtc_dims_or_index[i]; - } - } - } - /* get the function pointer on this communicator */ func = comm->c_topo->topo_cart_rank;