Protect against 0-byte allocations in carte_create and cart_sub.
cmr=v1.7.5:reviewer=jsquyres This commit was SVN r31146.
Этот коммит содержится в:
родитель
7adb137409
Коммит
dca2f0027e
@ -1,3 +1,4 @@
|
|||||||
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
||||||
* University Research and Technology
|
* University Research and Technology
|
||||||
@ -10,6 +11,8 @@
|
|||||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
||||||
|
* Copyright (c) 2014 Los Alamos National Security, LLC. All right
|
||||||
|
* reserved.
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -127,17 +130,27 @@ int mca_topo_base_cart_create(mca_topo_base_module_t *topo,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the proc structure from the previous communicator over to
|
/* Don't do any of the other initialization if we're not supposed
|
||||||
the new one. The topology module is then able to work on this
|
to be part of the new communicator (because nnodes has been
|
||||||
copy and rearrange it as it deems fit. */
|
reset to 0, making things like index[nnodes-1] be junk).
|
||||||
topo_procs = (ompi_proc_t**)malloc(num_procs * sizeof(ompi_proc_t *));
|
|
||||||
if(OMPI_GROUP_IS_DENSE(old_comm->c_local_group)) {
|
JMS: This should really be refactored to use
|
||||||
memcpy(topo_procs,
|
comm_create_group(), because ompi_comm_allocate() still
|
||||||
old_comm->c_local_group->grp_proc_pointers,
|
complains about 0-byte mallocs in debug builds for 0-member
|
||||||
num_procs * sizeof(ompi_proc_t *));
|
groups. */
|
||||||
} else {
|
if (num_procs > 0) {
|
||||||
for(i = 0 ; i < num_procs; i++) {
|
/* Copy the proc structure from the previous communicator over to
|
||||||
topo_procs[i] = ompi_group_peer_lookup(old_comm->c_local_group,i);
|
the new one. The topology module is then able to work on this
|
||||||
|
copy and rearrange it as it deems fit. */
|
||||||
|
topo_procs = (ompi_proc_t**)malloc(num_procs * sizeof(ompi_proc_t *));
|
||||||
|
if(OMPI_GROUP_IS_DENSE(old_comm->c_local_group)) {
|
||||||
|
memcpy(topo_procs,
|
||||||
|
old_comm->c_local_group->grp_proc_pointers,
|
||||||
|
num_procs * sizeof(ompi_proc_t *));
|
||||||
|
} else {
|
||||||
|
for(i = 0 ; i < num_procs; i++) {
|
||||||
|
topo_procs[i] = ompi_group_peer_lookup(old_comm->c_local_group,i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
||||||
* University Research and Technology
|
* University Research and Technology
|
||||||
@ -10,6 +11,8 @@
|
|||||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
||||||
|
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
|
||||||
|
* reserved.
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -120,28 +123,34 @@ int mca_topo_base_cart_sub (ompi_communicator_t* comm,
|
|||||||
cart->ndims = ndim;
|
cart->ndims = ndim;
|
||||||
cart->dims = dorig;
|
cart->dims = dorig;
|
||||||
cart->periods = porig;
|
cart->periods = porig;
|
||||||
cart->coords = (int*)malloc(sizeof(int) * ndim);
|
|
||||||
if (NULL == cart->coords) {
|
|
||||||
free(cart->periods);
|
|
||||||
if(NULL != cart->dims) free(cart->dims);
|
|
||||||
free(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) {
|
/* NTH: protect against a 0-byte alloc in the ndims = 0 case */
|
||||||
nprocs /= cart->dims[i];
|
if (ndim > 0) {
|
||||||
cart->coords[i] = rank / nprocs;
|
cart->coords = (int*)malloc(sizeof(int) * ndim);
|
||||||
rank %= nprocs;
|
if (NULL == cart->coords) {
|
||||||
|
free(cart->periods);
|
||||||
|
if(NULL != cart->dims) free(cart->dims);
|
||||||
|
free(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 = topo;
|
||||||
temp_comm->c_topo->mtc.cart = cart;
|
temp_comm->c_topo->mtc.cart = cart;
|
||||||
temp_comm->c_topo->reorder = false;
|
temp_comm->c_topo->reorder = false;
|
||||||
temp_comm->c_flags |= OMPI_COMM_CART;
|
temp_comm->c_flags |= OMPI_COMM_CART;
|
||||||
}
|
}
|
||||||
|
|
||||||
*new_comm = temp_comm;
|
*new_comm = temp_comm;
|
||||||
|
|
||||||
return MPI_SUCCESS;
|
return MPI_SUCCESS;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user