From eb61d86761870048f84a379cbb0866a4fb1d910d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Thu, 18 Aug 2016 12:42:57 +0100 Subject: [PATCH] Allow the users to change the compression rate of datasets. Compression is switched off by default for performance. --- examples/parameter_example.yml | 1 + src/engine.c | 2 ++ src/engine.h | 1 + src/serial_io.c | 10 ++++++---- src/single_io.c | 10 ++++++---- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index edb0885d62..278990c765 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -25,6 +25,7 @@ Snapshots: basename: output # Common part of the name of output files time_first: 0. # Time of the first output (in internal units) delta_time: 0.01 # Time difference between consecutive outputs (in internal units) + compression: 0 # (Optional) Set the level of compression of the HDF5 datasets [0-9]. 0 does no compression. UnitMass_in_cgs: 1 # (Optional) Unit system for the outputs (Grams) UnitLength_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters) UnitVelocity_in_cgs: 1 # (Optional) Unit system for the outputs (Centimeters per second) diff --git a/src/engine.c b/src/engine.c index fc8850d0cb..a626e611bc 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2918,6 +2918,8 @@ void engine_init(struct engine *e, struct space *s, parser_get_param_double(params, "Snapshots:delta_time"); e->ti_nextSnapshot = 0; parser_get_param_string(params, "Snapshots:basename", e->snapshotBaseName); + e->snapshotCompression = + parser_get_opt_param_int(params, "Snapshots:compression", 0); e->snapshotUnits = malloc(sizeof(struct UnitSystem)); units_init_default(e->snapshotUnits, params, "Snapshots", internal_units); e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min"); diff --git a/src/engine.h b/src/engine.h index e0c0f6a92e..ddb847d70c 100644 --- a/src/engine.h +++ b/src/engine.h @@ -150,6 +150,7 @@ struct engine { double deltaTimeSnapshot; int ti_nextSnapshot; char snapshotBaseName[200]; + int snapshotCompression; struct UnitSystem *snapshotUnits; /* Statistics information */ diff --git a/src/serial_io.c b/src/serial_io.c index c981e5e31d..7ecf88c448 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -224,10 +224,12 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, } /* Impose data compression */ - h_err = H5Pset_deflate(h_prop, 4); - if (h_err < 0) { - error("Error while setting compression options for field '%s'.", - props.name); + if(e->snapshotCompression > 0) { + h_err = H5Pset_deflate(h_prop, e->snapshotCompression); + if (h_err < 0) { + error("Error while setting compression options for field '%s'.", + props.name); + } } /* Create dataset */ diff --git a/src/single_io.c b/src/single_io.c index 93faab6717..de14a264df 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -261,10 +261,12 @@ void writeArray(struct engine* e, hid_t grp, char* fileName, FILE* xmfFile, } /* Impose data compression */ - h_err = H5Pset_deflate(h_prop, 4); - if (h_err < 0) { - error("Error while setting compression options for field '%s'.", - props.name); + if (e->snapshotCompression > 0) { + h_err = H5Pset_deflate(h_prop, e->snapshotCompression); + if (h_err < 0) { + error("Error while setting compression options for field '%s'.", + props.name); + } } /* Create dataset */ -- GitLab