src/h5core/h5u_module.c

- refactore "*num_particles*" to "*num_points*"
- h5u_set_view() can now be used for writing, there are still some limitations
This commit is contained in:
2015-09-08 20:43:38 +02:00
parent a620715ccc
commit 4f7c666b1f
3 changed files with 113 additions and 51 deletions
+76 -36
View File
@@ -18,7 +18,7 @@
#include "h5core/h5u_model.h"
h5_ssize_t
h5u_get_num_particles (
h5u_get_num_points (
const h5_file_t fh /*!< [in] Handle to open file */
) {
h5_file_p f = (h5_file_p)fh;
@@ -27,7 +27,7 @@ h5u_get_num_particles (
if (h5u_has_view ((h5_file_t)f)) {
/* if a view exists, use its size as the number of particles */
TRY (nparticles = h5u_get_num_particles_in_view (fh));
TRY (nparticles = h5u_get_num_points_in_view (fh));
} else {
/* otherwise, report all particles on disk in the first dataset
for this timestep */
@@ -38,7 +38,7 @@ h5u_get_num_particles (
}
h5_ssize_t
h5u_get_num_particles_in_view (
h5u_get_num_points_in_view (
const h5_file_t fh /*!< [in] Handle to open file */
) {
h5_file_p f = (h5_file_p)fh;
@@ -79,16 +79,19 @@ h5u_get_totalnum_particles_by_idx (
H5_CORE_API_ENTER (h5_ssize_t, "f=%p, idx=%lld", f, (long long)idx);
char dataset_name[H5_DATANAME_LEN];
dataset_name[0] = '\0';
TRY (hdf5_get_name_of_dataset_by_idx (
h5_err_t h5err;
TRY (h5err = hdf5_get_name_of_dataset_by_idx (
f->step_gid,
idx,
dataset_name,
H5_DATANAME_LEN));
if (h5err == H5_NOK)
H5_CORE_API_LEAVE (H5_NOK);
H5_CORE_API_RETURN (h5u_get_totalnum_particles_by_name (fh, dataset_name));
}
h5_err_t
h5u_set_num_particles (
h5u_set_num_points (
const h5_file_t fh, /*!< [in] Handle to open file */
const h5_size_t nparticles, /*!< [in] Number of particles */
const h5_size_t stride /*!< [in] Stride of particles in memory */
@@ -256,37 +259,74 @@ h5u_set_view (
if (f->u->shape > 0) {
TRY (total = hdf5_get_npoints_of_dataspace (f->u->shape) );
} else {
TRY (total = (hsize_t)h5u_get_totalnum_particles_by_idx (fh,0));
TRY (total = (hsize_t)h5u_get_totalnum_particles_by_idx (fh, 0));
}
if (total == 0) {
/* No datasets have been created yet and no views are set.
* We have to leave the view empty because we don't know how
* many particles there should be! */
H5_CORE_API_LEAVE (H5_SUCCESS);
}
if (end < 0) {
end = total+end;
h5_debug ("Total = %lld", (long long) total);
if ((long long)total <= 0) {
/*
No datasets have been created yet and no views are set.
We have to leave the view empty because we don't know how
many particles there should be!
:FIXME: Should 'total == 0' be considered valid or not?
:FIXME: why not gather total size?
*/
if (start < 0) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"Start of selection '%lld' out of range: must be >= 0",
(long long)start)
);
}
if (end < start) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"End of selection '%lld' out of range: must be >= %lld",
(long long)end,
(long long)start)
);
}
#if PARALLEL_IO
TRY (
h5priv_mpi_allreduce_max (
&end, &total, 1, MPI_LONG_LONG, f->props->comm)
);
#else
total = end - start;
#endif
total++;
TRY (h5u_reset_view(fh));
TRY (hdf5_close_dataspace (u->shape));
TRY (u->shape = hdf5_create_dataspace(1, &total, NULL) );
} else {
if (end < 0) {
end = total+end;
}
if (start < 0 || start >= total) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"Start of selection '%lld' out of range: must be in [0..%lld]",
(long long)start, (long long)total-1));
} else if (end < 0 || end >= total) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"End of selection '%lld' out of range: must be in [0..%lld]",
(long long)end, (long long)total-1));
} else if (end+1 < start) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"Invalid selection: start=%lld > end=%lld!\n",
(long long)start, (long long)end));
}
}
if (start < 0 || start >= total) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"Start of selection out of range: %lld not in [0..%lld]",
(long long)start, (long long)total-1));
} else if (end < 0 || end >= total) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"End of selection out of range: %lld not in [0..%lld]",
(long long)end, (long long)total-1));
} else if (end+1 < start) {
H5_CORE_API_LEAVE (
h5_error(
H5_ERR_INVAL,
"Invalid selection: start=%lld > end=%lld!\n",
(long long)start, (long long)end));
}
/* setting up the new view */
u->viewstart = start;
u->viewend = end;
@@ -363,7 +403,7 @@ h5u_set_view_length (
u->nparticles = length;
h5_debug (
"This view has %lld particles.",
"This view includes %lld particles.",
(long long)u->nparticles );
/* declare overall data size but then will select a subset */
@@ -476,7 +516,7 @@ h5u_get_view (
viewend = u->viewend;
}
else {
TRY (viewend = h5u_get_num_particles (fh));
TRY (viewend = h5u_get_num_points (fh));
}
if ( start ) *start = viewstart;
@@ -497,7 +537,7 @@ h5u_set_canonical_view (
h5_int64_t start = 0;
h5_int64_t total = 0;
TRY (total = h5u_get_num_particles (fh));
TRY (total = h5u_get_num_points (fh));
u->nparticles = total / f->nprocs;
+34 -12
View File
@@ -46,6 +46,18 @@ extern "C" {
\return \c H5_SUCCESS or \c H5_FAILURE.
*/
static inline h5_err_t
H5PartSetNumPoints (
const h5_file_t f, ///< [in] file handle.
h5_size_t npoints ///< [in] Number of elements.
) {
H5_API_ENTER (h5_err_t,
"f=%p, npoints=%llu",
(h5_file_p)f, (long long unsigned)npoints);
h5_size_t stride = 1;
H5_API_RETURN (h5u_set_num_points (f, npoints, stride));
}
static inline h5_err_t
H5PartSetNumParticles (
const h5_file_t f, ///< [in] file handle.
@@ -55,7 +67,7 @@ H5PartSetNumParticles (
"f=%p, nparticles=%llu",
(h5_file_p)f, (long long unsigned)nparticles);
h5_size_t stride = 1;
H5_API_RETURN (h5u_set_num_particles (f, nparticles, stride));
H5_API_RETURN (h5u_set_num_points (f, nparticles, stride));
}
/*!
@@ -81,22 +93,22 @@ H5PartSetNumParticles (
If you instead have a separate array for each fields,
such as \c x[] and \c y[],
use \ref H5PartSetNumParticles.
use \ref H5PartSetNumParticles().
\return \c H5_SUCCESS or \c H5_FAILURE.
*/
static inline h5_err_t
H5PartSetNumParticlesStrided (
const h5_file_t f, ///< [in] file handle.
h5_size_t nparticles, ///< [in] number of particles.
h5_size_t npoints, ///< [in] number of elements.
h5_size_t stride ///< [in] stride value (e.g. number
///< of fields in the particle array).
) {
H5_API_ENTER (h5_err_t,
"f=%p, nparticles=%llu, stride=%llu",
(h5_file_p)f, (long long unsigned)nparticles,
"f=%p, npoints=%llu, stride=%llu",
(h5_file_p)f, (long long unsigned)npoints,
(long long unsigned)stride);
H5_API_RETURN (h5u_set_num_particles (f, nparticles, stride));
H5_API_RETURN (h5u_set_num_points (f, npoints, stride));
}
/*!
@@ -215,7 +227,7 @@ H5PartGetDatasetInfo (
if a view has been set.
If not, it returns the total number of particles across all processors
from the last \ref H5PartSetNumParticles call.
from the last \ref H5PartSetNumParticles() call.
If you have neither set the number of particles
nor set a view, then this returns the total number of
@@ -226,9 +238,19 @@ H5PartGetDatasetInfo (
If none of these conditions are met, an error is thrown.
\return number of particles in current step.
\return number of elements in datasets in current step.
\return \c H5_FAILURE on error.
*/
static inline h5_ssize_t
H5PartGetNumPoints (
const h5_file_t f ///< [in] file handle.
) {
H5_API_ENTER (h5_ssize_t,
"f=%p",
(h5_file_p)f);
H5_API_RETURN (h5u_get_num_points (f));
}
static inline h5_ssize_t
H5PartGetNumParticles (
const h5_file_t f ///< [in] file handle.
@@ -236,7 +258,7 @@ H5PartGetNumParticles (
H5_API_ENTER (h5_ssize_t,
"f=%p",
(h5_file_p)f);
H5_API_RETURN (h5u_get_num_particles (f));
H5_API_RETURN (h5u_get_num_points (f));
}
/*!
@@ -260,7 +282,7 @@ H5PartResetView (
\ingroup h5part_model
Check whether a view has been set, either automatically with
\ref H5PartSetNumParticles or manually with \ref H5PartSetView
\ref H5PartSetNumParticles() or manually with \ref H5PartSetView
or \ref H5PartSetViewIndices.
\return \c 1 if view has been set.
@@ -288,7 +310,7 @@ H5PartHasView (
is set, or the number of particles in a dataset changes, or the view is
"unset" by calling \c H5PartSetView(file,-1,-1);
Before you set a view, \ref H5PartGetNumParticles will return the
Before you set a view, \ref H5PartGetNumPoints will return the
total number of particles in the current time-step (even for the parallel
reads). However, after you set a view, it will return the number of
particles contained in the view.
@@ -326,7 +348,7 @@ H5PartSetView (
for all the intermediate values (which will not be touched by the read
or write).
Before you set a view, the \c H5PartGetNumParticles() will return the
Before you set a view, the \c H5PartGetNumPoints() will return the
total number of particles in the current time-step (even for the parallel
reads). However, after you set a view, it will return the number of
particles contained in the view.
+3 -3
View File
@@ -17,11 +17,11 @@ extern "C" {
#endif
h5_ssize_t
h5u_get_num_particles (
h5u_get_num_points (
const h5_file_t);
h5_ssize_t
h5u_get_num_particles_in_view (
h5u_get_num_points_in_view (
const h5_file_t);
h5_ssize_t
@@ -35,7 +35,7 @@ h5u_get_totalnum_particles_by_idx (
h5_id_t);
h5_err_t
h5u_set_num_particles (
h5u_set_num_points (
const h5_file_t,
const h5_size_t, const h5_size_t);