1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-10-02 14:31:05 +02:00

Merge pull request #45 from TREX-CoE/fix-hdf5

More portable hdf5 back end
This commit is contained in:
Evgeny Posenitskiy 2021-05-04 20:29:09 +02:00 committed by GitHub
commit 7316f0e07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 24 deletions

View File

@ -22,8 +22,6 @@
#+end_src #+end_src
DOCUMENT HDF5 BACK END HERE
#+begin_src c :tangle prefix_hdf5.h :noweb yes #+begin_src c :tangle prefix_hdf5.h :noweb yes
<<header>> <<header>>
@ -182,7 +180,7 @@ trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num)
const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT); const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT);
if (num_id <= 0) return TREXIO_INVALID_ID; if (num_id <= 0) return TREXIO_INVALID_ID;
const herr_t status = H5Aread(num_id, H5T_NATIVE_ULLONG, num); const herr_t status = H5Aread(num_id, H5T_NATIVE_UINT64, num);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
@ -204,7 +202,7 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
if (H5Aexists(f->$group$_group, $GROUP_NUM$_NAME) == 0) { if (H5Aexists(f->$group$_group, $GROUP_NUM$_NAME) == 0) {
/* Write the dimensioning variables */ /* Write the dimensioning variables */
const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG); const hid_t dtype = H5Tcopy(H5T_NATIVE_UINT64);
const hid_t dspace = H5Screate(H5S_SCALAR); const hid_t dspace = H5Screate(H5S_SCALAR);
const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME, dtype, dspace, const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME, dtype, dspace,
@ -243,7 +241,7 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
} else { } else {
const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG); const hid_t dtype = H5Tcopy(H5T_NATIVE_UINT64);
const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT); const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT);
if (num_id <= 0) return TREXIO_INVALID_ID; if (num_id <= 0) return TREXIO_INVALID_ID;
@ -304,8 +302,7 @@ trexio_hdf5_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype$*
herr_t status; herr_t status;
int rrank; int rrank;
// get the rank of the dataset in a file // get the rank of the dataset in a file
status = H5LTget_dataset_ndims (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, status = H5LTget_dataset_ndims (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, &rrank);
&rrank);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
@ -337,8 +334,9 @@ trexio_hdf5_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype$*
free(ddims); free(ddims);
/* High-level H5LT API. No need to deal with dataspaces and datatypes */ /* High-level H5LT API. No need to deal with dataspaces and datatypes */
status = H5LTread_dataset_$group_dset_h5_dtype$(f->$group$_group, status = H5LTread_dataset(f->$group$_group,
$GROUP$_$GROUP_DSET$_NAME, $GROUP$_$GROUP_DSET$_NAME,
H5T_NATIVE_$GROUP_DSET_H5_DTYPE$,
$group_dset$); $group_dset$);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
@ -363,11 +361,13 @@ trexio_hdf5_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_
trexio_hdf5_t* f = (trexio_hdf5_t*) file; trexio_hdf5_t* f = (trexio_hdf5_t*) file;
if ( H5LTfind_dataset(f->$group$_group, $GROUP$_$GROUP_DSET$_NAME) != 1) { if ( H5LTfind_dataset(f->$group$_group, $GROUP$_$GROUP_DSET$_NAME) != 1 ) {
const herr_t status = const herr_t status = H5LTmake_dataset(f->$group$_group,
H5LTmake_dataset_$group_dset_h5_dtype$ (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, $GROUP$_$GROUP_DSET$_NAME,
(int) rank, (const hsize_t*) dims, $group_dset$); (int) rank, (const hsize_t*) dims,
H5T_NATIVE_$GROUP_DSET_H5_DTYPE$,
$group_dset$);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
} else { } else {
@ -375,9 +375,10 @@ trexio_hdf5_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_
hid_t dset_id = H5Dopen(f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, H5P_DEFAULT); hid_t dset_id = H5Dopen(f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, H5P_DEFAULT);
if (dset_id <= 0) return TREXIO_INVALID_ID; if (dset_id <= 0) return TREXIO_INVALID_ID;
const herr_t status = const herr_t status = H5Dwrite(dset_id,
H5Dwrite(dset_id, H5T_NATIVE_$GROUP_DSET_H5_DTYPE$, H5S_ALL, H5S_ALL, H5T_NATIVE_$GROUP_DSET_H5_DTYPE$,
H5P_DEFAULT, $group_dset$); H5S_ALL, H5S_ALL, H5P_DEFAULT,
$group_dset$);
H5Dclose(dset_id); H5Dclose(dset_id);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
@ -417,3 +418,5 @@ trexio_hdf5_has_$group$_$group_dset$ (trexio_t* const file)
#endif #endif
#+end_src #+end_src

View File

@ -288,7 +288,7 @@ for fname in files_funcs_dsets:
c_dtype_single = 'float' c_dtype_single = 'float'
elif params['dtype'] == 'int64_t': elif params['dtype'] == 'int64_t':
h5_dtype = 'long' h5_dtype = 'int64'
f_dtype_double = 'integer(8)' f_dtype_double = 'integer(8)'
f_dtype_single = 'integer(4)' f_dtype_single = 'integer(4)'
c_dtype_double = 'int64_t' c_dtype_double = 'int64_t'