2004-03-07 01:40:26 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-03-07 01:40:26 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2004-03-07 01:40:26 +03:00
|
|
|
#include "mca/topo/base/base.h"
|
2004-04-17 00:54:48 +04:00
|
|
|
#include "communicator/communicator.h"
|
|
|
|
#include "mca/topo/topo.h"
|
2004-03-07 01:40:26 +03:00
|
|
|
|
2004-03-08 09:48:24 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2004-07-21 02:32:45 +04:00
|
|
|
int mca_topo_base_cart_sub (MPI_Comm comm,
|
2004-03-08 09:48:24 +03:00
|
|
|
int *remain_dims,
|
2004-04-17 00:54:48 +04:00
|
|
|
MPI_Comm *new_comm){
|
2004-07-21 02:32:45 +04:00
|
|
|
|
|
|
|
struct ompi_communicator_t *temp_comm;
|
2004-03-08 09:48:24 +03:00
|
|
|
int errcode;
|
|
|
|
int colour;
|
|
|
|
int key;
|
|
|
|
int colfactor;
|
|
|
|
int keyfactor;
|
|
|
|
int rank;
|
|
|
|
int ndim;
|
|
|
|
int dim;
|
2004-07-21 02:32:45 +04:00
|
|
|
bool allfalse;
|
2004-03-08 09:48:24 +03:00
|
|
|
int i;
|
|
|
|
int *d;
|
|
|
|
int *c;
|
|
|
|
int *r;
|
|
|
|
int *p;
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
*new_comm = MPI_COMM_NULL;
|
|
|
|
|
2004-03-08 09:48:24 +03:00
|
|
|
/*
|
|
|
|
* Compute colour and key used in splitting the communicator.
|
|
|
|
*/
|
|
|
|
colour = key = 0;
|
|
|
|
colfactor = keyfactor = 1;
|
|
|
|
ndim = 0;
|
2004-07-21 02:32:45 +04:00
|
|
|
allfalse = false;
|
2004-03-08 09:48:24 +03:00
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
i = comm->c_topo_comm->mtc_ndims_or_nnodes - 1;
|
|
|
|
d = comm->c_topo_comm->mtc_dims_or_index + i;
|
2004-04-17 00:54:48 +04:00
|
|
|
c = comm->c_topo_comm->mtc_coords + i;
|
2004-03-08 09:48:24 +03:00
|
|
|
r = remain_dims + i;
|
|
|
|
|
|
|
|
for (; i >= 0; --i, --d, --c, --r) {
|
|
|
|
dim = (*d > 0) ? *d : -(*d);
|
|
|
|
if (*r == 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 cartesian communicator with just ourselves in it (you can't
|
|
|
|
* have a communicator unless you're in it).
|
|
|
|
*/
|
|
|
|
if (ndim == 0) {
|
2004-07-21 02:32:45 +04:00
|
|
|
colour = ompi_comm_rank (comm);
|
2004-03-08 09:48:24 +03:00
|
|
|
ndim = 1;
|
2004-07-21 02:32:45 +04:00
|
|
|
allfalse = true;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Split the communicator.
|
|
|
|
*/
|
2004-10-07 23:14:27 +04:00
|
|
|
errcode = ompi_comm_split (comm, colour, key, &temp_comm, true);
|
2004-03-08 09:48:24 +03:00
|
|
|
if (errcode != MPI_SUCCESS) {
|
|
|
|
return errcode;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fill the communicator with topology information.
|
|
|
|
*/
|
2004-07-21 02:32:45 +04:00
|
|
|
if (temp_comm != MPI_COMM_NULL) {
|
|
|
|
|
|
|
|
temp_comm->c_topo_comm->mtc_ndims_or_nnodes = ndim;
|
|
|
|
|
2004-03-08 09:48:24 +03:00
|
|
|
if (!allfalse) {
|
2004-07-21 02:32:45 +04:00
|
|
|
p = temp_comm->c_topo_comm->mtc_dims_or_index;
|
|
|
|
d = comm->c_topo_comm->mtc_dims_or_index;
|
2004-03-08 09:48:24 +03:00
|
|
|
r = remain_dims;
|
2004-07-21 02:32:45 +04:00
|
|
|
for (i = 0; i < comm->c_topo_comm->mtc_ndims_or_nnodes; ++i, ++d, ++r) {
|
2004-03-08 09:48:24 +03:00
|
|
|
if (*r) {
|
|
|
|
*p++ = *d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2004-07-21 02:32:45 +04:00
|
|
|
temp_comm->c_topo_comm->mtc_dims_or_index[0] = 1;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Compute the caller's coordinates.
|
|
|
|
*/
|
2004-07-21 02:32:45 +04:00
|
|
|
rank = ompi_comm_rank (temp_comm);
|
|
|
|
if (MPI_SUCCESS != errcode) {
|
|
|
|
OBJ_RELEASE(temp_comm);
|
2004-03-08 09:48:24 +03:00
|
|
|
return errcode;
|
|
|
|
}
|
2004-07-21 02:32:45 +04:00
|
|
|
errcode = temp_comm->c_topo->topo_cart_coords (temp_comm, rank,
|
|
|
|
ndim, temp_comm->c_topo_comm->mtc_coords);
|
|
|
|
if (MPI_SUCCESS != errcode) {
|
|
|
|
OBJ_RELEASE(temp_comm);
|
2004-03-08 09:48:24 +03:00
|
|
|
return errcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
*new_comm = temp_comm;
|
|
|
|
return MPI_SUCCESS;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|