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 65202a2 commit 4c67551
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,9 @@ int PIOc_init_decomp(int iosysid, int pio_type, int ndims, const int *gdimlen, i
const PIO_Offset *compmap, int *ioidp, int rearranger,
const PIO_Offset *iostart, const PIO_Offset *iocount)
{
PIO_Offset compmap_1_based[maplen];
PIO_Offset *compmap_1_based;
int *rearrangerp = NULL;
int ret;

LOG((1, "PIOc_init_decomp iosysid = %d pio_type = %d ndims = %d maplen = %d",
iosysid, pio_type, ndims, maplen));
Expand All @@ -703,6 +704,10 @@ int PIOc_init_decomp(int iosysid, int pio_type, int ndims, const int *gdimlen, i
if (rearranger)
rearrangerp = &rearranger;

/* Allocate storage for compmap that's one-based. */
if (!(compmap_1_based = malloc(sizeof(PIO_Offset) * maplen)))
return PIO_ENOMEM;

/* Add 1 to all elements in compmap. */
for (int e = 0; e < maplen; e++)
{
Expand All @@ -711,8 +716,12 @@ int PIOc_init_decomp(int iosysid, int pio_type, int ndims, const int *gdimlen, i
}

/* Call the legacy version of the function. */
return PIOc_InitDecomp(iosysid, pio_type, ndims, gdimlen, maplen, compmap_1_based,
ioidp, rearrangerp, iostart, iocount);
ret = PIOc_InitDecomp(iosysid, pio_type, ndims, gdimlen, maplen, compmap_1_based,
ioidp, rearrangerp, iostart, iocount);

free(compmap_1_based);

return ret;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,10 @@ int PIOc_read_nc_decomp(int iosysid, const char *filename, int *ioidp, MPI_Comm
/* Now initialize the iodesc on each task for this decomposition. */
if (!ret)
{
PIO_Offset compmap[task_maplen[my_rank]];
PIO_Offset *compmap;

if (!(compmap = malloc(sizeof(PIO_Offset) * task_maplen[my_rank])))
return PIO_ENOMEM;

/* Copy array into PIO_Offset array. Make it 1 based. */
for (int e = 0; e < task_maplen[my_rank]; e++)
Expand All @@ -1163,6 +1166,8 @@ int PIOc_read_nc_decomp(int iosysid, const char *filename, int *ioidp, MPI_Comm
/* Initialize the decomposition. */
ret = PIOc_InitDecomp(iosysid, pio_type, ndims, global_dimlen, task_maplen[my_rank],
compmap, ioidp, NULL, NULL, NULL);

free(compmap);
}

/* Free resources. */
Expand Down
4 changes: 2 additions & 2 deletions tests/cunit/test_perf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#define NDIM3 3

/* The length of our sample data along each dimension. */
#define X_DIM_LEN 256
#define Y_DIM_LEN 256
#define X_DIM_LEN 512
#define Y_DIM_LEN 512
#define Z_DIM_LEN 64

/* This is the length of the map for each task. */
Expand Down

0 comments on commit 4c67551

Please sign in to comment.