From b059b6d2d19c81b4b72b37ef801a0efd6d379619 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 26 Jun 2019 07:06:54 -0600 Subject: [PATCH] now find_region() returns error code, and takes pointer to regionlen as a parameter --- src/clib/pio_internal.h | 4 ++-- src/clib/pio_rearrange.c | 26 ++++++++++++++------------ tests/cunit/test_rearr.c | 3 ++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 4f3a3aebcbc..6c6146e702a 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -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, diff --git a/src/clib/pio_rearrange.c b/src/clib/pio_rearrange.c index 0638dfcbdee..d2f3b385e29 100644 --- a/src/clib/pio_rearrange.c +++ b/src/clib/pio_rearrange.c @@ -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 @@ -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; } /** @@ -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; @@ -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, ®ionlen))) + return ret; pioassert(region->start[0] >= 0, "failed to find region", __FILE__, __LINE__); nmaplen = nmaplen + regionlen; diff --git a/tests/cunit/test_rearr.c b/tests/cunit/test_rearr.c index 3f29022713a..9c653bfdd84 100644 --- a/tests/cunit/test_rearr.c +++ b/tests/cunit/test_rearr.c @@ -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, ®ionlen)) + return ERR_WRONG; /* Check results. */ if (regionlen != 1 || start[0] != 0 || count[0] != 1)