[svn-r1374] Added in code to support the H5Diterate function, which I've got to add tests

for now.  Also, I revised some of the code for hyperslab I/O, which should
provide a modest speedup in situations with lots of hyperslabs.
This commit is contained in:
Quincey Koziol 1999-06-23 21:16:13 -05:00
parent ace37763c3
commit c4c6318e6a
11 changed files with 916 additions and 288 deletions

View File

@ -2577,6 +2577,93 @@ H5D_get_storage_size(H5D_t *dset)
FUNC_LEAVE(size);
}
/*-------------------------------------------------------------------------
* Function: H5Diterate
*
* Purpose: This routine iterates over all the elements selected in a memory
* buffer. The callback function is called once for each element selected
* in the dataspace. The selection in the dataspace is modified so
* that any elements already iterated over are removed from the selection
* if the iteration is interrupted (by the H5D_operator_t function
* returning non-zero) in the "middle" of the iteration and may be
* re-started by the user where it left off.
*
* NOTE: Until "subtracting" elements from a selection is implemented,
* the selection is not modified.
*
* Parameters:
* void *buf; IN/OUT: Pointer to the buffer in memory containing
* the elements to iterate over.
* hid_t type_id; IN: Datatype ID for the elements stored in BUF.
* hid_t space_id; IN: Dataspace ID for BUF, also contains the
* selection to iterate over.
* H5D_operator_t operator; IN: Function pointer to the routine to be
* called for each element in BUF iterated over.
* void *operator_data; IN/OUT: Pointer to any user-defined data
* associated with the operation.
*
* Operation information:
* H5D_operator_t is defined as:
* typedef herr_t (*H5D_operator_t)(void *elem, hid_t type_id,
* hsize_t ndim, hssize_t *point, void *operator_data);
*
* H5D_operator_t parameters:
* void *elem; IN/OUT: Pointer to the element in memory containing
* the current point.
* hid_t type_id; IN: Datatype ID for the elements stored in ELEM.
* hsize_t ndim; IN: Number of dimensions for POINT array
* hssize_t *point; IN: Array containing the location of the element
* within the original dataspace.
* void *operator_data; IN/OUT: Pointer to any user-defined data
* associated with the operation.
*
* The return values from an operator are:
* Zero causes the iterator to continue, returning zero when all
* elements have been processed.
* Positive causes the iterator to immediately return that positive
* value, indicating short-circuit success. The iterator can be
* restarted at the next element.
* Negative causes the iterator to immediately return that value,
* indicating failure. The iterator can be restarted at the next
* element.
*
* Return: Returns the return value of the last operator if it was non-zero,
* or zero if all elements were processed. Otherwise returns a
* negative value.
*
* Programmer: Quincey Koziol
* Friday, June 11, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Diterate(void *buf, hid_t type_id, hid_t space_id, H5D_operator_t operator,
void *operator_data)
{
H5S_t *space = NULL;
herr_t ret_value=FAIL;
FUNC_ENTER(H5Diterate, FAIL);
/* Check args */
if (NULL==operator)
HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid operator");
if (buf==NULL)
HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid buffer");
if (H5I_DATATYPE != H5I_get_type(type_id))
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid datatype");
if (H5I_DATASPACE != H5I_get_type(space_id) ||
NULL == (space = H5I_object(space_id)))
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataspace");
ret_value=H5S_select_iterate(buf,type_id,space,operator,operator_data);
FUNC_LEAVE(ret_value);
} /* end H5Diterate() */
/*-------------------------------------------------------------------------
* Function: H5Dvlen_reclaim
@ -2614,7 +2701,7 @@ H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf)
/* Call H5Diterate with args, etc. */
FUNC_LEAVE(ret_value);
}
} /* end H5Dvlen_reclaim() */
/*-------------------------------------------------------------------------

View File

@ -39,6 +39,10 @@ typedef enum H5D_transfer_t {
} H5D_transfer_t;
/* Define the operator function pointer for H5Diterate() */
typedef herr_t (*H5D_operator_t)(void *elem, hid_t type_id, hsize_t ndim,
hssize_t *point, void *operator_data);
#ifdef __cplusplus
extern "C" {
#endif
@ -56,6 +60,8 @@ __DLL__ herr_t H5Dread (hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
__DLL__ herr_t H5Dwrite (hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, const void *buf);
__DLL__ herr_t H5Dextend (hid_t dset_id, const hsize_t *size);
__DLL__ herr_t H5Diterate(void *buf, hid_t type_id, hid_t space_id,
H5D_operator_t operator, void *operator_data);
__DLL__ herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf);
__DLL__ herr_t H5Ddebug(hid_t dset_id, unsigned int flags);

View File

@ -1818,6 +1818,7 @@ H5Soffset_simple(hid_t space_id, const hssize_t *offset)
FUNC_LEAVE(SUCCEED);
} /* end H5Soffset_simple() */
/*-------------------------------------------------------------------------
* Function: H5S_debug

View File

@ -914,3 +914,92 @@ H5S_all_bounds(H5S_t *space, hsize_t *start, hsize_t *end)
FUNC_LEAVE (ret_value);
} /* H5Sget_all_bounds() */
/*--------------------------------------------------------------------------
NAME
H5S_all_select_iterate
PURPOSE
Iterate over a "all" selection, calling a user's function for each
element.
USAGE
herr_t H5S_all_select_iterate(buf, type_id, space, operator, operator_data)
void *buf; IN/OUT: Buffer containing elements to iterate over
hid_t type_id; IN: Datatype ID of BUF array.
H5S_t *space; IN: Dataspace object containing selection to iterate over
H5D_operator_t operator; IN: Function pointer to the routine to be
called for each element in BUF iterated over.
void *operator_data; IN/OUT: Pointer to any user-defined data
associated with the operation.
RETURNS
Returns the return value of the last operator if it was non-zero, or zero
if all elements were processed. Otherwise returns a negative value.
DESCRIPTION
Iterates over the selected elements in a memory buffer, calling the user's
callback function for each element. The selection in the dataspace is
modified so that any elements already iterated over are removed from the
selection if the iteration is interrupted (by the H5D_operator_t function
returning non-zero) in the "middle" of the iteration and may be re-started
by the user where it left off.
NOTE: Until "subtracting" elements from a selection is implemented,
the selection is not modified.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5S_all_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t operator,
void *operator_data)
{
hsize_t mem_size[H5O_LAYOUT_NDIMS]; /* Dataspace size */
hsize_t mem_offset[H5O_LAYOUT_NDIMS]; /* current coordinates */
hsize_t offset; /* offset of region in buffer */
hsize_t nelemts; /* Number of elements to iterate through */
void *tmp_buf; /* temporary location of the element in the buffer */
intn rank; /* Dataspace rank */
intn index; /* Index to increment */
herr_t ret_value=0; /* return value */
FUNC_ENTER (H5S_all_select_iterate, 0);
assert(buf);
assert(space);
assert(operator);
assert(H5I_DATATYPE != H5I_get_type(type_id));
/* Get the dataspace extent rank */
rank=space->extent.u.simple.rank;
/* Set up the size of the memory space */
HDmemcpy(mem_size, space->extent.u.simple.size, rank*sizeof(hsize_t));
mem_size[rank]=H5Tget_size(type_id);
/* Set the coordinates to zero */
HDmemset(mem_offset, 0, (rank+1)*sizeof(hsize_t));
/* Get the number of elements to iterate through */
nelemts=H5S_get_simple_extent_npoints(space);
/* Iterate through the entire dataset */
while(nelemts>0 && ret_value==0) {
/* Get the offset in the memory buffer */
offset=H5V_array_offset(rank+1,mem_size,mem_offset);
tmp_buf=((char *)buf+offset);
ret_value=(*operator)(tmp_buf,type_id,rank,mem_offset,operator_data);
/* Advance the coordinate (currently in C memory order) */
index=rank-1; /* Leave the byte offset in the element alone */
while(++mem_offset[index]==mem_size[index] && index>=0) {
mem_offset[index]=0;
index--;
} /* end while */
/* Decrement the number of elements to iterate through */
nelemts--;
} /* end while */
FUNC_LEAVE (ret_value);
} /* H5S_all_select_iterate() */

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@
*/
#include <H5private.h>
#include <H5Eprivate.h>
#include <H5Iprivate.h>
#include <H5Sprivate.h>
#include <H5Vprivate.h>
#include <H5Dprivate.h>
@ -95,3 +96,44 @@ H5S_none_select_deserialize (H5S_t *space, const uint8_t UNUSED *buf)
done:
FUNC_LEAVE (ret_value);
} /* H5S_none_select_deserialize() */
/*--------------------------------------------------------------------------
NAME
H5S_none_select_iterate
PURPOSE
Iterate over a none selection, calling a user's function for each
element. (i.e. the user's function is not called because there are
zero elements selected)
USAGE
herr_t H5S_none_select_iterate(buf, type_id, space, operator, operator_data)
void *buf; IN/OUT: Buffer containing elements to iterate over
hid_t type_id; IN: Datatype ID of BUF array.
H5S_t *space; IN: Dataspace object containing selection to iterate over
H5D_operator_t operator; IN: Function pointer to the routine to be
called for each element in BUF iterated over.
void *operator_data; IN/OUT: Pointer to any user-defined data
associated with the operation.
RETURNS
Returns success (0).
DESCRIPTION
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5S_none_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t operator,
void UNUSED *operator_data)
{
herr_t ret_value=SUCCEED; /* return value */
FUNC_ENTER (H5S_none_select_iterate, FAIL);
assert(buf);
assert(space);
assert(operator);
assert(H5I_DATATYPE != H5I_get_type(type_id));
FUNC_LEAVE (ret_value);
} /* H5S_hyper_select_iterate() */

