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 7771bcd commit ed4f875
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");
}
}

inline AttributePhaseChange::AttributePhaseChange(unsigned max_compact, unsigned min_dense)

Check warning on line 547 in include/highfive/bits/H5PropertyList_misc.hpp

View check run for this annotation

Codecov / codecov/patch

include/highfive/bits/H5PropertyList_misc.hpp#L547

Added line #L547 was not covered by tests
: _max_compact(max_compact)
, _min_dense(min_dense) {}

Check warning on line 549 in include/highfive/bits/H5PropertyList_misc.hpp

View check run for this annotation

Codecov / codecov/patch

include/highfive/bits/H5PropertyList_misc.hpp#L549

Added line #L549 was not covered by tests

inline 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");
}
}

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

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

inline 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);

Check warning on line 8 in src/examples/create_large_attribute.cpp

View check run for this annotation

Codecov / codecov/patch

src/examples/create_large_attribute.cpp#L7-L8

Added lines #L7 - L8 were not covered by tests

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));

Check warning on line 14 in src/examples/create_large_attribute.cpp

View check run for this annotation

Codecov / codecov/patch

src/examples/create_large_attribute.cpp#L10-L14

Added lines #L10 - L14 were not covered by tests

auto group = file.createGroup("grp", gcpl);
group.createAttribute("attr", large_attr);

Check warning on line 17 in src/examples/create_large_attribute.cpp

View check run for this annotation

Codecov / codecov/patch

src/examples/create_large_attribute.cpp#L16-L17

Added lines #L16 - L17 were not covered by tests

return 0;

Check warning on line 19 in src/examples/create_large_attribute.cpp

View check run for this annotation

Codecov / codecov/patch

src/examples/create_large_attribute.cpp#L19

Added line #L19 was not covered by tests
}

0 comments on commit ed4f875

Please sign in to comment.