Skip to content

Commit

Permalink
revise the SZ package for the builtin integration with HDF5 filter
Browse files Browse the repository at this point in the history
  • Loading branch information
disheng222 committed Feb 11, 2022
1 parent fdf44bf commit 1d4dec8
Show file tree
Hide file tree
Showing 48 changed files with 3,939 additions and 3,661 deletions.
72 changes: 52 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,29 @@ endif()
#compile with C-99 and standard C++14
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Check for the existence of certain header files
include (CheckIncludeFiles)
include (CheckFunctionExists)
CHECK_INCLUDE_FILES ("unistd.h" HAVE_UNISTD_H)
CHECK_INCLUDE_FILES ("sys/time.h" HAVE_SYS_TIME_H)

if (WINDOWS)
set (HAVE_GETTIMEOFDAY 1)
endif ()

if (MINGW OR NOT WINDOWS)
CHECK_FUNCTION_EXISTS (gettimeofday HAVE_GETTIMEOFDAY)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
endif ()

# Generate the config.h file containing user settings needed by compilation
configure_file (config.h.cmake ${CMAKE_BINARY_DIR}/config.h @ONLY)

#generate tags for the project if tags exist
option(BUILD_CTAGS "enable ctags generation target" OFF)
if(BUILD_CTAGS)
Expand All @@ -51,34 +70,47 @@ endif()
option(BUILD_SHARED_LIBS "build shared libraries over static libraries" ON)

#find dependencies
option(SZ_FIND_DEPS "find dependent libraries or build ext libraries" ON)
include(GNUInstallDirs)
find_package(PkgConfig)
pkg_search_module(ZSTD IMPORTED_TARGET libzstd)

#by default pass no 3rd party exports
set(thirdparty_export "")

if(ZSTD_FOUND)
set(ZSTD_dep PkgConfig::ZSTD)
else()
add_subdirectory(zstd)
set(ZSTD_dep zstd)
list(APPEND thirdparty_export "zstd")
endif()
if(SZ_FIND_DEPS)
find_package(PkgConfig)
pkg_search_module(ZSTD IMPORTED_TARGET libzstd)

#by default pass no 3rd party exports
set(thirdparty_export "")

if(ZSTD_FOUND)
set(ZSTD_dep PkgConfig::ZSTD)
else()
add_subdirectory(zstd)
set(ZSTD_dep zstd)
list(APPEND thirdparty_export "zstd")
endif()

find_package(ZLIB)
if(ZLIB_FOUND)
set(ZLIB_dep ZLIB::ZLIB)
find_package(ZLIB)
if(ZLIB_FOUND)
set(ZLIB_dep ZLIB::ZLIB)
else()
add_subdirectory(zlib)
set(ZLIB_dep ZLIB)
list(APPEND thirdparty_export "ZLIB")
endif()
else()
add_subdirectory(zlib)
set(ZLIB_dep ZLIB)
list(APPEND thirdparty_export "ZLIB")
add_subdirectory(zstd)
set(ZSTD_dep zstd)
list(APPEND thirdparty_export "zstd")
add_subdirectory(zlib)
set(ZLIB_dep ZLIB)
list(APPEND thirdparty_export "ZLIB")
endif()

find_package(OpenMP)

add_subdirectory(sz)
add_subdirectory(example)
option(BUILD_SZ_EXAMPLES "build sz example" OFF)
if(BUILD_SZ_EXAMPLES)
add_subdirectory(example)
endif()

option(BUILD_PYTHON_WRAPPER "build python wrapper" OFF)
if(BUILD_PYTHON_WRAPPER)
Expand Down
1 change: 1 addition & 0 deletions example/sz.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <math.h>
#include "sz.h"
#include "rw.h"
#include <sys/time.h>

struct timeval startTime;
struct timeval endTime; /* Start and end times */
Expand Down
1 change: 1 addition & 0 deletions example/sz_gsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <gsl/gsl_wavelet.h>
#include "sz.h"
#include "rw.h"
#include <sys/time.h>

