Skip to content

Commit

Permalink
Enable setting attribute phase change thresholds.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Jun 30, 2023
1 parent f1c33b2 commit de0578c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
35 changes: 35 additions & 0 deletions include/highfive/H5PropertyList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,41 @@ class LinkCreationOrder {
unsigned _flags;
};


///
/// \brief Set threshold for attribute storage.
///
/// HDF5 can store Attributes in the object header (compact) or in the B-tree
/// (dense). This property sets the threshold when attributes are moved to one
/// or the other storage format.
///
/// Please refer to the upstream documentation of `H5Pset_attr_phase_change` or
/// Section 8 (Attributes) in the User Guide, in particular Subsection 8.5.
///
class AttributePhaseChange {
public:
///
/// \brief Create the property from the threshold values.
///
/// When the number of attributes hits `max_compact` the attributes are
/// moved to dense storage, once the number drops to below `min_dense` the
/// attributes are moved to compact storage.
AttributePhaseChange(unsigned max_compact, unsigned min_dense);

/// \brief Extract threshold values from property list.
explicit AttributePhaseChange(const GroupCreateProps& gcpl);

unsigned max_compact() const;
unsigned min_dense() const;

private:
friend GroupCreateProps;
void apply(hid_t hid) const;

unsigned _max_compact;
unsigned _min_dense;
};

/// @}

} // namespace HighFive
Expand Down
28 changes: 28 additions & 0 deletions include/highfive/bits/H5PropertyList_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,32 @@ inline void LinkCreationOrder::fromPropertyList(hid_t hid) {
"Error getting property for link creation order");
}
}

AttributePhaseChange::AttributePhaseChange(unsigned max_compact, unsigned min_dense)
: _max_compact(max_compact)
, _min_dense(min_dense) {}

AttributePhaseChange::AttributePhaseChange(const GroupCreateProps& gcpl) {
if (H5Pget_attr_phase_change(gcpl.getId(), &_max_compact, &_min_dense) < 0) {
HDF5ErrMapper::ToException<PropertyException>(
"Error getting property for attribute phase change");
}
}

unsigned AttributePhaseChange::max_compact() const {
return _max_compact;
}

unsigned AttributePhaseChange::min_dense() const {
return _min_dense;
}

void AttributePhaseChange::apply(hid_t hid) const {
if (H5Pset_attr_phase_change(hid, _max_compact, _min_dense) < 0) {
HDF5ErrMapper::ToException<PropertyException>(
"Error getting property for attribute phase change");
}
}


} // namespace HighFive
20 changes: 20 additions & 0 deletions src/examples/create_large_attribute.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <H5Fpublic.h>
#include <highfive/H5File.hpp>
#include <highfive/H5Group.hpp>
#include <numeric>
#include <vector>

int main() {
std::vector<double> large_attr(16000, 0.0);

auto fapl = HighFive::FileAccessProps::Default();
fapl.add(HighFive::FileVersionBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST));
HighFive::File file("create_large_attribute.h5", HighFive::File::Truncate, fapl);
auto gcpl = HighFive::GroupCreateProps::Default();
gcpl.add(HighFive::AttributePhaseChange(0, 0));

auto group = file.createGroup("info", gcpl);
group.createAttribute("rig", rig);

return 0;
}

0 comments on commit de0578c

Please sign in to comment.