Skip to content

Commit 105c7d0

Browse files
authored
Soft disable deflate filter and add profiling regions to hdf5 output (#899)
* Deflate compression filter is not called any more if compression is soft disabled * Sprinkle profiling regions over hdf5 outputs
1 parent d9d2212 commit 105c7d0

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [[PR 868]](https://github.com/parthenon-hpc-lab/parthenon/pull/868) Add block-local face, edge, and nodal fields and allow for packing
1313

1414
### Changed (changing behavior/API/variables/...)
15+
- [[PR 897]](https://github.com/parthenon-hpc-lab/parthenon/pull/897) Deflate compression filter is not called any more if compression is soft disabled
1516
- [[PR 896]](https://github.com/parthenon-hpc-lab/parthenon/pull/896) Update Kokkos integration to support installed version. Use `serial` (flat MPI) host parallelization by default (instead of OpenMP)
1617
- [[PR 894]](https://github.com/parthenon-hpc-lab/parthenon/pull/894) Demand that sparse pool order sparse ids
1718
- [[PR 888]](https://github.com/parthenon-hpc-lab/parthenon/pull/888) Bump Kokkos submodule to 4.0.1

doc/sphinx/src/outputs.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ allocated only in a few blocks, because all other blocks would write
7171
zeros of these variables, which can drastically increase output file
7272
size (and decrease I/O performance) without compression. The optional
7373
parameter ``hdf5_compression_level`` can be used to set the compression
74-
level (between 1 and 9, default is 5). Compression can be disabled
75-
altogether with the CMake build option
74+
level (between 1 and 9, default is 5). If ``parthenon`` is compiled with
75+
support for compression, this also enables (logical) chunking of the
76+
data in blocks of ``nx1*nx2*nx3``. Compression (and thus chunking) can
77+
be disabled altogether with the CMake build option
7678
``PARTHENON_DISABLE_HDF5_COMPRESSION``.
7779
See the :ref:`building` for more details.
7880

src/outputs/parthenon_hdf5.cpp

+47-7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
6464
using namespace HDF5;
6565
using namespace OutputUtils;
6666

67+
if constexpr (WRITE_SINGLE_PRECISION) {
68+
Kokkos::Profiling::pushRegion("PHDF5::WriteOutputFileSinglePrec");
69+
} else {
70+
Kokkos::Profiling::pushRegion("PHDF5::WriteOutputFileRealPrec");
71+
}
72+
6773
// writes all graphics variables to hdf file
6874
// HDF5 structures
6975
// Also writes companion xdmf file
@@ -111,7 +117,9 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
111117
// -------------------------------------------------------------------------------- //
112118
// WRITING ATTRIBUTES //
113119
// -------------------------------------------------------------------------------- //
120+
Kokkos::Profiling::pushRegion("write Attributes");
114121
{
122+
Kokkos::Profiling::pushRegion("write input");
115123
// write input key-value pairs
116124
std::ostringstream oss;
117125
pin->ParameterDump(oss);
@@ -120,11 +128,13 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
120128
const H5G input_group = MakeGroup(file, "/Input");
121129

122130
HDF5WriteAttribute("File", oss.str().c_str(), input_group);
123-
} // Input section
131+
Kokkos::Profiling::popRegion(); // write input
132+
} // Input section
124133

125134
// we'll need this again at the end
126135
const H5G info_group = MakeGroup(file, "/Info");
127136
{
137+
Kokkos::Profiling::pushRegion("write Info");
128138
HDF5WriteAttribute("OutputFormatVersion", OUTPUT_VERSION_FORMAT, info_group);
129139

130140
if (tm != nullptr) {
@@ -178,18 +188,22 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
178188
}
179189

180190
HDF5WriteAttribute("BoundaryConditions", boundary_condition_str, info_group);
181-
} // Info section
191+
Kokkos::Profiling::popRegion(); // write Info
192+
} // Info section
182193

183194
// write Params
184195
{
196+
Kokkos::Profiling::pushRegion("behold: write Params");
185197
const H5G params_group = MakeGroup(file, "/Params");
186198

187199
for (const auto &package : pm->packages.AllPackages()) {
188200
const auto state = package.second;
189201
// Write all params that can be written as HDF5 attributes
190202
state->AllParams().WriteAllToHDF5(state->label(), params_group);
191203
}
192-
} // Params section
204+
Kokkos::Profiling::popRegion(); // behold: write Params
205+
} // Params section
206+
Kokkos::Profiling::popRegion(); // write Attributes
193207

194208
// -------------------------------------------------------------------------------- //
195209
// WRITING MESHBLOCK METADATA //
@@ -226,6 +240,7 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
226240

227241
// write Blocks metadata
228242
{
243+
Kokkos::Profiling::pushRegion("write block metadata");
229244
const H5G gBlocks = MakeGroup(file, "/Blocks");
230245

231246
// write Xmin[ndim] for blocks
@@ -255,9 +270,11 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
255270
HDF5Write2D(gBlocks, "loc.level-gid-lid-cnghost-gflag", tmpID.data(), p_loc_offset,
256271
p_loc_cnt, p_glob_cnt, pl_xfer);
257272
}
258-
} // Block section
273+
Kokkos::Profiling::popRegion(); // write block metadata
274+
} // Block section
259275

260276
// Write mesh coordinates to file
277+
Kokkos::Profiling::pushRegion("write mesh coords");
261278
for (const bool face : {true, false}) {
262279
const H5G gLocations = MakeGroup(file, face ? "/Locations" : "/VolumeLocations");
263280

@@ -280,10 +297,12 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
280297
HDF5Write2D(gLocations, "z", loc_z.data(), p_loc_offset, p_loc_cnt, p_glob_cnt,
281298
pl_xfer);
282299
}
300+
Kokkos::Profiling::popRegion(); // write mesh coords
283301

284302
// Write Levels and Logical Locations with the level for each Meshblock loclist contains
285303
// levels and logical locations for all meshblocks on all ranks
286304
{
305+
Kokkos::Profiling::pushRegion("write levels and locations");
287306
const auto &loclist = pm->GetLocList();
288307

289308
std::vector<std::int64_t> levels;
@@ -310,11 +329,13 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
310329

311330
// reset for collective output
312331
local_count[0] = num_blocks_local;
332+
Kokkos::Profiling::popRegion(); // write levels and locations
313333
}
314334

315335
// -------------------------------------------------------------------------------- //
316336
// WRITING VARIABLES DATA //
317337
// -------------------------------------------------------------------------------- //
338+
Kokkos::Profiling::pushRegion("write all variable data");
318339

319340
// All blocks have the same list of variable metadata that exist in the entire
320341
// simulation, but not all variables may be allocated on all blocks
@@ -391,6 +412,7 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
391412

392413
// for each variable we write
393414
for (auto &vinfo : all_vars_info) {
415+
Kokkos::Profiling::pushRegion("write variable loop");
394416
// not really necessary, but doesn't hurt
395417
memset(tmpData.data(), 0, tmpData.size() * sizeof(OutT));
396418

@@ -448,13 +470,18 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
448470

449471
#ifndef PARTHENON_DISABLE_HDF5_COMPRESSION
450472
PARTHENON_HDF5_CHECK(H5Pset_chunk(pl_dcreate, ndim, chunk_size.data()));
451-
PARTHENON_HDF5_CHECK(
452-
H5Pset_deflate(pl_dcreate, std::min(9, output_params.hdf5_compression_level)));
473+
// Do not run the pipeline if compression is soft disabled.
474+
// By default data would still be passed, which may result in slower output.
475+
if (output_params.hdf5_compression_level > 0) {
476+
PARTHENON_HDF5_CHECK(
477+
H5Pset_deflate(pl_dcreate, std::min(9, output_params.hdf5_compression_level)));
478+
}
453479
#endif
454480

455481
// load up data
456482
hsize_t index = 0;
457483

484+
Kokkos::Profiling::pushRegion("fill host output buffer");
458485
// for each local mesh block
459486
for (size_t b_idx = 0; b_idx < num_blocks_local; ++b_idx) {
460487
const auto &pmb = pm->block_list[b_idx];
@@ -520,11 +547,16 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
520547
}
521548
}
522549
}
550+
Kokkos::Profiling::popRegion(); // fill host output buffer
523551