View File

@ -9,6 +9,7 @@
*/
#include <H5private.h>
#include <H5Eprivate.h>
#include <H5Iprivate.h>
#include <H5MMprivate.h>
#include <H5Sprivate.h>
#include <H5Vprivate.h>
@ -1107,4 +1108,78 @@ H5S_point_select_contiguous(const H5S_t *space)
ret_value=FALSE;
FUNC_LEAVE (ret_value);
} /* H5S_select_contiguous() */
} /* H5S_point_select_contiguous() */
/*--------------------------------------------------------------------------
NAME
H5S_point_select_iterate
PURPOSE
Iterate over a point selection, calling a user's function for each
element.
USAGE
herr_t H5S_point_select_iterate(buf, type_id, space, operator, operator_data)
void *buf; IN/OUT: Buffer containing elements to iterate over
hid_t type_id; IN: Datatype ID of BUF array.
H5S_t *space; IN: Dataspace object containing selection to iterate over
H5D_operator_t operator; IN: Function pointer to the routine to be
called for each element in BUF iterated over.
void *operator_data; IN/OUT: Pointer to any user-defined data
associated with the operation.
RETURNS
Returns the return value of the last operator if it was non-zero, or zero
if all elements were processed. Otherwise returns a negative value.
DESCRIPTION
Iterates over the selected elements in a memory buffer, calling the user's
callback function for each element. The selection in the dataspace is
modified so that any elements already iterated over are removed from the
selection if the iteration is interrupted (by the H5D_operator_t function
returning non-zero) in the "middle" of the iteration and may be re-started
by the user where it left off.
NOTE: Until "subtracting" elements from a selection is implemented,
the selection is not modified.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5S_point_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t operator,
void *operator_data)
{
hsize_t mem_size[H5O_LAYOUT_NDIMS]; /* Dataspace size */
hsize_t offset; /* offset of region in buffer */
void *tmp_buf; /* temporary location of the element in the buffer */
H5S_pnt_node_t *node; /* Point node */
intn rank; /* Dataspace rank */
herr_t ret_value=0; /* return value */
FUNC_ENTER (H5S_point_select_iterate, 0);
assert(buf);
assert(space);
assert(operator);
assert(H5I_DATATYPE != H5I_get_type(type_id));
/* Get the dataspace extent rank */
rank=space->extent.u.simple.rank;
/* Set up the size of the memory space */
HDmemcpy(mem_size, space->extent.u.simple.size, rank*sizeof(hsize_t));
mem_size[rank]=H5Tget_size(type_id);
/* Iterate through the node, checking the bounds on each element */
node=space->select.sel_info.pnt_lst->head;
while(node!=NULL && ret_value==0) {
/* Get the offset in the memory buffer */
offset=H5V_array_offset(rank+1,mem_size,node->pnt);
tmp_buf=((char *)buf+offset);
ret_value=(*operator)(tmp_buf,type_id,rank,node->pnt,operator_data);
node=node->next;
} /* end while */
FUNC_LEAVE (ret_value);
} /* H5S_point_select_iterate() */

