2004-03-07 01:40:26 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mca/topo/base/base.h"
|
2004-04-17 00:54:48 +04:00
|
|
|
#include "communicator/communicator.h"
|
2004-07-21 02:32:45 +04:00
|
|
|
#include "group/group.h"
|
2004-04-17 00:54:48 +04:00
|
|
|
#include "mca/topo/topo.h"
|
2004-07-21 02:32:45 +04:00
|
|
|
#include "mpi.h"
|
2004-03-07 01:40:26 +03:00
|
|
|
|
2004-03-08 09:48:24 +03:00
|
|
|
/*
|
|
|
|
* function - makes a new communicator to which topology information
|
|
|
|
* has been attached
|
|
|
|
*
|
|
|
|
* @param comm input communicator (handle)
|
|
|
|
* @param ndims number of dimensions of cartesian grid (integer)
|
|
|
|
* @param dims integer array of size ndims specifying the number of processes in
|
|
|
|
* each dimension
|
|
|
|
* @param periods logical array of size ndims specifying whether the grid is
|
|
|
|
* periodic (true) or not (false) in each dimension
|
|
|
|
* @param reorder ranking may be reordered (true) or not (false) (logical)
|
|
|
|
* @param comm_cart communicator with new cartesian topology (handle)
|
|
|
|
*
|
2004-08-06 18:30:18 +04:00
|
|
|
* Open MPI currently ignores the 'reorder' flag.
|
2004-03-08 09:48:24 +03:00
|
|
|
*
|
|
|
|
* @retval MPI_SUCCESS
|
|
|
|
*/
|
|
|
|
|
2004-08-02 04:24:22 +04:00
|
|
|
int mca_topo_base_cart_create (mca_topo_base_comm_t *topo_data,
|
|
|
|
int *proc_count,
|
|
|
|
ompi_proc_t **proc_pointers,
|
|
|
|
int *new_rank,
|
|
|
|
int ndims,
|
|
|
|
int *dims,
|
|
|
|
int *periods,
|
|
|
|
bool reorder) {
|
2004-07-21 02:32:45 +04:00
|
|
|
|
2004-03-08 09:48:24 +03:00
|
|
|
int nprocs;
|
2004-07-21 02:32:45 +04:00
|
|
|
int dim;
|
2004-03-08 09:48:24 +03:00
|
|
|
int i;
|
|
|
|
int *p;
|
2004-07-21 02:32:45 +04:00
|
|
|
int *coords = topo_data->mtc_coords;
|
2004-03-08 09:48:24 +03:00
|
|
|
|
|
|
|
nprocs = 1;
|
2004-07-21 02:32:45 +04:00
|
|
|
p = topo_data->mtc_dims_or_index;
|
|
|
|
|
|
|
|
/* Calculate the number of processes in this grid */
|
|
|
|
for (i = 0; i < topo_data->mtc_ndims_or_nnodes; ++i, ++p) {
|
|
|
|
if(*p <= 0) {
|
|
|
|
return OMPI_ERROR;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
nprocs *= *p;
|
|
|
|
}
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
/* check for the error condition */
|
2004-03-08 09:48:24 +03:00
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
if (*proc_count < nprocs) {
|
|
|
|
return MPI_ERR_DIMS;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
/* check if we have to trim the list of processes */
|
|
|
|
if (nprocs < *proc_count) {
|
|
|
|
*proc_count = nprocs;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
2004-07-21 02:32:45 +04:00
|
|
|
|
|
|
|
if (*new_rank > (nprocs-1)) {
|
|
|
|
/* sorry, but in our scheme this process is cut off */
|
|
|
|
*new_rank = MPI_UNDEFINED;
|
|
|
|
return MPI_SUCCESS;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
for (i = 0, p = topo_data->mtc_dims_or_index; i < ndims; ++i, ++p) {
|
|
|
|
*p = (*periods) ? -(*dims) : *dims;
|
|
|
|
++dims;
|
|
|
|
++periods;
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
/* Have to replace this with the actual function body itself */
|
|
|
|
p = topo_data->mtc_dims_or_index;
|
|
|
|
coords = topo_data->mtc_coords;
|
|
|
|
|
|
|
|
for (i=0;
|
|
|
|
(i < topo_data->mtc_ndims_or_nnodes);
|
|
|
|
++i, ++p) {
|
|
|
|
dim = (*p > 0) ? *p : -(*p);
|
|
|
|
nprocs /= dim;
|
|
|
|
*coords++ = *new_rank / nprocs;
|
|
|
|
*new_rank %= nprocs;
|
|
|
|
}
|
2004-03-08 09:48:24 +03:00
|
|
|
|
2004-07-21 02:32:45 +04:00
|
|
|
/* end here */
|
2004-03-08 09:48:24 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|