552+
Kokkos::Profiling::pushRegion("write variable data");
524553
// write data to file
525554
HDF5WriteND(file, var_name, tmpData.data(), ndim, p_loc_offset, p_loc_cnt, p_glob_cnt,
526555
pl_xfer, pl_dcreate);
556+
Kokkos::Profiling::popRegion(); // write variable data
557+
Kokkos::Profiling::popRegion(); // write variable loop
527558
}
559+
Kokkos::Profiling::popRegion(); // write all variable data
528560

529561
// names of variables
530562
std::vector<std::string> var_names;
@@ -557,6 +589,7 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
557589
// write SparseInfo and SparseFields (we can't write a zero-size dataset, so only write
558590
// this if we have sparse fields)
559591
if (num_sparse > 0) {
592+
Kokkos::Profiling::pushRegion("write sparse info");
560593
local_count[1] = global_count[1] = num_sparse;
561594

562595
HDF5Write2D(file, "SparseInfo", sparse_allocated.get(), p_loc_offset, p_loc_cnt,
@@ -569,12 +602,14 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
569602

570603
const H5D dset = H5D::FromHIDCheck(H5Dopen2(file, "SparseInfo", H5P_DEFAULT));
571604
HDF5WriteAttribute("SparseFields", names, dset);
572-
} // SparseInfo and SparseFields sections
605+
Kokkos::Profiling::popRegion(); // write sparse info
606+
} // SparseInfo and SparseFields sections
573607

574608
// -------------------------------------------------------------------------------- //
575609
// WRITING PARTICLE DATA //
576610
// -------------------------------------------------------------------------------- //
577611

612+
Kokkos::Profiling::pushRegion("write particle data");
578613
AllSwarmInfo swarm_info(pm->block_list, output_params.swarms, restart_);
579614
for (auto &[swname, swinfo] : swarm_info.all_info) {
580615
const H5G g_swm = MakeGroup(file, swname);
@@ -635,9 +670,14 @@ void PHDF5Output::WriteOutputFileImpl(Mesh *pm, ParameterInput *pin, SimTime *tm
635670
pl_xfer);
636671
}
637672
}
673+
Kokkos::Profiling::popRegion(); // write particle data
638674

675+
Kokkos::Profiling::pushRegion("genXDMF");
639676
// generate XDMF companion file
640677
XDMF::genXDMF(filename, pm, tm, nx1, nx2, nx3, all_vars_info, swarm_info);
678+
Kokkos::Profiling::popRegion(); // genXDMF
679+
680+
Kokkos::Profiling::popRegion(); // WriteOutputFile???Prec
641681
}
642682

643683
std::string PHDF5Output::GenerateFilename_(ParameterInput *pin, SimTime *tm,

0 commit comments

Comments
 (0)