Skip to content

Commit

Permalink
added library context
Browse files Browse the repository at this point in the history
  • Loading branch information
brtnfld committed Nov 7, 2024
1 parent 0fe899b commit ea07c0c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/H5VL_log_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ void *H5VL_log_dataset_create (void *obj,
void **ureqp, *ureq;
H5D_fill_value_t stat;
void *lib_state = NULL;
void *lib_context = NULL;
// char lname[1024];
H5VL_logi_err_finally finally (
[&dcpl_id, &lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&dcpl_id, &lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });

try {
H5VL_LOGI_PROFILING_TIMER_START;
Expand Down Expand Up @@ -160,7 +161,7 @@ void *H5VL_log_dataset_create (void *obj,
H5VL_logi_get_filters (dcpl_id, dip->filters);

// Reset hdf5 context to allow attr operations within a dataset operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

// Record dataset metadata as attributes
H5VL_logi_add_att (dp, H5VL_LOG_DATASETI_ATTR_DIMS, H5T_STD_I64LE, H5T_NATIVE_INT64,
Expand Down
19 changes: 11 additions & 8 deletions src/H5VL_log_dataseti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,15 @@ void *H5VL_log_dataseti_open (void *obj, void *uo, hid_t dxpl_id) {
std::unique_ptr<H5VL_log_dset_info_t> dip; // Dataset info
H5D_fill_value_t stat;
void *lib_state = NULL;
H5VL_logi_err_finally finally ([&dcpl_id, &lib_state] () -> void {
void *lib_context = NULL;
H5VL_logi_err_finally finally ([&dcpl_id, &lib_state, &lib_context] () -> void {
if (dcpl_id >= 0) { H5Pclose (dcpl_id); }
H5VL_logi_restore_lib_stat (lib_state);
H5VL_logi_restore_lib_stat (lib_state, lib_context);
});
H5VL_LOGI_PROFILING_TIMER_START;

// Reset hdf5 context to allow file operations within a dataset operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

dp = std::make_unique<H5VL_log_dset_t> (op, H5I_DATASET, uo);

Expand Down Expand Up @@ -806,9 +807,10 @@ void H5VL_log_dataseti_write (H5VL_log_dset_t *dp,
int clen, inlen; // Compressed size; Size of data to be compressed
#endif
void *lib_state = NULL;
H5VL_logi_err_finally finally ([&ptype, &lib_state] () -> void {
void *lib_context = NULL;
H5VL_logi_err_finally finally ([&ptype, &lib_state, &lib_context] () -> void {
H5VL_log_type_free (ptype);
H5VL_logi_restore_lib_stat (lib_state);
H5VL_logi_restore_lib_stat (lib_state, lib_context);
});
H5VL_LOGI_PROFILING_TIMER_START;

Expand All @@ -830,7 +832,7 @@ void H5VL_log_dataseti_write (H5VL_log_dset_t *dp,
H5VL_LOGI_PROFILING_TIMER_STOP (dp->fp, TIMER_H5VL_LOG_DATASET_WRITE_INIT);

// Reset hdf5 context to allow file operations within a dataset operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

if (dp->fp->config ^ H5VL_FILEI_CONFIG_METADATA_MERGE) {
H5VL_LOGI_PROFILING_TIMER_START;
Expand Down Expand Up @@ -1047,9 +1049,10 @@ void H5VL_log_dataseti_read (H5VL_log_dset_t *dp,
hbool_t rtype; // Non-blocking?
size_t num_pending_writes = 0;
void *lib_state = NULL;
void *lib_context = NULL;
H5FD_mpio_xfer_t xfer_mode;
H5VL_logi_err_finally finally (
[&lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });
H5VL_LOGI_PROFILING_TIMER_START;

H5VL_LOGI_PROFILING_TIMER_START;
Expand All @@ -1059,7 +1062,7 @@ void H5VL_log_dataseti_read (H5VL_log_dset_t *dp,
H5VL_LOGI_PROFILING_TIMER_STOP (dp->fp, TIMER_H5VL_LOG_DATASET_READ_INIT);

// Reset hdf5 context to allow file operations within a dataset operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

// Check mem space selection
if (mem_space_id == H5S_ALL)
Expand Down
5 changes: 3 additions & 2 deletions src/H5VL_log_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ herr_t H5VL_log_file_specific (void *file,
herr_t err = 0;
H5VL_log_file_t *fp = (H5VL_log_file_t *)file;
void *lib_state = NULL;
void *lib_context = NULL;
H5VL_logi_err_finally finally (
[&lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });

try {
#ifdef LOGVOL_DEBUG
Expand Down Expand Up @@ -459,7 +460,7 @@ herr_t H5VL_log_file_specific (void *file,
H5VL_LOGI_PROFILING_TIMER_START;
if (fp->is_log_based_file) {
// Reset hdf5 context to allow dataset operations within a file operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

H5VL_log_filei_flush(fp, dxpl_id);
} else {
Expand Down
17 changes: 10 additions & 7 deletions src/H5VL_log_filei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ void H5VL_log_filei_post_open (H5VL_log_file_t *fp) {
hbool_t exists;
int attbuf[H5VL_LOG_FILEI_NATTR];
void *lib_state = NULL;
void *lib_context = NULL;
H5VL_logi_err_finally finally (
[&lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });

H5VL_LOGI_PROFILING_TIMER_START;

Expand Down Expand Up @@ -165,7 +166,7 @@ void H5VL_log_filei_post_open (H5VL_log_file_t *fp) {
H5VL_LOGI_PROFILING_TIMER_STOP (fp, TIMER_H5VL_LOG_FILE_OPEN_SUBFILE);

// Reset hdf5 context to allow group operations within a file operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

// Open the LOG group
loc.obj_type = H5I_FILE;
Expand Down Expand Up @@ -203,13 +204,14 @@ void H5VL_log_filei_post_create (H5VL_log_file_t *fp) {
H5VL_loc_params_t loc;
int attbuf[H5VL_LOG_FILEI_NATTR];
void *lib_state = NULL;
void *lib_context = NULL;
H5VL_logi_err_finally finally (
[&lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });

H5VL_LOGI_PROFILING_TIMER_START;

// Reset hdf5 context to allow group and attr operations within a file operation
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

// Figure out lustre configuration
H5VL_LOGI_PROFILING_TIMER_START;
Expand Down Expand Up @@ -712,8 +714,9 @@ void H5VL_log_filei_close (H5VL_log_file_t *fp) {
int mpierr;
int attbuf[5];
void *lib_state = NULL;
void *lib_context = NULL;
H5VL_logi_err_finally finally (
[&lib_state] () -> void { H5VL_logi_restore_lib_stat (lib_state); });
[&lib_state, &lib_context] () -> void { H5VL_logi_restore_lib_stat (lib_state, lib_context); });

#ifdef LOGVOL_DEBUG
if (H5VL_logi_debug_verbose ()) { printf ("H5VL_log_filei_close(%p, ...)\n", fp); }
Expand All @@ -734,7 +737,7 @@ void H5VL_log_filei_close (H5VL_log_file_t *fp) {
H5VL_LOGI_PROFILING_TIMER_START;

// Reset hdf5 context to allow file operations within other object close operations
H5VL_logi_reset_lib_stat (lib_state);
H5VL_logi_reset_lib_stat (lib_state, lib_context);

if (fp->flag != H5F_ACC_RDONLY) {
// Flush write requests
Expand Down Expand Up @@ -773,7 +776,7 @@ void H5VL_log_filei_close (H5VL_log_file_t *fp) {
CHECK_ERR
H5VL_LOGI_PROFILING_TIMER_STOP (fp, TIMER_H5VLGROUP_CLOSE);

H5VL_logi_restore_lib_stat (lib_state);
H5VL_logi_restore_lib_stat (lib_state, lib_context);

#ifdef LOGVOL_PROFILING
{
Expand Down
2 changes: 1 addition & 1 deletion src/H5VL_log_filei_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void H5VL_log_filei_metaflush (H5VL_log_file_t *fp) {
rbuf[2]; // [Local metadata offset within the metadata dataset, Global metadata size]
MPI_Offset mdsize = 0; // Local metadata size
MPI_Offset *mdoffs = NULL;
MPI_Offset *mdoffs_snd;
MPI_Offset *mdoffs_snd = NULL;
MPI_Aint *offs = NULL; // Offset in MPI_Type_create_hindexed
int *lens = NULL; // Lens in MPI_Type_create_hindexed
int nentry = 0; // Number of metadata entries
Expand Down
13 changes: 11 additions & 2 deletions src/H5VL_logi_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,29 @@ inline char *H5VL_logi_name_remap (const char *name) {
return ret;
}

inline void H5VL_logi_reset_lib_stat (void *&stat) {
inline void H5VL_logi_reset_lib_stat (void *&stat, void *&context) {
herr_t err = 0;
err = H5VLretrieve_lib_state (&stat);
CHECK_ERR
#if H5_VERSION_GE(2, 0, 0)
err = H5VLopen_lib_context (&context);
#else
err = H5VLstart_lib_state ();
#endif
CHECK_ERR
err = H5VLrestore_lib_state (stat);
CHECK_ERR
}

inline void H5VL_logi_restore_lib_stat (void *&stat) {
inline void H5VL_logi_restore_lib_stat (void *&stat, void *&context) {
herr_t err = 0;

if (stat) {
#if H5_VERSION_GE(2, 0, 0)
err = H5VLclose_lib_context (context);
#else
err = H5VLfinish_lib_state ();
#endif
CHECK_ERR
err = H5VLrestore_lib_state (stat);
CHECK_ERR
Expand Down

0 comments on commit ea07c0c

Please sign in to comment.