1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Inria. All rights reserved.
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2014-2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "ompi/mca/topo/base/base.h"
#include "ompi/communicator/communicator.h"
/*
* function - partitions a communicator into subgroups which
* form lower-dimensional cartesian subgrids
*
* @param comm communicator with cartesian structure (handle)
* @param remain_dims the 'i'th entry of 'remain_dims' specifies whether
* the 'i'th dimension is kept in the subgrid (true)
* or is dropped (false) (logical vector)
* @param new_comm communicator containing the subgrid that includes the
* calling process (handle)
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_TOPOLOGY
* @retval MPI_ERR_COMM
*/
int mca_topo_base_cart_sub (ompi_communicator_t* comm,
const int *remain_dims,
ompi_communicator_t** new_comm)
{
struct ompi_communicator_t *temp_comm;
mca_topo_base_comm_cart_2_2_0_t *old_cart;
int errcode, colour, key, colfactor, keyfactor;
int ndim, dim, i;
int *d, *dorig = NULL, *dold, *c, *p, *porig = NULL, *pold;
mca_topo_base_module_t* topo;
mca_topo_base_comm_cart_2_2_0_t* cart;
*new_comm = MPI_COMM_NULL;
old_cart = comm->c_topo->mtc.cart;
/*
* Compute colour and key used in splitting the communicator.
*/
colour = key = 0;
colfactor = keyfactor = 1;
ndim = 0;
i = old_cart->ndims - 1;
d = old_cart->dims + i;
c = comm->c_topo->mtc.cart->coords + i;
for (; i >= 0; --i, --d, --c) {
dim = *d;
if (remain_dims[i] == 0) {
colour += colfactor * (*c);
colfactor *= dim;
} else {
++ndim;
key += keyfactor * (*c);
keyfactor *= dim;
}
}
/* Special case: if all of remain_dims were false, we need to make
a 0-dimension cartesian communicator with just ourselves in it
(you can't have a communicator unless you're in it). */
if (0 == ndim) {
colour = ompi_comm_rank (comm);
}
/* Split the communicator. */
errcode = ompi_comm_split(comm, colour, key, &temp_comm, false);
if (errcode != OMPI_SUCCESS) {
return errcode;
}
/* Fill the communicator with topology information. */
if (temp_comm != MPI_COMM_NULL) {
assert( NULL == temp_comm->c_topo );
if (OMPI_SUCCESS != (errcode = mca_topo_base_comm_select(temp_comm,
comm->c_topo,
&topo,
OMPI_COMM_CART))) {
ompi_comm_free(&temp_comm);
return OMPI_ERR_OUT_OF_RESOURCE;
}
if (ndim >= 1) {
/* Copy the dimensions */
dorig = d = (int*)malloc(ndim * sizeof(int));
dold = old_cart->dims;
/* Copy the periods */
porig = p = (int*)malloc(ndim * sizeof(int));
pold = old_cart->periods;
for (i = 0; i < old_cart->ndims; ++i, ++dold, ++pold) {
if (remain_dims[i]) {
*d++ = *dold;
*p++ = *pold;
}
}
}
cart = OBJ_NEW(mca_topo_base_comm_cart_2_2_0_t);
if( NULL == cart ) {
ompi_comm_free(&temp_comm);
if (NULL != dorig) {
free(dorig);
}
if (NULL != porig) {
free(porig);
}
return OMPI_ERR_OUT_OF_RESOURCE;
}
cart->ndims = ndim;
cart->dims = dorig;
cart->periods = porig;
/* NTH: protect against a 0-byte alloc in the ndims = 0 case */
if (ndim > 0) {
cart->coords = (int*)malloc(sizeof(int) * ndim);
if (NULL == cart->coords) {
free(cart->periods);
if(NULL != cart->dims) free(cart->dims);
OBJ_RELEASE(cart);
return OMPI_ERR_OUT_OF_RESOURCE;
}
{ /* setup the cartesian topology */
int nprocs = temp_comm->c_local_group->grp_proc_count,
rank = temp_comm->c_local_group->grp_my_rank;
for (i = 0; i < ndim; ++i) {
nprocs /= cart->dims[i];
cart->coords[i] = rank / nprocs;
rank %= nprocs;
}
}
}
temp_comm->c_topo = topo;
temp_comm->c_topo->mtc.cart = cart;
temp_comm->c_topo->reorder = false;
temp_comm->c_flags |= OMPI_COMM_CART;
}
*new_comm = temp_comm;
return MPI_SUCCESS;
}
|