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"
|
|
|
|
#include "mca/topo/topo.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)
|
|
|
|
*
|
|
|
|
* LAM/MPI currently ignores the 'reorder' flag.
|
|
|
|
*
|
|
|
|
* @retval MPI_SUCCESS
|
|
|
|
*/
|
|
|
|
|
2004-04-17 00:54:48 +04:00
|
|
|
int topo_base_cart_create (MPI_Comm old_comm,
|
2004-03-08 09:48:24 +03:00
|
|
|
int ndims,
|
|
|
|
int *dims,
|
|
|
|
int *periods,
|
|
|
|
int reorder,
|
2004-04-17 00:54:48 +04:00
|
|
|
MPI_Comm *comm_cart){
|
|
|
|
MPI_Comm newcomm;
|
|
|
|
#if 0
|
|
|
|
MPI_Group newgroup;
|
|
|
|
int rank;
|
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
int size;
|
|
|
|
int nprocs;
|
|
|
|
int err;
|
|
|
|
int range[1][3];
|
|
|
|
int i;
|
|
|
|
int *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the # of processes in the grid.
|
|
|
|
*/
|
|
|
|
nprocs = 1;
|
|
|
|
for (i = 0, p = dims; i < ndims; ++i, ++p) {
|
|
|
|
if (*p <= 0) {
|
|
|
|
return MPI_ERR_DIMS;
|
|
|
|
}
|
|
|
|
nprocs *= *p;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Create the group for the new communicator.
|
|
|
|
*/
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_comm_size (comm, &size);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
if (err != MPI_SUCCESS) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nprocs > size) {
|
|
|
|
return MPI_ERR_DIMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nprocs == size) {
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_comm_group (comm, &newgroup);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
} else {
|
|
|
|
range[0][0] = 0;
|
|
|
|
range[0][1] = nprocs - 1;
|
|
|
|
range[0][2] = 1;
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_group_range_incl (comm->c_group, 1, range, &newgroup);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err != MPI_SUCCESS) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Create the new communicator.
|
|
|
|
*/
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_comm_create (comm, newgroup, comm_cart);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
if (err != MPI_SUCCESS) {
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
lam_group_free (&newgroup);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fill the communicator with topology information.
|
|
|
|
*/
|
|
|
|
newcomm = *comm_cart;
|
|
|
|
if (newcomm != MPI_COMM_NULL) {
|
2004-04-17 00:54:48 +04:00
|
|
|
newcomm->c_topo_comm->mtc_type = MPI_CART;
|
|
|
|
newcomm->c_topo_comm->mtc_nprocs = nprocs;
|
|
|
|
newcomm->c_topo_comm->mtc_ndims = ndims;
|
|
|
|
newcomm->c_topo_comm->mtc_dims = (int *)
|
2004-03-08 09:48:24 +03:00
|
|
|
malloc((unsigned) 2 * ndims * sizeof(int));
|
2004-04-17 00:54:48 +04:00
|
|
|
if (newcomm->c_topo_comm->mtc_dims == 0) {
|
2004-03-08 09:48:24 +03:00
|
|
|
return MPI_ERR_OTHER;
|
|
|
|
}
|
2004-04-17 00:54:48 +04:00
|
|
|
newcomm->c_topo_comm->mtc_coords = newcomm->c_topo_comm->mtc_dims + ndims;
|
|
|
|
for (i = 0, p = newcomm->c_topo_comm->mtc_dims; i < ndims; ++i, ++p) {
|
2004-03-08 09:48:24 +03:00
|
|
|
*p = (*periods) ? -(*dims) : *dims;
|
|
|
|
++dims;
|
|
|
|
++periods;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Compute the caller's coordinates.
|
|
|
|
*/
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_comm_rank (newcomm, &rank);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
if (err != MPI_SUCCESS) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
|
|
|
err = lam_cart_coords (newcomm, rank,
|
|
|
|
ndims, newcomm->c_topo_comm->mtc_coords);
|
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
if (err != MPI_SUCCESS) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-17 00:54:48 +04:00
|
|
|
#if 0
|
2004-03-08 09:48:24 +03:00
|
|
|
err = lam_group_free (&newgroup);
|
2004-04-17 00:54:48 +04:00
|
|
|
#endif
|
2004-03-08 09:48:24 +03:00
|
|
|
if (err != MPI_SUCCESS) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|