summaryrefslogtreecommitdiffstats
path: root/src/H5Smpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Smpio.c')
-rw-r--r--src/H5Smpio.c93
1 files changed, 59 insertions, 34 deletions
diff --git a/src/H5Smpio.c b/src/H5Smpio.c
index 0c14129..a9108a5 100644
--- a/src/H5Smpio.c
+++ b/src/H5Smpio.c
@@ -73,10 +73,10 @@ static herr_t H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_poin
static herr_t H5S__mpio_point_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
hbool_t *is_derived_type, hbool_t do_permute, hsize_t **permute_map,
hbool_t *is_permuted);
-static herr_t H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute_map,
+static herr_t H5S__mpio_permute_type(H5S_t *space, size_t elmt_size, hsize_t **permute_map,
MPI_Datatype *new_type, int *count, hbool_t *is_derived_type);
-static herr_t H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type,
- int *count, hbool_t *is_derived_type);
+static herr_t H5S__mpio_reg_hyper_type(H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
+ hbool_t *is_derived_type);
static herr_t H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type,
int *count, hbool_t *is_derived_type);
static herr_t H5S__release_datatype(H5S_mpio_mpitype_list_t *type_list);
@@ -95,6 +95,9 @@ static herr_t H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *
/* Declare a free list to manage the H5S_mpio_mpitype_node_t struct */
H5FL_DEFINE_STATIC(H5S_mpio_mpitype_node_t);
+/* Declare a free list to manage dataspace selection iterators */
+H5FL_EXTERN(H5S_sel_iter_t);
+
/*-------------------------------------------------------------------------
* Function: H5S__mpio_all_type
*
@@ -501,17 +504,19 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute, MPI_Datatype *new_type,
- int *count, hbool_t *is_derived_type)
+H5S__mpio_permute_type(H5S_t *space, size_t elmt_size, hsize_t **permute, MPI_Datatype *new_type, int *count,
+ hbool_t *is_derived_type)
{
- MPI_Aint * disp = NULL; /* Datatype displacement for each point*/
- H5S_sel_iter_t sel_iter; /* Selection iteration info */
- hbool_t sel_iter_init = FALSE; /* Selection iteration info has been initialized */
- hssize_t snum_points; /* Signed number of elements in selection */
- hsize_t num_points; /* Number of points in the selection */
- size_t max_elem; /* Maximum number of elements allowed in sequences */
- hsize_t u; /* Local index variable */
- herr_t ret_value = SUCCEED; /* Return value */
+ MPI_Aint * disp = NULL; /* Datatype displacement for each point*/
+ H5S_sel_iter_t *sel_iter = NULL; /* Selection iteration info */
+ hbool_t sel_iter_init = FALSE; /* Selection iteration info has been initialized */
+ hssize_t snum_points; /* Signed number of elements in selection */
+ hsize_t num_points; /* Number of points in the selection */
+ hsize_t * off = NULL;
+ size_t * len = NULL;
+ size_t max_elem; /* Maximum number of elements allowed in sequences */
+ hsize_t u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -527,8 +532,18 @@ H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute,
if (NULL == (disp = (MPI_Aint *)H5MM_malloc(sizeof(MPI_Aint) * num_points)))
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements")
+ /* Allocate arrays to hold sequence offsets and lengths */
+ if (NULL == (off = H5MM_malloc(H5D_IO_VECTOR_SIZE * sizeof(*off))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate sequence offsets array")
+ if (NULL == (len = H5MM_malloc(H5D_IO_VECTOR_SIZE * sizeof(*len))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate sequence lengths array")
+
+ /* Allocate a selection iterator for iterating over the dataspace */
+ if (NULL == (sel_iter = H5FL_MALLOC(H5S_sel_iter_t)))
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "couldn't allocate dataspace selection iterator")
+
/* Initialize selection iterator */
- if (H5S_select_iter_init(&sel_iter, space, elmt_size, 0) < 0)
+ if (H5S_select_iter_init(sel_iter, space, elmt_size, 0) < 0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator")
sel_iter_init = TRUE; /* Selection iteration info has been initialized */
@@ -538,14 +553,12 @@ H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute,
/* Loop, while elements left in selection */
u = 0;
while (max_elem > 0) {
- hsize_t off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */
- size_t len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */
- size_t nelem; /* Number of elements used in sequences */
- size_t nseq; /* Number of sequences generated */
- size_t curr_seq; /* Current sequence being worked on */
+ size_t nelem; /* Number of elements used in sequences */
+ size_t nseq; /* Number of sequences generated */
+ size_t curr_seq; /* Current sequence being worked on */
/* Get the sequences of bytes */
- if (H5S_SELECT_ITER_GET_SEQ_LIST(&sel_iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off,
+ if (H5S_SELECT_ITER_GET_SEQ_LIST(sel_iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off,
len) < 0)
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "sequence length generation failed")
@@ -602,9 +615,14 @@ H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute,
done:
/* Release selection iterator */
- if (sel_iter_init)
- if (H5S_SELECT_ITER_RELEASE(&sel_iter) < 0)
+ if (sel_iter) {
+ if (sel_iter_init && H5S_SELECT_ITER_RELEASE(sel_iter) < 0)
HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator")
+ sel_iter = H5FL_FREE(H5S_sel_iter_t, sel_iter);
+ }
+
+ H5MM_free(len);
+ H5MM_free(off);
/* Free memory */
if (disp)
@@ -634,11 +652,11 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
+H5S__mpio_reg_hyper_type(H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
hbool_t *is_derived_type)
{
- H5S_sel_iter_t sel_iter; /* Selection iteration info */
- hbool_t sel_iter_init = FALSE; /* Selection iteration info has been initialized */
+ H5S_sel_iter_t *sel_iter = NULL; /* Selection iteration info */
+ hbool_t sel_iter_init = FALSE; /* Selection iteration info has been initialized */
struct dim { /* less hassle than malloc/free & ilk */
hssize_t start;
@@ -668,32 +686,37 @@ H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new
HDassert(sizeof(MPI_Aint) >= sizeof(elmt_size));
bigio_count = H5_mpi_get_bigio_count();
+
+ /* Allocate a selection iterator for iterating over the dataspace */
+ if (NULL == (sel_iter = H5FL_MALLOC(H5S_sel_iter_t)))
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "couldn't allocate dataspace selection iterator")
+
/* Initialize selection iterator */
- if (H5S_select_iter_init(&sel_iter, space, elmt_size, 0) < 0)
+ if (H5S_select_iter_init(sel_iter, space, elmt_size, 0) < 0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator")
sel_iter_init = TRUE; /* Selection iteration info has been initialized */
/* Abbreviate args */
- diminfo = sel_iter.u.hyp.diminfo;
+ diminfo = sel_iter->u.hyp.diminfo;
HDassert(diminfo);
/* Make a local copy of the dimension info so we can operate with them */
/* Check if this is a "flattened" regular hyperslab selection */
- if (sel_iter.u.hyp.iter_rank != 0 && sel_iter.u.hyp.iter_rank < space->extent.rank) {
+ if (sel_iter->u.hyp.iter_rank != 0 && sel_iter->u.hyp.iter_rank < space->extent.rank) {
/* Flattened selection */
- rank = sel_iter.u.hyp.iter_rank;
+ rank = sel_iter->u.hyp.iter_rank;
#ifdef H5S_DEBUG
if (H5DEBUG(S))
HDfprintf(H5DEBUG(S), "%s: Flattened selection\n", __func__);
#endif
for (u = 0; u < rank; ++u) {
H5_CHECK_OVERFLOW(diminfo[u].start, hsize_t, hssize_t)
- d[u].start = (hssize_t)diminfo[u].start + sel_iter.u.hyp.sel_off[u];
+ d[u].start = (hssize_t)diminfo[u].start + sel_iter->u.hyp.sel_off[u];
d[u].strid = diminfo[u].stride;
d[u].block = diminfo[u].block;
d[u].count = diminfo[u].count;
- d[u].xtent = sel_iter.u.hyp.size[u];
+ d[u].xtent = sel_iter->u.hyp.size[u];
#ifdef H5S_DEBUG
if (H5DEBUG(S)) {
@@ -951,9 +974,11 @@ H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new
done:
/* Release selection iterator */
- if (sel_iter_init)
- if (H5S_SELECT_ITER_RELEASE(&sel_iter) < 0)
+ if (sel_iter) {
+ if (sel_iter_init && H5S_SELECT_ITER_RELEASE(sel_iter) < 0)
HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator")
+ sel_iter = H5FL_FREE(H5S_sel_iter_t, sel_iter);
+ }
#ifdef H5S_DEBUG
if (H5DEBUG(S))
@@ -1364,7 +1389,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5S_mpio_space_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
+H5S_mpio_space_type(H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count,
hbool_t *is_derived_type, hbool_t do_permute, hsize_t **permute_map, hbool_t *is_permuted)
{
herr_t ret_value = SUCCEED; /* Return value */