Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port PR270 to 1.10 Branch: Improve performance of multiple calls to H5Sget_select_elem_pointlist #276

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ New Features

Library:
--------
-
- Improved performance of H5Sget_select_elem_pointlist

Modified library to cache the point after the last block of points
retrieved by H5Sget_select_elem_pointlist, so a subsequent call to the
same function to retrieve the next block of points from the list can
proceed immediately without needing to iterate over the point list.

(NAF - 2021/01/19)

Fortran Library:
----------------
Expand Down
5 changes: 5 additions & 0 deletions src/H5Spkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ struct H5S_pnt_list_t {

H5S_pnt_node_t *head; /* Pointer to head of point list */
H5S_pnt_node_t *tail; /* Pointer to tail of point list */

hsize_t last_idx; /* Index of the point after the last returned from H5S__get_select_elem_pointlist() */
H5S_pnt_node_t *last_idx_pnt; /* Point after the last returned from H5S__get_select_elem_pointlist().
* If we ever add a way to remove points or add points in the middle of
* the pointlist we will need to invalidate these fields. */
};

/* Information about hyperslab spans */
Expand Down
33 changes: 26 additions & 7 deletions src/H5Spoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank)
H5MM_memcpy(dst->high_bounds, src->high_bounds, (rank * sizeof(hsize_t)));
H5MM_memcpy(dst->low_bounds, src->low_bounds, (rank * sizeof(hsize_t)));

/* Clear cached iteration point */
dst->last_idx = 0;
dst->last_idx_pnt = NULL;

/* Set return value */
ret_value = dst;

Expand Down Expand Up @@ -1356,6 +1360,7 @@ H5S__point_deserialize(H5S_t **space, const uint8_t **p)
static herr_t
H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t numpoints, hsize_t *buf)
{
const hsize_t endpoint = startpoint + numpoints; /* Index of last point in iteration */
H5S_pnt_node_t *node; /* Point node */
unsigned rank; /* Dataspace rank */

Expand All @@ -1367,14 +1372,20 @@ H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t n
/* Get the dataspace extent rank */
rank = space->extent.rank;

/* Get the head of the point list */
node = space->select.sel_info.pnt_lst->head;
/* Check for cached point at the correct index */
if(space->select.sel_info.pnt_lst->last_idx_pnt
&& startpoint == space->select.sel_info.pnt_lst->last_idx)
node = space->select.sel_info.pnt_lst->last_idx_pnt;
else {
/* Get the head of the point list */
node = space->select.sel_info.pnt_lst->head;

/* Iterate to the first point to return */
while (node != NULL && startpoint > 0) {
startpoint--;
node = node->next;
} /* end while */
/* Iterate to the first point to return */
while (node != NULL && startpoint > 0) {
startpoint--;
node = node->next;
} /* end while */
} /* end else */

/* Iterate through the node, copying each point's information */
while (node != NULL && numpoints > 0) {
Expand All @@ -1384,6 +1395,10 @@ H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t n
node = node->next;
} /* end while */

/* Cached next point in iteration */
space->select.sel_info.pnt_lst->last_idx = endpoint;
space->select.sel_info.pnt_lst->last_idx_pnt = node;

FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5S__get_select_elem_pointlist() */

Expand Down Expand Up @@ -2175,6 +2190,10 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of
} /* end for */
} /* end else */

/* Clear cached iteration point */
new_space->select.sel_info.pnt_lst->last_idx = 0;
new_space->select.sel_info.pnt_lst->last_idx_pnt = NULL;

/* Number of elements selected will be the same */
new_space->select.num_elem = base_space->select.num_elem;

Expand Down