Skip to content

Commit 1e8143c

Browse files
committed
Use Blosc2 filter
not yet integrated into CI
1 parent b89713b commit 1e8143c

1 file changed

Lines changed: 73 additions & 2 deletions

File tree

examples/7_extended_write_serial.cpp

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
#include <openPMD/openPMD.hpp>
22

3-
#include <algorithm>
3+
#if __has_include(<blosc2_filter.h>)
4+
#include <blosc2_filter.h>
5+
#define OPENPMD_USE_BLOSC2_FILTER 1
6+
#else
7+
#define OPENPMD_USE_BLOSC2_FILTER 0
8+
#endif
9+
410
#include <iostream>
11+
#include <numeric>
12+
#include <stdexcept>
513

614
int main()
715
{
816
namespace io = openPMD;
917

18+
#if OPENPMD_USE_BLOSC2_FILTER
19+
/*
20+
* This registers the Blosc2 plugin from
21+
* https://github.com/Blosc/HDF5-Blosc2 as a demonstration on how to
22+
* activate and configure dynamic HDF5 filter plugins through openPMD.
23+
*/
24+
25+
char *version, *date;
26+
int r = register_blosc2(&version, &date);
27+
if (r < 1)
28+
{
29+
throw std::runtime_error("Unable to register Blosc2 plugin with HDF5.");
30+
}
31+
else
32+
{
33+
std::cout << "Blosc2 plugin registered in version " << version
34+
<< " and date " << date << "." << std::endl;
35+
}
36+
#endif
37+
1038
{
1139
auto f = io::Series(
1240
"working/directory/2D_simData.h5",
@@ -91,7 +119,7 @@ int main()
91119
}
92120

93121
io::Mesh mesh = cur_it.meshes["lowRez_2D_field"];
94-
mesh.setAxisLabels({"x", "y"});
122+
mesh.setAxisLabels({"x", "y", "z"});
95123

96124
// data is assumed to reside behind a pointer as a contiguous
97125
// column-major array shared data ownership during IO is indicated with
@@ -134,6 +162,49 @@ int main()
134162
d.options = datasetConfig;
135163
mesh["x"].resetDataset(d);
136164

165+
#if OPENPMD_USE_BLOSC2_FILTER
166+
/*
167+
* FILTER_BLOSC2 resolves to 32026, the permanent plugin ID registered
168+
* with the HDF Group. Plugin-specific options are given via c_values,
169+
* refer to the specific plugin's documentation. For the Blosc2 plugin,
170+
* parameters 0, 1, 2 and 3 are reserved. Parameter 4 is the compression
171+
* level, parameter 5 is a boolean for activating shuffling and
172+
* parameter 6 denotes the compression method.
173+
*/
174+
d.options = R"END(
175+
{
176+
"adios2": {
177+
"dataset": {
178+
"operators": [
179+
{
180+
"type": "zlib",
181+
"parameters": {
182+
"clevel": 9
183+
}
184+
}
185+
]
186+
}
187+
},
188+
"hdf5": {
189+
"dataset": {
190+
"chunks": "auto",
191+
"permanent_filters": {
192+
"id": )END" +
193+
std::to_string(FILTER_BLOSC2) + R"END(,
194+
"flags": "mandatory",
195+
"c_values": [0, 0, 0, 0, 4, 1, )END" +
196+
std::to_string(BLOSC_ZSTD) + R"END(]
197+
}
198+
}
199+
}
200+
})END";
201+
#endif
202+
d.extent = {500, 500};
203+
mesh["z"].resetDataset(d);
204+
auto span = mesh["z"].storeChunk<double>({0, 0}, {500, 500});
205+
auto span_data = span.currentBuffer();
206+
std::iota(span_data.begin(), span_data.end(), 41.);
207+
137208
io::ParticleSpecies electrons = cur_it.particles["electrons"];
138209

139210
io::Extent mpiDims{4};

0 commit comments

Comments
 (0)