Skip to content

Commit

Permalink
Merge pull request ESMCI#1536 from NCAR/ejh_err
Browse files Browse the repository at this point in the history
now find_region() returns error code, and takes pointer to regionlen as a parameter
  • Loading branch information
edhartnett authored Jun 26, 2019
2 parents ab6c5fe + 4b766be commit 14e2a55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ extern "C" {
int alloc_region2(iosystem_desc_t *ios, int ndims, io_region **region);

/* Set start and count so that they describe the first region in map.*/
PIO_Offset find_region(int ndims, const int *gdims, int maplen, const PIO_Offset *map,
PIO_Offset *start, PIO_Offset *count);
int find_region(int ndims, const int *gdims, int maplen, const PIO_Offset *map,
PIO_Offset *start, PIO_Offset *count, PIO_Offset *regionlen);

/* Calculate start and count regions for the subset rearranger. */
int get_regions(int ndims, const int *gdimlen, int maplen, const PIO_Offset *map,
Expand Down
26 changes: 14 additions & 12 deletions src/clib/pio_rearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,21 @@ expand_region(int dim, const int *gdimlen, int maplen, const PIO_Offset *map,
* found region.
* @param count array (length ndims) that will get counts of found
* region.
* @returns length of the region found.
* @param regionlen pointer that gets the length of the region found.
* @returns 0 for success, error code otherwise.
* @author Jim Edwards
*/
PIO_Offset
int
find_region(int ndims, const int *gdimlen, int maplen, const PIO_Offset *map,
PIO_Offset *start, PIO_Offset *count)
PIO_Offset *start, PIO_Offset *count, PIO_Offset *regionlen)
{
PIO_Offset regionlen = 1;

/* Check inputs. */
pioassert(ndims > 0 && gdimlen && maplen > 0 && map && start && count,
"invalid input", __FILE__, __LINE__);
pioassert(ndims > 0 && gdimlen && maplen > 0 && map && start && count &&
regionlen, "invalid input", __FILE__, __LINE__);
LOG((2, "find_region ndims = %d maplen = %d", ndims, maplen));

*regionlen = 1;

int max_size[ndims];

/* Convert the index which is the first element of map into global
Expand All @@ -187,9 +188,9 @@ find_region(int ndims, const int *gdimlen, int maplen, const PIO_Offset *map,

/* Calculate the number of data elements in this region. */
for (int dim = 0; dim < ndims; dim++)
regionlen *= count[dim];
*regionlen *= count[dim];

return regionlen;
return PIO_NOERR;
}

/**
Expand Down Expand Up @@ -1845,7 +1846,7 @@ get_regions(int ndims, const int *gdimlen, int maplen, const PIO_Offset *map,
int *maxregions, io_region *firstregion)
{
int nmaplen = 0;
int regionlen;
PIO_Offset regionlen;
io_region *region;
int ret;

Expand Down Expand Up @@ -1879,8 +1880,9 @@ get_regions(int ndims, const int *gdimlen, int maplen, const PIO_Offset *map,
region->count[i] = 1;

/* Set start/count to describe first region in map. */
regionlen = find_region(ndims, gdimlen, maplen-nmaplen,
&map[nmaplen], region->start, region->count);
if ((ret = find_region(ndims, gdimlen, maplen-nmaplen,
&map[nmaplen], region->start, region->count, &regionlen)))
return ret;
pioassert(region->start[0] >= 0, "failed to find region", __FILE__, __LINE__);

nmaplen = nmaplen + regionlen;
Expand Down
3 changes: 2 additions & 1 deletion tests/cunit/test_rearr.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ int test_find_region()
PIO_Offset regionlen;

/* Call the function we are testing. */
regionlen = find_region(ndims, gdimlen, maplen, map, start, count);
if (find_region(ndims, gdimlen, maplen, map, start, count, &regionlen))
return ERR_WRONG;

/* Check results. */
if (regionlen != 1 || start[0] != 0 || count[0] != 1)
Expand Down

0 comments on commit 14e2a55

Please sign in to comment.