2013-09-26 21:56:20 +00:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2004-01-21 00:05:46 +00:00
|
|
|
/*
|
2007-03-16 23:11:45 +00:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2005-11-05 19:57:48 +00:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2014-05-16 22:23:52 +00:00
|
|
|
* Copyright (c) 2004-2013 The University of Tennessee and The University
|
2005-11-05 19:57:48 +00:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-23 20:59:57 -07:00
|
|
|
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
|
2004-11-28 20:09:25 +00:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2015-02-24 12:44:27 -05:00
|
|
|
* Copyright (c) 2007-2015 Cisco Systems, Inc. All rights reserved.
|
2013-09-26 21:56:20 +00:00
|
|
|
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
|
2015-06-23 20:59:57 -07:00
|
|
|
* reserved.
|
2014-05-16 22:23:52 +00:00
|
|
|
* Copyright (c) 2012-2013 Inria. All rights reserved.
|
2014-05-13 04:49:23 +00:00
|
|
|
* Copyright (c) 2014 Research Organization for Information Science
|
|
|
|
* and Technology (RIST). All rights reserved.
|
2004-11-22 01:38:40 +00:00
|
|
|
* $COPYRIGHT$
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2004-11-22 01:38:40 +00:00
|
|
|
* Additional copyrights may follow
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2004-10-15 19:31:47 +00:00
|
|
|
* $HEADER$
|
2004-01-21 00:05:46 +00:00
|
|
|
*/
|
2004-06-07 15:33:53 +00:00
|
|
|
#include "ompi_config.h"
|
2004-01-21 00:05:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "ompi/mpi/c/bindings.h"
|
2009-04-29 01:32:14 +00:00
|
|
|
#include "ompi/runtime/params.h"
|
|
|
|
#include "ompi/communicator/communicator.h"
|
|
|
|
#include "ompi/errhandler/errhandler.h"
|
2005-09-12 09:17:44 +00:00
|
|
|
#include "ompi/mca/topo/topo.h"
|
2008-02-12 18:01:17 +00:00
|
|
|
#include "ompi/memchecker.h"
|
2004-01-21 00:05:46 +00:00
|
|
|
|
2009-05-06 20:11:28 +00:00
|
|
|
#if OPAL_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-21 00:05:46 +00:00
|
|
|
#pragma weak MPI_Cart_rank = PMPI_Cart_rank
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 15:33:53 +00:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2006-02-12 01:33:29 +00:00
|
|
|
#include "ompi/mpi/c/profile/defines.h"
|
2004-04-20 18:50:43 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-30 02:58:53 +00:00
|
|
|
static const char FUNC_NAME[] = "MPI_Cart_rank";
|
|
|
|
|
2013-09-26 21:56:20 +00:00
|
|
|
int MPI_Cart_rank(MPI_Comm comm, const int coords[], int *rank)
|
2004-08-02 00:24:22 +00:00
|
|
|
{
|
2008-08-31 18:39:05 +00:00
|
|
|
int i, err;
|
2008-02-19 22:15:52 +00:00
|
|
|
|
2008-02-12 08:46:27 +00:00
|
|
|
MEMCHECKER(
|
|
|
|
memchecker_comm(comm);
|
|
|
|
);
|
2007-03-16 23:11:45 +00:00
|
|
|
|
2004-04-21 20:55:54 +00:00
|
|
|
/* check the arguments */
|
|
|
|
if (MPI_PARAM_CHECK) {
|
2014-05-13 04:49:23 +00:00
|
|
|
mca_topo_base_comm_cart_2_2_0_t* cart;
|
2004-07-30 02:58:53 +00:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2007-03-21 11:10:42 +00:00
|
|
|
if (ompi_comm_invalid(comm)) {
|
2004-06-07 15:33:53 +00:00
|
|
|
return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_COMM,
|
2004-07-30 02:58:53 +00:00
|
|
|
FUNC_NAME);
|
2004-04-21 20:55:54 +00:00
|
|
|
}
|
2015-06-23 20:59:57 -07:00
|
|
|
if (OMPI_COMM_IS_INTER(comm)) {
|
2005-04-19 00:45:29 +00:00
|
|
|
return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_COMM,
|
2004-07-30 02:58:53 +00:00
|
|
|
FUNC_NAME);
|
2004-04-21 20:55:54 +00:00
|
|
|
}
|
2015-02-24 12:44:27 -05:00
|
|
|
|
|
|
|
/* Need this check here to protect the access to "cart",
|
|
|
|
below. I.e., if OMPI_COMM_IS_CART is true, then cart is
|
|
|
|
guaranteed to be != NULL. */
|
|
|
|
if (!OMPI_COMM_IS_CART(comm)) {
|
|
|
|
return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_TOPOLOGY,
|
|
|
|
FUNC_NAME);
|
|
|
|
}
|
|
|
|
|
2013-07-01 12:40:08 +00:00
|
|
|
cart = comm->c_topo->mtc.cart;
|
2008-08-31 19:31:10 +00:00
|
|
|
/* Per MPI-2.1, coords is only relevant if the dimension of
|
|
|
|
the cartesian comm is >0 */
|
2013-07-01 12:40:08 +00:00
|
|
|
if (((NULL == coords) &&
|
|
|
|
(cart->ndims >= 1)) ||
|
2008-08-31 19:31:10 +00:00
|
|
|
(NULL == rank)){
|
2005-04-19 00:45:29 +00:00
|
|
|
return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_ARG,
|
2004-07-30 02:58:53 +00:00
|
|
|
FUNC_NAME);
|
2004-04-21 20:55:54 +00:00
|
|
|
}
|
2008-08-31 18:39:05 +00:00
|
|
|
|
|
|
|
/* Check if coords[i] is within the acceptable range if
|
|
|
|
dimension i is not periodic */
|
2013-07-01 12:40:08 +00:00
|
|
|
for (i = 0; i < cart->ndims; ++i) {
|
|
|
|
if (!cart->periods[i] &&
|
2015-06-23 20:59:57 -07:00
|
|
|
(coords[i] < 0 ||
|
2013-07-01 12:40:08 +00:00
|
|
|
coords[i] >= cart->dims[i])) {
|
2008-08-31 18:39:05 +00:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
|
|
|
|
}
|
|
|
|
}
|
2015-02-24 12:44:27 -05:00
|
|
|
} else {
|
|
|
|
/* Need to always test for cartesian communicators, even in
|
|
|
|
the !MPI_PARAM_CHECK case. */
|
|
|
|
if (!OMPI_COMM_IS_CART(comm)) {
|
|
|
|
return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_TOPOLOGY,
|
|
|
|
FUNC_NAME);
|
|
|
|
}
|
2013-07-01 12:40:08 +00:00
|
|
|
}
|
2008-02-19 22:15:52 +00:00
|
|
|
OPAL_CR_ENTER_LIBRARY();
|
|
|
|
|
2013-09-26 21:56:20 +00:00
|
|
|
/* XXX -- CONST -- do not cast away const -- update mca/topo */
|
|
|
|
err = comm->c_topo->topo.cart.cart_rank(comm, (int *) coords, rank);
|
2008-02-19 22:15:52 +00:00
|
|
|
OPAL_CR_EXIT_LIBRARY();
|
2004-04-21 20:55:54 +00:00
|
|
|
|
2013-07-01 12:40:08 +00:00
|
|
|
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
|
2004-01-21 00:05:46 +00:00
|
|
|
}
|