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 a6025c8 commit dc20149
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 @@ -1035,6 +1035,10 @@ int PIOc_write_nc_decomp(int iosysid, const char *filename, int cmode, int ioid,
/* 2D array that will hold all the map information for all
* tasks. */
int full_map[ios->num_comptasks][max_maplen];
int *full_map1;

if (!(full_map1 = malloc(sizeof(int) * ios->num_comptasks * max_maplen)))
return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__);

/* Fill local array with my map. Use the fill value for unused */
/* elements at the end if max_maplen is longer than maplen. Also
Expand All @@ -1051,22 +1055,23 @@ int PIOc_write_nc_decomp(int iosysid, const char *filename, int cmode, int ioid,
}

/* Gather my_map from all computation tasks and fill the full_map array. */
if ((mpierr = MPI_Allgather(my_map, max_maplen, MPI_INT, full_map, max_maplen,
if ((mpierr = MPI_Allgather(my_map, max_maplen, MPI_INT, full_map1, max_maplen,
MPI_INT, ios->comp_comm)))
return check_mpi2(ios, NULL, mpierr, __FILE__, __LINE__);

free(my_map);

for (int p = 0; p < ios->num_comptasks; p++)
for (int e = 0; e < max_maplen; e++)
LOG((3, "full_map[%d][%d] = %d", p, e, full_map[p][e]));
LOG((3, "full_map[%d][%d] = %d", p, e, full_map1[p * max_maplen + e]));

/* Write the netCDF decomp file. */
if ((ret = pioc_write_nc_decomp_int(ios, filename, cmode, iodesc->ndims, iodesc->dimlen,
ios->num_comptasks, task_maplen, (int *)full_map, title,
ios->num_comptasks, task_maplen, full_map1, title,
history, fortran_order)))
return ret;

free(full_map1);
return PIO_NOERR;
}

Expand Down

0 comments on commit dc20149

Please sign in to comment.