View File

@ -342,6 +342,8 @@ __DLL__ hssize_t H5S_select_serial_size(const H5S_t *space);
__DLL__ herr_t H5S_select_serialize(const H5S_t *space, uint8_t *buf);
__DLL__ herr_t H5S_select_deserialize(H5S_t *space, const uint8_t *buf);
__DLL__ htri_t H5S_select_contiguous(const H5S_t *space);
__DLL__ herr_t H5S_select_iterate(void *buf, hid_t type_id, H5S_t *space,
H5D_operator_t operator, void *operator_data);
/* Point select functions */
__DLL__ herr_t H5S_point_add(H5S_t *space, size_t num_elemn,
@ -355,6 +357,8 @@ __DLL__ herr_t H5S_point_select_serialize(const H5S_t *space, uint8_t *buf);
__DLL__ herr_t H5S_point_select_deserialize(H5S_t *space, const uint8_t *buf);
__DLL__ herr_t H5S_point_bounds(H5S_t *space, hsize_t *start, hsize_t *end);
__DLL__ htri_t H5S_point_select_contiguous(const H5S_t *space);
__DLL__ herr_t H5S_point_select_iterate(void *buf, hid_t type_id, H5S_t *space,
H5D_operator_t operator, void *operator_data);
/* "All" select functions */
__DLL__ herr_t H5S_all_release(H5S_t *space);
@ -374,6 +378,8 @@ __DLL__ herr_t H5S_all_write(H5F_t *f, const struct H5O_layout_t *layout,
const H5S_t *file_space, const H5S_t *mem_space,
const H5F_xfer_t *xfer_parms, const void *buf,
hbool_t *must_convert/*out*/);
__DLL__ herr_t H5S_all_select_iterate(void *buf, hid_t type_id, H5S_t *space,
H5D_operator_t operator, void *operator_data);
/* Hyperslab selection functions */
__DLL__ herr_t H5S_hyper_add(H5S_t *space, const hssize_t *start,
@ -396,10 +402,14 @@ __DLL__ herr_t H5S_hyper_select_serialize(const H5S_t *space, uint8_t *buf);
__DLL__ herr_t H5S_hyper_select_deserialize(H5S_t *space, const uint8_t *buf);
__DLL__ herr_t H5S_hyper_bounds(H5S_t *space, hsize_t *start, hsize_t *end);
__DLL__ htri_t H5S_hyper_select_contiguous(const H5S_t *space);
__DLL__ herr_t H5S_hyper_select_iterate(void *buf, hid_t type_id, H5S_t *space,
H5D_operator_t operator, void *operator_data);
/* "None" selection functions */
__DLL__ herr_t H5S_none_select_serialize(const H5S_t *space, uint8_t *buf);
__DLL__ herr_t H5S_none_select_deserialize(H5S_t *space, const uint8_t *buf);
__DLL__ herr_t H5S_none_select_iterate(void *buf, hid_t type_id, H5S_t *space,
H5D_operator_t operator, void *operator_data);
#ifdef HAVE_PARALLEL
/* MPI-IO function to read directly from app buffer to file rky980813 */

View File

@ -1683,3 +1683,72 @@ H5S_select_contiguous(const H5S_t *space)
FUNC_LEAVE (ret_value);
} /* H5S_select_contiguous() */
/*--------------------------------------------------------------------------
NAME
H5S_iterate
PURPOSE
Iterate over the selected elements in a memory buffer.
USAGE
herr_t H5S_select_iterate(buf, type_id, space, operator, operator_data)
void *buf; IN/OUT: Buffer containing elements to iterate over
hid_t type_id; IN: Datatype ID of BUF array.
H5S_t *space; IN: Dataspace object containing selection to iterate over
H5D_operator_t operator; IN: Function pointer to the routine to be
called for each element in BUF iterated over.
void *operator_data; IN/OUT: Pointer to any user-defined data
associated with the operation.
RETURNS
Returns the return value of the last operator if it was non-zero, or zero
if all elements were processed. Otherwise returns a negative value.
DESCRIPTION
Iterates over the selected elements in a memory buffer, calling the user's
callback function for each element. The selection in the dataspace is
modified so that any elements already iterated over are removed from the
selection if the iteration is interrupted (by the H5D_operator_t function
returning non-zero) in the "middle" of the iteration and may be re-started
by the user where it left off.
NOTE: Until "subtracting" elements from a selection is implemented,
the selection is not modified.
--------------------------------------------------------------------------*/
herr_t
H5S_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t operator,
void *operator_data)
{
herr_t ret_value=FAIL;
FUNC_ENTER(H5S_select_iterate, FAIL);
/* Check args */
assert(buf);
assert(space);
assert(operator);
assert(H5I_DATATYPE != H5I_get_type(type_id));
switch(space->select.type) {
case H5S_SEL_POINTS: /* Sequence of points selected */
ret_value=H5S_point_select_iterate(buf,type_id,space,operator,operator_data);
break;
case H5S_SEL_HYPERSLABS: /* Hyperslab selection defined */
ret_value=H5S_hyper_select_iterate(buf,type_id,space,operator,operator_data);
break;
case H5S_SEL_ALL: /* Entire extent selected */
ret_value=H5S_all_select_iterate(buf,type_id,space,operator,operator_data);
break;
case H5S_SEL_NONE: /* Nothing selected */
ret_value=H5S_none_select_iterate(buf,type_id,space,operator,operator_data);
break;
case H5S_SEL_ERROR:
case H5S_SEL_N:
break;
}
FUNC_LEAVE(SUCCEED);
} /* end H5S_select_iterate() */

