Skip to content

Commit

Permalink
starting to put map array allocations on heap with alloc instead of VLAs
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 7, 2019
1 parent 933f426 commit 163da37
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,19 +1533,24 @@ int pioc_read_nc_decomp_int(int iosysid, const char *filename, int *ndims, int *

/* Read the map. */
int map_varid;
int map_in[num_tasks_in][max_maplen_in];
int *map_in;

if (!(map_in = malloc(sizeof(int) * num_tasks_in * max_maplen_in)))
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);

if ((ret = PIOc_inq_varid(ncid, DECOMP_MAP_VAR_NAME, &map_varid)))
return pio_err(ios, NULL, ret, __FILE__, __LINE__);
if ((ret = PIOc_get_var_int(ncid, map_varid, (int *)map_in)))
if ((ret = PIOc_get_var_int(ncid, map_varid, map_in)))
return pio_err(ios, NULL, ret, __FILE__, __LINE__);
if (map)
{
if (!(*map = malloc(num_tasks_in * max_maplen_in * sizeof(int))))
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);
for (int t = 0; t < num_tasks_in; t++)
for (int l = 0; l < max_maplen_in; l++)
(*map)[t * max_maplen_in + l] = map_in[t][l];
(*map)[t * max_maplen_in + l] = map_in[t * max_maplen_in + l];
}
free(map_in);

/* Close the netCDF decomp file. */
LOG((2, "pioc_read_nc_decomp_int about to close file ncid = %d", ncid));
Expand Down

0 comments on commit 163da37

Please sign in to comment.