Skip to content

Commit

Permalink
Add access to values of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Feb 5, 2023
1 parent 4e5e971 commit 76a812e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 57 deletions.
10 changes: 2 additions & 8 deletions include/highfive/H5Group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,9 @@ class Group: public Object,
};

inline std::pair<unsigned int, unsigned int> Group::getEstimatedLinkInfo() const {
unsigned int est_num_entries;
unsigned int est_name_len;

auto gcpl = getCreatePropertyList();
if (H5Pget_est_link_info(gcpl.getId(), &est_num_entries, &est_name_len) < 0) {
HDF5ErrMapper::ToException<GroupException>(
std::string("Unable to access group link size property"));
}
return std::make_pair(est_num_entries, est_name_len);
auto eli = EstimatedLinkInfo(gcpl);
return std::make_pair(eli.num_entries(), eli.name_len());
}

} // namespace HighFive
104 changes: 98 additions & 6 deletions include/highfive/H5PropertyList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ template <typename T, typename U>
T get_plist(const U& obj, hid_t (*f)(hid_t)) {
auto hid = f(obj.getId());
if (hid < 0) {
HDF5ErrMapper::ToException<PropertyException>(std::string("Unable to get property list"));
HDF5ErrMapper::ToException<PropertyException>("Unable to get property list");
}
T t{};
t._hid = hid;
Expand Down Expand Up @@ -244,15 +244,29 @@ class FileVersionBounds {
: _low(low)
, _high(high) {}

FileVersionBounds(const FileAccessProps& fapl) {
if (H5Pget_libver_bounds(fapl.getId(), &_low, &_high) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Unable to access file version bounds");
}
}

H5F_libver_t get_low() const {
return _low;
}

H5F_libver_t get_high() const {
return _high;
}

private:
friend FileAccessProps;
void apply(const hid_t list) const {
if (H5Pset_libver_bounds(list, _low, _high) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Error setting file version bounds");
}
}
const H5F_libver_t _low;
const H5F_libver_t _high;
H5F_libver_t _low;
H5F_libver_t _high;
};

///
Expand All @@ -265,14 +279,25 @@ class MetadataBlockSize {
MetadataBlockSize(hsize_t size)
: _size(size) {}

MetadataBlockSize(const FileAccessProps& fapl) {
if (H5Pget_meta_block_size(fapl.getId(), &_size) < 0) {
HDF5ErrMapper::ToException<PropertyException>(
"Unable to access file metadata block size");
}
}

hsize_t get_size() const {
return _size;
}

private:
friend FileAccessProps;
void apply(const hid_t list) const {
if (H5Pset_meta_block_size(list, _size) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Error setting metadata block size");
}
}
const hsize_t _size;
hsize_t _size;
};

#if H5_VERSION_GE(1, 10, 1)
Expand All @@ -292,6 +317,25 @@ class FileSpaceStrategy {
/// \param threshold The free-space manager wont track sections small than this threshold.
FileSpaceStrategy(H5F_fspace_strategy_t strategy, hbool_t persist, hsize_t threshold);


FileSpaceStrategy(const FileCreateProps& fcpl) {
if (H5Pget_file_space_strategy(fcpl.getId(), &_strategy, &_persist, &_threshold) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Unable to get file space strategy");
}
}

H5F_fspace_strategy_t get_strategy() const {
return _strategy;
}

hbool_t get_persist() const {
return _persist;
}

hsize_t get_threshold() const {
return _threshold;
}

private:
friend FileCreateProps;

Expand Down Expand Up @@ -319,6 +363,16 @@ class FileSpacePageSize {
/// \param page_size The page size in bytes.
explicit FileSpacePageSize(hsize_t page_size);

FileSpacePageSize(const FileCreateProps& fcpl) {
if (H5Pget_file_space_page_size(fcpl.getId(), &_page_size) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Unable to get file space page size");
}
}

hsize_t get_page_size() const {
return _page_size;
}

private:
friend FileCreateProps;

Expand Down Expand Up @@ -370,11 +424,26 @@ class EstimatedLinkInfo {
: _entries(entries)
, _length(length) {}

EstimatedLinkInfo(const GroupCreateProps& gcpl) {
if (H5Pget_est_link_info(gcpl.getId(), &_entries, &_length) < 0) {
HDF5ErrMapper::ToException<PropertyException>(
"Unable to access group link size property");
}
}

unsigned num_entries() const {
return _entries;
}

unsigned name_len() const {
return _length;
}

private:
friend GroupCreateProps;
void apply(hid_t hid) const;
const unsigned _entries;
const unsigned _length;
unsigned _entries;
unsigned _length;
};


Expand Down Expand Up @@ -496,6 +565,29 @@ class UseCollectiveIO {
void apply(hid_t hid) const;
bool _enable;
};

class MpioNoCollectiveCause {
public:
MpioNoCollectiveCause(const DataTransferProps& dxpl) {
if (H5Pget_mpio_no_collective_cause(dxpl.getId(), &_local_cause, &_global_cause) < 0) {
HDF5ErrMapper::ToException<PropertyException>(
"Failed to check mpio_no_collective_cause.");
}
}

uint32_t get_local_cause() const {
return _local_cause;
}

uint32_t get_global_cause() const {
return _global_cause;
}

private:
friend DataTransferProps;
uint32_t _local_cause;
uint32_t _global_cause;
};
#endif

} // namespace HighFive
Expand Down
36 changes: 6 additions & 30 deletions include/highfive/bits/H5File_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,56 +92,32 @@ inline const std::string& File::getName() const noexcept {
}

inline hsize_t File::getMetadataBlockSize() const {
hsize_t size;
auto fapl = getAccessPropertyList();
if (H5Pget_meta_block_size(fapl.getId(), &size) < 0) {
HDF5ErrMapper::ToException<FileException>(
std::string("Unable to access file metadata block size"));
}
return size;
return MetadataBlockSize(fapl).get_size();
}

inline std::pair<H5F_libver_t, H5F_libver_t> File::getVersionBounds() const {
H5F_libver_t low;
H5F_libver_t high;
auto fapl = getAccessPropertyList();
if (H5Pget_libver_bounds(fapl.getId(), &low, &high) < 0) {
HDF5ErrMapper::ToException<FileException>(
std::string("Unable to access file version bounds"));
}
return std::make_pair(low, high);
auto fileVer = FileVersionBounds(fapl);
return std::make_pair(fileVer.get_low(), fileVer.get_high());
}

#if H5_VERSION_GE(1, 10, 1)
inline H5F_fspace_strategy_t File::getFileSpaceStrategy() const {
auto fcpl = getCreatePropertyList();

H5F_fspace_strategy_t strategy;
hbool_t persist;
hsize_t threshold;

if (H5Pget_file_space_strategy(fcpl.getId(), &strategy, &persist, &threshold) < 0) {
HDF5ErrMapper::ToException<FileException>(std::string("Unable to get file space strategy"));
}

return strategy;
FileSpaceStrategy spaceStrategy(fcpl);
return spaceStrategy.get_strategy();
}

inline hsize_t File::getFileSpacePageSize() const {
auto fcpl = getCreatePropertyList();
hsize_t page_size;

if (getFileSpaceStrategy() != H5F_FSPACE_STRATEGY_PAGE) {
HDF5ErrMapper::ToException<FileException>(
std::string("Cannot obtain page size as paged allocation is not used."));
}

if (H5Pget_file_space_page_size(fcpl.getId(), &page_size) < 0) {
HDF5ErrMapper::ToException<FileException>(
std::string("Unable to get file space page size"));
}

return page_size;
return FileSpacePageSize(fcpl).get_page_size();
}
#endif

Expand Down
10 changes: 3 additions & 7 deletions src/examples/parallel_hdf5_collective_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ const std::string DATASET_NAME("dset");
// MPI-IO operations were used, one may. Conveniently, this also provides identifiers
// of the cause for not using collective MPI calls.
void check_collective_io(const HighFive::DataTransferProps& xfer_props) {
uint32_t local_cause = 0, global_cause = 0;
auto err = H5Pget_mpio_no_collective_cause(xfer_props.getId(), &local_cause, &global_cause);
if (err < 0) {
throw std::runtime_error("Failed to check mpio_no_collective_cause.");
}
if (local_cause || global_cause) {
auto mnccp = HighFive::MpioNoCollectiveCause(xfer_props);
if (mnccp.get_local_cause() || mnccp.get_global_cause()) {
std::cout
<< "The operation was successful, but couldn't use collective MPI-IO. local cause: "
<< local_cause << " global cause:" << global_cause << std::endl;
<< mnccp.get_local_cause() << " global cause:" << mnccp.get_global_cause() << std::endl;
}
}

Expand Down
9 changes: 3 additions & 6 deletions tests/unit/tests_high_five_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ struct MpiFixture {
};

void check_was_collective(const DataTransferProps& xfer_props) {
uint32_t local_cause = 0, global_cause = 0;
if (H5Pget_mpio_no_collective_cause(xfer_props.getId(), &local_cause, &global_cause) < 0) {
throw std::runtime_error("Failed to check mpio_no_collective_cause.");
}
CHECK(local_cause == 0);
CHECK(global_cause == 0);
auto mnccp = MpioNoCollectiveCause(xfer_props);
CHECK(mnccp.get_local_cause() == 0);
CHECK(mnccp.get_global_cause() == 0);
}

template <typename T>
Expand Down

0 comments on commit 76a812e

Please sign in to comment.