struct timeval startTime;
struct timeval endTime; /* Start and end times */
Expand Down
1 change: 1 addition & 0 deletions example/sz_openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sz.h"
#include "rw.h"
#include "sz_omp.h"
#include <sys/time.h>

struct timeval startTime;
struct timeval endTime; /* Start and end times */
Expand Down
1 change: 1 addition & 0 deletions example/sz_pastri.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <math.h>
#include "sz.h"
#include "rw.h"
#include <sys/time.h>

struct timeval startTime;
struct timeval endTime; /* Start and end times */
Expand Down
1 change: 1 addition & 0 deletions example/sz_randomaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <math.h>
#include "sz.h"
#include "rw.h"
#include <sys/time.h>

struct timeval startTime;
struct timeval endTime; /* Start and end times */
Expand Down
2 changes: 1 addition & 1 deletion example/testdouble_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include "sz.h"
Expand Down
4 changes: 2 additions & 2 deletions example/testdouble_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -104,7 +104,7 @@ int main(int argc, char * argv[])


char oriFilePath[650];
strncpy(oriFilePath, zipFilePath, (unsigned)strlen(zipFilePath)-3);
strcpy(oriFilePath, zipFilePath);
oriFilePath[strlen(zipFilePath)-3] = '\0';
double *ori_data = readDoubleData(oriFilePath, &totalNbEle, &status);
if(status!=SZ_SCES)
Expand Down
2 changes: 1 addition & 1 deletion example/testfloat_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include "sz.h"
Expand Down
4 changes: 2 additions & 2 deletions example/testfloat_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -106,7 +106,7 @@ int main(int argc, char * argv[])
//SZ_Finalize();

char oriFilePath[640];
strncpy(oriFilePath, zipFilePath, (unsigned)strlen(zipFilePath)-3);
strcpy(oriFilePath, zipFilePath);
oriFilePath[strlen(zipFilePath)-3] = '\0';
float *ori_data = readFloatData(oriFilePath, &totalNbEle, &status);
if(status!=SZ_SCES)
Expand Down
2 changes: 1 addition & 1 deletion example/testint_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
4 changes: 2 additions & 2 deletions example/testint_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See COPYRIGHT in top-level directory.
*/


