1 | #ifndef __XIOS_ONETCDF4_PLUGIN__ |
---|
2 | #define __XIOS_ONETCDF4_PLUGIN__ |
---|
3 | |
---|
4 | #include "xios_spl.hpp" |
---|
5 | |
---|
6 | #if !defined(USING_NETCDF_PAR) |
---|
7 | #include "exception.hpp" |
---|
8 | #endif |
---|
9 | |
---|
10 | #include "mpi.hpp" |
---|
11 | namespace xios |
---|
12 | { |
---|
13 | /*! |
---|
14 | \class CONetCDF4Plugin |
---|
15 | This class computes parameters for HDF5 plugin compression filters : SZ, ZFP ... |
---|
16 | */ |
---|
17 | class CONetCDF4Plugin |
---|
18 | { |
---|
19 | public: |
---|
20 | //! Compute HDF5 plugin parameters from SZ parameters |
---|
21 | static void interpretParametersSZ(const CArray<double,1>& inParams, size_t* nOutParams, unsigned int **outParams) |
---|
22 | { |
---|
23 | if (inParams.numElements()!=5) |
---|
24 | { |
---|
25 | ERROR("CONetCDF4Plugin::interpretParametersSZ(...)", "The SZ compressor requires 5 parameters : " |
---|
26 | << "compression_params=\"(0,4)[mode abs_err rel_err pw_rel_err psnr]\" must be specified," |
---|
27 | << " see details in https://www.mcs.anl.gov/~shdi/download/sz-2.0-user-guide.pdf" ); |
---|
28 | } |
---|
29 | *nOutParams = 9; |
---|
30 | *outParams = new unsigned int[*nOutParams]; |
---|
31 | |
---|
32 | for (size_t iParam=0 ; iParam<(*nOutParams) ; iParam++) (*outParams)[iParam] = 0; |
---|
33 | |
---|
34 | // 1st parameter is the SZ error bound mode |
---|
35 | // https://github.com/szcompressor/SZ/blob/master/hdf5-filter/H5Z-SZ/docs/H5Z-SZ-Guide.pdf |
---|
36 | (*outParams)[0] = (unsigned int)(inParams(0)); |
---|
37 | |
---|
38 | // 1 double -> 2 unsigned int |
---|
39 | for (size_t iParam=0 ; iParam<4 ; iParam++) |
---|
40 | { |
---|
41 | memcpy( &((*outParams)[1+iParam*2]), &(inParams(1+iParam)), sizeof(double) ); |
---|
42 | unsigned int tmp_swap = (*outParams)[1+iParam*2 ]; |
---|
43 | (*outParams)[1+iParam*2 ] = (*outParams)[1+iParam*2+1]; |
---|
44 | (*outParams)[1+iParam*2+1] = tmp_swap; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | //! Compute HDF5 plugin parameters from ZFP parameters |
---|
49 | static void interpretParametersZFP(const CArray<double,1>& inParams, size_t* nOutParams, unsigned int **outParams) |
---|
50 | { |
---|
51 | if (inParams.numElements()==0) // N = f( mode ) |
---|
52 | { |
---|
53 | ERROR("CONetCDF4Plugin::interpretParametersSZ(...)", "The 1st parameter of ZFP compressor is the mode, must be lower or equal to 5" ); |
---|
54 | } |
---|
55 | |
---|
56 | // https://github.com/LLNL/H5Z-ZFP/blob/master/test/test_write.c#L237 |
---|
57 | // https://github.com/LLNL/H5Z-ZFP/blob/master/src/H5Zzfp_version.h |
---|
58 | if (inParams(0) == 1) *nOutParams = 4; // RATE (mode=1) : 1 double |
---|
59 | else if (inParams(0) == 2) *nOutParams = 3; // PRECISION (mode=2) : 2 unsigned int |
---|
60 | else if (inParams(0) == 3) *nOutParams = 4; // ACCURACY (mode=3) : 1 double |
---|
61 | else if (inParams(0) == 4) *nOutParams = 6; // EXPERT (mode=4) : 3 unsigned int + 1 int |
---|
62 | else if (inParams(0) == 5) *nOutParams = 1; // REVERSIBLE (mode=5) : - |
---|
63 | |
---|
64 | *outParams = new unsigned int[*nOutParams]; |
---|
65 | |
---|
66 | // https://github.com/LLNL/H5Z-ZFP/blob/master/src/H5Zzfp_plugin.h |
---|
67 | (*outParams)[0] = (unsigned int)(inParams(0)); |
---|
68 | (*outParams)[1] = 0; |
---|
69 | if ((inParams(0) == 1)||(inParams(0) == 3)) |
---|
70 | { |
---|
71 | memcpy( &((*outParams)[2]), &(inParams(1)), sizeof(double) ); |
---|
72 | } |
---|
73 | else if (inParams(0) == 2) |
---|
74 | { |
---|
75 | (*outParams)[2] = (unsigned int)(inParams(1)); |
---|
76 | } |
---|
77 | else if (inParams(0) == 4) |
---|
78 | { |
---|
79 | (*outParams)[2] = (unsigned int)(inParams(1)); |
---|
80 | (*outParams)[3] = (unsigned int)(inParams(2)); |
---|
81 | (*outParams)[4] = (unsigned int)(inParams(3)); |
---|
82 | (*outParams)[5] = (unsigned int)(inParams(4)); |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|
86 | }; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | #endif // __XIOS_ONETCDF4_PLUGIN__ |
---|