1 /* 2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana 3 * University Research and Technology 4 * Corporation. All rights reserved. 5 * Copyright (c) 2004-2013 The University of Tennessee and The University 6 * of Tennessee Research Foundation. All rights 7 * reserved. 8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 9 * University of Stuttgart. All rights reserved. 10 * Copyright (c) 2004-2005 The Regents of the University of California. 11 * All rights reserved. 12 * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. 13 * Copyright (c) 2012-2013 Inria. All rights reserved. 14 * $COPYRIGHT$ 15 * 16 * Additional copyrights may follow 17 * 18 * $HEADER$ 19 */ 20 21 #include "ompi_config.h" 22 #include "ompi/mca/topo/base/base.h" 23 #include "ompi/communicator/communicator.h" 24 25 /* 26 * function - determines process coords in cartesian topology given 27 * rank in group 28 * 29 * @param comm - communicator with cartesian structure (handle) 30 * @param rank - rank of a process within group of 'comm' (integer) 31 * @param maxdims - length of vector 'coords' in the calling program (integer) 32 * @param coords - integer array (of size 'ndims') containing the cartesian 33 * coordinates of specified process (integer) 34 * 35 * @retval MPI_SUCCESS 36 */ 37 38 int mca_topo_base_cart_coords(ompi_communicator_t* comm, 39 int rank, 40 int maxdims, 41 int *coords) 42 { 43 int dim, remprocs, i, *d; 44 45 /* 46 * loop computing the co-ordinates 47 */ 48 d = comm->c_topo->mtc.cart->dims; 49 remprocs = ompi_comm_size(comm); 50 51 for (i = 0; 52 (i < comm->c_topo->mtc.cart->ndims) && (i < maxdims); 53 ++i, ++d) { 54 dim = *d; 55 remprocs /= dim; 56 *coords++ = rank / remprocs; 57 rank %= remprocs; 58 } 59 60 return MPI_SUCCESS; 61 }