Skip to content

Commit

Permalink
moved memory use from stack to heap
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 27, 2019
1 parent 4c67551 commit 8cd99d9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/clib/pio_rearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ int create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt,
if (mcount[i] > 0)
{
int len = mcount[i] / blocksize;
int displace[len];
int *displace;

if (!(displace = malloc(sizeof(int) * len)))
return pio_err(NULL, NULL, PIO_ENOMEM, __FILE__, __LINE__);

LOG((3, "blocksize = %d i = %d mcount[%d] = %d len = %d", blocksize, i, i,
mcount[i], len));
if (blocksize == 1)
Expand Down Expand Up @@ -376,8 +380,11 @@ int create_mpi_datatypes(MPI_Datatype mpitype, int msgcnt,
LOG((3, "calling MPI_Type_create_indexed_block len = %d blocksize = %d "
"mpitype = %d", len, blocksize, mpitype));
/* Create an indexed datatype with constant-sized blocks. */
if ((mpierr = MPI_Type_create_indexed_block(len, blocksize, displace,
mpitype, &mtype[i])))
mpierr = MPI_Type_create_indexed_block(len, blocksize, displace,
mpitype, &mtype[i]);

free(displace);
if (mpierr)
return check_mpi(NULL, mpierr, __FILE__, __LINE__);

if (mtype[i] == PIO_DATATYPE_NULL)
Expand Down

0 comments on commit 8cd99d9

Please sign in to comment.