Skip to content

Commit 78fbf4e

Browse files
authored
Add HDF5 option to configure script and add environment variables for configuring HDF5 (#5392)
## Summary - Resolves #5391 - Adds an `--hdf5` flag to the `configure` script to allow configuring AMReX with HDF5 support - Adds two new environment variables: - `HDF5_ALIGNMENT_SIZE` which is passed to `H5Pset_alignment()` - `HDF5_BLOCK_SIZE` which is passed to `H5Pset_meta_block_size()` ## Additional background - The two new environment variables mirror how the [other HDF5 configuration option](https://github.com/AMReX-Codes/amrex/blob/development/Src/Extern/HDF5/AMReX_PlotFileUtilHDF5.cpp#L460-L467) is currently set. - ~If we want to move forward with these changes, I will add appropriate documentation before taking the PR out of draft.~ ## Checklist The proposed changes: - [ ] ~fix a bug or incorrect behavior in AMReX~ - [x] add new capabilities to AMReX - [ ] ~changes answers in the test suite to more than roundoff level~ - [ ] ~are likely to significantly affect the results of downstream AMReX users~ - [x] include documentation in the code and/or rst files, if appropriate
1 parent d49c43f commit 78fbf4e

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

Docs/sphinx_documentation/source/IO.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ Using compression requires data to be stored in a chunked format. The size of th
234234
chunks can (and generally should) be configured by changing the ``HDF5_CHUNK_SIZE``
235235
environment variable, with a default value of 1024 elements provided.
236236

237+
For MPI-enabled builds, two additional file access properties can be tuned via
238+
environment variables. ``HDF5_ALIGNMENT_SIZE`` (in bytes, default 16 MiB) sets
239+
both the threshold and alignment passed to ``H5Pset_alignment``: object
240+
allocations of at least this size are aligned to a multiple of it, while
241+
smaller allocations are left unpadded. ``HDF5_BLOCK_SIZE`` (in bytes, default
242+
4 MiB) sets the minimum metadata block allocation size via
243+
``H5Pset_meta_block_size``, which aggregates small metadata writes to reduce
244+
I/O overhead on parallel file systems.
245+
237246
HDF5 Asynchronous Output
238247
------------------------
239248
The HDF5 output also comes with its own asynchronous I/O support, which is different

GNUmakefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ endif
5151
ifeq ($(USE_BITTREE),TRUE)
5252
Pdirs += Extern/Bittree
5353
endif
54+
ifeq ($(USE_HDF5),TRUE)
55+
Pdirs += Extern/HDF5
56+
endif
5457
Ppack := $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package)
5558
include $(Ppack)
5659

Src/Extern/HDF5/AMReX_PlotFileUtilHDF5.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,23 @@ static void SetHDF5fapl(hid_t fapl)
117117
H5Pset_fapl_mpio(fapl, comm, MPI_INFO_NULL);
118118

119119
// Alignment and metadata block size
120-
int alignment = 16 * 1024 * 1024;
121-
int blocksize = 4 * 1024 * 1024;
120+
const char *alignment_env = getenv("HDF5_ALIGNMENT_SIZE");
121+
const char *block_env = getenv("HDF5_BLOCK_SIZE");
122+
123+
hsize_t alignment = 16 * 1024 * 1024; // 16 MiB
124+
hsize_t block = 4 * 1024 * 1024; // 4 MiB
125+
126+
if (alignment_env != NULL) {
127+
alignment = (hsize_t)strtoull(alignment_env, NULL, 10);
128+
}
129+
if (block_env != NULL) {
130+
block = (hsize_t)strtoull(block_env, NULL, 10);
131+
}
132+
133+
// Threshold = alignment value: only allocations >= alignment bytes
134+
// get aligned. Avoids padding small allocations up to 16 MiB.
122135
H5Pset_alignment(fapl, alignment, alignment);
123-
H5Pset_meta_block_size(fapl, blocksize);
136+
H5Pset_meta_block_size(fapl, block);
124137

125138
// Collective metadata ops
126139
H5Pset_coll_metadata_write(fapl, true);

Tools/libamrex/configure.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def configure(argv):
132132
help="Enable Bittree mode [default=no]",
133133
choices=["yes","no"],
134134
default="no")
135+
parser.add_argument("--enable-hdf5",
136+
help="Enable HDF5 output mode [default=no]",
137+
choices=["yes","no"],
138+
default="no")
135139
args = parser.parse_args()
136140

137141
if args.with_fortran == "no":
@@ -174,6 +178,7 @@ def configure(argv):
174178
f.write("CUDA_ARCH = " + args.cuda_arch.strip() + "\n")
175179
f.write("AMREX_NO_PROBINIT = {}\n".format("TRUE" if args.enable_probinit == "no" else "FALSE"))
176180
f.write("USE_BITTREE = {}\n".format("TRUE" if args.enable_bittree == "yes" else "FALSE"))
181+
f.write("USE_HDF5 = {}\n".format("TRUE" if args.enable_hdf5 == "yes" else "FALSE"))
177182
f.write("\n")
178183

179184
fin = open("GNUmakefile.in","r")

0 commit comments

Comments
 (0)