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) 2009 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/example/topo_example.h" 23 24 #include "ompi/communicator/communicator.h" 25 26 /* 27 * function - mca_topo_example_cart_map 28 * 29 * @param comm input communicator (handle) 30 * @param ndims number of dimensions of cartesian structure (integer) 31 * @param dims integer array of size 'ndims' specifying the number of 32 * processes in each coordinate direction 33 * @param periods logical array of size 'ndims' specifying the 34 * periodicity specification in each coordinate direction 35 * @param newrank reordered rank of the calling process; 'MPI_UNDEFINED' 36 * if calling process does not belong to grid (integer) 37 * 38 * @retval MPI_SUCCESS 39 * @retval MPI_ERR_DIMS 40 */ 41 42 int mca_topo_example_cart_map (ompi_communicator_t* comm, 43 int ndims, 44 int *dims, 45 int *periods, 46 int *newrank) 47 { 48 int nprocs; 49 int rank; 50 int size; 51 int i; 52 int *p; 53 54 /* 55 * Compute the # of processes in the grid. 56 */ 57 nprocs = 1; 58 for (i = 0, p = dims; i < ndims; ++i, ++p) { 59 if (*p <= 0) { 60 return MPI_ERR_DIMS; 61 } 62 nprocs *= *p; 63 } 64 /* 65 * Check that number of processes <= size of communicator. 66 */ 67 size = ompi_comm_size(comm); 68 if (nprocs > size) { 69 return MPI_ERR_DIMS; 70 } 71 /* 72 * Compute my new rank. To be slightly different than the "unity" 73 * component, start with a rank that is size-my_initial_rank. 74 */ 75 rank = ompi_comm_size(comm) - 1 - ompi_comm_rank(comm); 76 *newrank = ((rank < 0) || (rank >= nprocs)) ? MPI_UNDEFINED : rank; 77 78 return MPI_SUCCESS; 79 }