void smpi_cart_topo_destroy(MPIR_Cart_Topology cart) {
if (cart) {
if(cart->dims) {
- free(cart->dims);
+ xbt_free(cart->dims);
}
if(cart->periodic) {
- free(cart->periodic);
+ xbt_free(cart->periodic);
}
if(cart->position) {
- free(cart->position);
+ xbt_free(cart->position);
}
- free(cart);
+ xbt_free(cart);
}
}
newCart->topo.cart->nnodes = newSize;
- /* memcpy(newCart->topo.cart->dims, dims, ndims * sizeof(*newCart->topo.cart->dims)); */
- /* memcpy(newCart->topo.cart->periodic, periods, ndims * sizeof(*newCart->topo.cart->periodic)); */
-
// FIXME : code duplication... See smpi_mpi_cart_coords
nranks = newSize;
for (i=0; i<ndims; i++) {
} else {
if (rank == 0) {
newCart = smpi_cart_topo_create(ndims);
- *comm_cart = smpi_comm_new(smpi_comm_group(MPI_COMM_SELF), newCart);
+ *comm_cart = smpi_comm_new(smpi_group_copy(smpi_comm_group(MPI_COMM_SELF)), newCart);
} else {
*comm_cart = MPI_COMM_NULL;
}
}
newNDims = 0;
for (i = 0 ; i < oldNDims ; i++) {
- if (remain_dims[i]) newNDims++;
+ if (remain_dims[i])
+ newNDims++;
}
if (newNDims > 0) {
int smpi_mpi_cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
MPI_Topology topo = smpi_comm_topo(comm);
-
- for(int i = 0 ; i < maxdims ; i++) {
+ int ndims=topo->topo.cart->ndims < maxdims ? topo->topo.cart->ndims : maxdims;
+ for(int i = 0 ; i < ndims ; i++) {
dims[i] = topo->topo.cart->dims[i];
periods[i] = topo->topo.cart->periodic[i];
coords[i] = topo->topo.cart->position[i];
} else if (coord < 0) {
if(topo->topo.cart->periodic[i]) {
coord = coord % topo->topo.cart->dims[i];
- if (coord) coord = topo->topo.cart->dims[i] + coord;
+ if (coord)
+ coord = topo->topo.cart->dims[i] + coord;
} else {
*rank = -1;
return MPI_ERR_ARG;