#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -274,7 +274,7 @@ void assessDeCompressionData(int dataType, char* zipFilePath, void* decompressed
size_t i, totalNbEle;
int status;
char oriFilePath[640];
strncpy(oriFilePath, zipFilePath, (unsigned)strlen(zipFilePath)-3);
strcpy(oriFilePath, zipFilePath);
oriFilePath[strlen(zipFilePath)-3] = '\0';
int64_t *data = (int64_t*)malloc(sizeof(int64_t)*nbEle);//decompressed data
int64_t *ori_data = (int64_t*)malloc(sizeof(int64_t)*nbEle); //original data
Expand Down
29 changes: 28 additions & 1 deletion sz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
add_library (SZ
if (BUILD_SHARED_LIBS)
set (BUILD_EXT_LIBS_TYPE "SHARED")
else ()
set (BUILD_EXT_LIBS_TYPE "STATIC")
endif ()

add_library (SZ ${BUILD_EXT_LIBS_TYPE}
src/ArithmeticCoding.c
src/ByteToolkit.c
src/CacheTable.c
Expand Down Expand Up @@ -60,10 +66,31 @@ add_library (SZ
)

target_include_directories(SZ
PRIVATE
${CMAKE_BINARY_DIR}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/sz>
)
if (${BUILD_EXT_LIBS_TYPE} MATCHES "SHARED")
set (LIB_RELEASE_NAME "SZ")
set (LIB_DEBUG_NAME "SZ${CMAKE_DEBUG_POSTFIX}")
else ()
if (WIN32 AND NOT MINGW)
set (LIB_RELEASE_NAME "libSZ")
set (LIB_DEBUG_NAME "libSZ${CMAKE_DEBUG_POSTFIX}")
else ()
set (LIB_RELEASE_NAME "SZ")
set (LIB_DEBUG_NAME "SZ${CMAKE_DEBUG_POSTFIX}")
endif ()
endif ()
set_target_properties (SZ PROPERTIES
OUTPUT_NAME ${LIB_RELEASE_NAME}
# OUTPUT_NAME_DEBUG ${LIB_DEBUG_NAME}
OUTPUT_NAME_RELEASE ${LIB_RELEASE_NAME}
OUTPUT_NAME_MINSIZEREL ${LIB_RELEASE_NAME}
OUTPUT_NAME_RELWITHDEBINFO ${LIB_RELEASE_NAME}
)

target_link_libraries (SZ PUBLIC ${ZLIB_dep} ${ZSTD_dep} m)

Expand Down
52 changes: 26 additions & 26 deletions sz/include/ByteToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ extern "C" {

//ByteToolkit.c

unsigned short bytesToUInt16_bigEndian(unsigned char* bytes);
unsigned int bytesToUInt32_bigEndian(unsigned char* bytes);
unsigned long bytesToUInt64_bigEndian(unsigned char* b);
extern unsigned short bytesToUInt16_bigEndian(unsigned char* bytes);
extern unsigned int bytesToUInt32_bigEndian(unsigned char* bytes);
extern unsigned long bytesToUInt64_bigEndian(unsigned char* b);

short bytesToInt16_bigEndian(unsigned char* bytes);
int bytesToInt32_bigEndian(unsigned char* bytes);
long bytesToInt64_bigEndian(unsigned char* b);
int bytesToInt_bigEndian(unsigned char* bytes);
extern short bytesToInt16_bigEndian(unsigned char* bytes);
extern int bytesToInt32_bigEndian(unsigned char* bytes);
extern long bytesToInt64_bigEndian(unsigned char* b);
extern int bytesToInt_bigEndian(unsigned char* bytes);

void intToBytes_bigEndian(unsigned char *b, unsigned int num);
extern void intToBytes_bigEndian(unsigned char *b, unsigned int num);

void int64ToBytes_bigEndian(unsigned char *b, uint64_t num);
void int32ToBytes_bigEndian(unsigned char *b, uint32_t num);
void int16ToBytes_bigEndian(unsigned char *b, uint16_t num);
extern void int64ToBytes_bigEndian(unsigned char *b, uint64_t num);
extern void int32ToBytes_bigEndian(unsigned char *b, uint32_t num);
extern void int16ToBytes_bigEndian(unsigned char *b, uint16_t num);

long bytesToLong_bigEndian(unsigned char* b);
void longToBytes_bigEndian(unsigned char *b, unsigned long num);
extern long bytesToLong_bigEndian(unsigned char* b);
extern void longToBytes_bigEndian(unsigned char *b, unsigned long num);
long doubleToOSEndianLong(double value);
int floatToOSEndianInt(float value);
short getExponent_float(float value);
short getPrecisionReqLength_float(float precision);
short getExponent_double(double value);
short getPrecisionReqLength_double(double precision);
extern short getExponent_float(float value);
extern short getPrecisionReqLength_float(float precision);
extern short getExponent_double(double value);
extern short getPrecisionReqLength_double(double precision);
unsigned char numberOfLeadingZeros_Int(int i);
unsigned char numberOfLeadingZeros_Long(long i);
unsigned char getLeadingNumbers_Int(int v1, int v2);
Expand All @@ -49,15 +49,15 @@ short bytesToShort(unsigned char* bytes);
void shortToBytes(unsigned char* b, short value);
int bytesToInt(unsigned char* bytes);
long bytesToLong(unsigned char* bytes);
float bytesToFloat(unsigned char* bytes);
void floatToBytes(unsigned char *b, float num);
double bytesToDouble(unsigned char* bytes);
void doubleToBytes(unsigned char *b, double num);
extern float bytesToFloat(unsigned char* bytes);
extern void floatToBytes(unsigned char *b, float num);
extern double bytesToDouble(unsigned char* bytes);
extern void doubleToBytes(unsigned char *b, double num);
int extractBytes(unsigned char* byteArray, size_t k, int validLength);
int getMaskRightCode(int m);
int getLeftMovingCode(int kMod8);
int getRightMovingSteps(int kMod8, int resiBitLength);
int getRightMovingCode(int kMod8, int resiBitLength);
extern int getLeftMovingCode(int kMod8);
extern int getRightMovingSteps(int kMod8, int resiBitLength);
extern int getRightMovingCode(int kMod8, int resiBitLength);
short* convertByteDataToShortArray(unsigned char* bytes, size_t byteLength);
unsigned short* convertByteDataToUShortArray(unsigned char* bytes, size_t byteLength);

Expand All @@ -68,8 +68,8 @@ void convertUIntArrayToBytes(unsigned int* states, size_t stateLength, unsigned
void convertLongArrayToBytes(int64_t* states, size_t stateLength, unsigned char* bytes);
void convertULongArrayToBytes(uint64_t* states, size_t stateLength, unsigned char* bytes);

size_t bytesToSize(unsigned char* bytes);
void sizeToBytes(unsigned char* outBytes, size_t size);
extern size_t bytesToSize(unsigned char* bytes);
extern void sizeToBytes(unsigned char* outBytes, size_t size);

void put_codes_to_output(unsigned int buf, int bitSize, unsigned char** p, int* lackBits, size_t *outSize);

Expand Down
22 changes: 11 additions & 11 deletions sz/include/CompressElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ typedef struct LossyCompressionElement
unsigned char integerMidBytes[8];
int integerMidBytes_Length; //they are mid_bits actually
//char curBytes[8];
//int curBytes_Length; //4 for single_precision or 8 for double_precision
//int curBytes_Length; //4 for single_precision or 8 for double_precision
int resMidBitsLength;
int residualMidBits;
} LossyCompressionElement;

char* decompressGroupIDArray(unsigned char* bytes, size_t dataLength);

short computeGroupNum_float(float value);
short computeGroupNum_double(double value);
extern short computeGroupNum_float(float value);
extern short computeGroupNum_double(double value);

void listAdd_double(double last3CmprsData[3], double value);
void listAdd_float(float last3CmprsData[3], float value);
void listAdd_int(int64_t last3CmprsData[3], int64_t value);
extern void listAdd_double(double last3CmprsData[3], double value);
extern void listAdd_float(float last3CmprsData[3], float value);
extern void listAdd_int(int64_t last3CmprsData[3], int64_t value);
void listAdd_int32(int32_t last3CmprsData[3], int32_t value);
void listAdd_float_group(float *groups, int *flags, char groupNum, float oriValue, float decValue, char* curGroupID);
void listAdd_double_group(double *groups, int *flags, char groupNum, double oriValue, double decValue, char* curGroupID);
extern void listAdd_float_group(float *groups, int *flags, char groupNum, float oriValue, float decValue, char* curGroupID);
extern void listAdd_double_group(double *groups, int *flags, char groupNum, double oriValue, double decValue, char* curGroupID);

int validPrediction_double(double minErr, double precision);
int validPrediction_float(float minErr, float precision);
double* generateGroupErrBounds(int errorBoundMode, double realPrecision, double pwrErrBound);
int generateGroupMaxIntervalCount(double* groupErrBounds);

void new_LossyCompressionElement(LossyCompressionElement *lce, int leadingNum, unsigned char* intMidBytes,
void new_LossyCompressionElement(LossyCompressionElement *lce, int leadingNum, unsigned char* intMidBytes,
int intMidBytes_Length, int resiMidBitsLength, int resiBits);
void updateLossyCompElement_Double(unsigned char* curBytes, unsigned char* preBytes,
void updateLossyCompElement_Double(unsigned char* curBytes, unsigned char* preBytes,
int reqBytesLength, int resiBitsLength, LossyCompressionElement *lce);
void updateLossyCompElement_Float(unsigned char* curBytes, unsigned char* preBytes,
extern void updateLossyCompElement_Float(unsigned char* curBytes, unsigned char* preBytes,
int reqBytesLength, int resiBitsLength, LossyCompressionElement *lce);

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 1d4dec8

Please sign in to comment.