View File

@ -679,3 +679,49 @@ H5V_array_fill(void *_dst, const void *src, size_t size, size_t count)
FUNC_LEAVE(SUCCEED);
} /* H5V_array_fill() */
/*-------------------------------------------------------------------------
* Function: H5V_array_offset
*
* Purpose: Given a coordinate description of a location in an array, this
* function returns the byte offset of the coordinate.
*
* The dimensionality of the whole array, the hyperslab, and the
* returned stride array is N. The whole array dimensions are
* TOTAL_SIZE and the coordinate is at offset OFFSET.
*
* Return: Success: Byte offset from beginning of array to start
* of striding.
*
* Failure: abort() -- should never fail
*
* Programmer: Quincey Koziol
* Tuesday, June 22, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hsize_t
H5V_array_offset(intn n, const hsize_t *total_size, const hssize_t *offset)
{
hsize_t skip; /*starting point byte offset */
hsize_t acc; /*accumulator */
int i; /*counter */
FUNC_ENTER(H5V_array_stride, (HDabort(), 0));
assert(n >= 0 && n <= H5V_HYPER_NDIMS);
assert(total_size);
assert(offset);
/* others */
for (i=n-1, acc=1, skip=0; i>=0; --i) {
skip += acc * offset[i];
acc *= total_size[i];
}
FUNC_LEAVE(skip);
}

View File

@ -72,6 +72,8 @@ __DLL__ herr_t H5V_stride_optimize2(intn *np, hsize_t *elmt_size,
hssize_t *stride2);
__DLL__ herr_t H5V_array_fill(void *_dst, const void *src, size_t size,
size_t count);
__DLL__ hsize_t H5V_array_offset(intn n, const hsize_t *total_size,
const hssize_t *offset);
/*-------------------------------------------------------------------------