diff --git a/include/SZ3/api/impl/SZAlgoLorenzoReg.hpp b/include/SZ3/api/impl/SZAlgoLorenzoReg.hpp index 5047f95d..12a69343 100644 --- a/include/SZ3/api/impl/SZAlgoLorenzoReg.hpp +++ b/include/SZ3/api/impl/SZAlgoLorenzoReg.hpp @@ -31,8 +31,8 @@ std::shared_ptr> make_compressor_typetwo_lorenz int methodCnt = (conf.lorenzo + conf.lorenzo2 + conf.regression + conf.regression2); int use_single_predictor = (methodCnt == 1); if (methodCnt == 0) { - printf("All lorenzo and regression methods are disabled.\n"); - exit(0); + fprintf(stderr, "All lorenzo and regression methods are disabled.\n"); + throw std::invalid_argument("All lorenzo and regression methods are disabled."); } if (conf.lorenzo) { if (use_single_predictor) { diff --git a/include/SZ3/api/impl/SZDispatcher.hpp b/include/SZ3/api/impl/SZDispatcher.hpp index 8b9c65bd..1e2ccfa3 100644 --- a/include/SZ3/api/impl/SZDispatcher.hpp +++ b/include/SZ3/api/impl/SZDispatcher.hpp @@ -27,8 +27,8 @@ size_t SZ_compress_dispatcher(Config &conf, const T *data, uchar *cmpData, size_ } else if (conf.cmprAlgo == ALGO_NOPRED) { cmpSize = SZ_compress_nopred(conf, dataCopy.data(), cmpData, cmpCap); } else { - printf("SZ_compress_dispatcher, Method not supported\n"); - exit(0); + fprintf(stderr, "Unknown compression algorithm\n"); + throw std::invalid_argument("Unknown compression algorithm"); } } catch (std::length_error &e) { @@ -58,6 +58,7 @@ size_t SZ_compress_dispatcher(Config &conf, const T *data, uchar *cmpData, size_ if (zstdCmpSize < cmpSize) { conf.cmprAlgo = ALGO_LOSSLESS; if (zstdCmpSize > cmpCap) { + fprintf(stderr, SZ_ERROR_COMP_BUFFER_NOT_LARGE_ENOUGH); throw std::length_error(SZ_ERROR_COMP_BUFFER_NOT_LARGE_ENOUGH); } memcpy(cmpData, zstdCmpData, zstdCmpSize); @@ -78,7 +79,8 @@ void SZ_decompress_dispatcher(Config &conf, const uchar *cmpData, size_t cmpSize auto decDataPos = reinterpret_cast(decData); zstd.decompress(cmpData, cmpSize, decDataPos, decDataSize); if (decDataSize != conf.num * sizeof(T)) { - throw std::runtime_error("Decompressed data size does not match the original data size\n"); + fprintf(stderr, "Decompressed data size does not match the original data size\n"); + throw std::runtime_error("Decompressed data size does not match the original data size"); } } else if (conf.cmprAlgo == ALGO_LORENZO_REG) { SZ_decompress_LorenzoReg(conf, cmpData, cmpSize, decData); @@ -87,8 +89,8 @@ void SZ_decompress_dispatcher(Config &conf, const uchar *cmpData, size_t cmpSize } else if (conf.cmprAlgo == ALGO_NOPRED) { SZ_decompress_nopred(conf, cmpData, cmpSize, decData); } else { - printf("SZ_decompress_dispatcher, Method not supported\n"); - exit(0); + fprintf(stderr, "Unknown compression algorithm\n"); + throw std::invalid_argument("Unknown compression algorithm"); } } } // namespace SZ3 diff --git a/include/SZ3/api/sz.hpp b/include/SZ3/api/sz.hpp index 0e20d834..c8370912 100644 --- a/include/SZ3/api/sz.hpp +++ b/include/SZ3/api/sz.hpp @@ -68,8 +68,8 @@ size_t SZ_compress(const SZ3::Config &config, const T *data, char *cmpData, size } else if (conf.N == 4) { cmpDataLen = SZ_compress_impl(conf, data, cmpDataPos, cmpDataCap); } else { - printf("Data dimension higher than 4 is not supported.\n"); - exit(0); + fprintf(stderr, "Data dimension higher than 4 is not supported.\n"); + throw std::invalid_argument("Data dimension higher than 4 is not supported."); } auto cmpConfPos = reinterpret_cast(cmpData); @@ -134,8 +134,8 @@ void SZ_decompress(SZ3::Config &config, char *cmpData, size_t cmpSize, T *&decDa } else if (config.N == 4) { SZ_decompress_impl(config, cmpDataPos, cmpDataSize, decData); } else { - printf("Data dimension higher than 4 is not supported.\n"); - exit(0); + fprintf(stderr, "Data dimension higher than 4 is not supported.\n"); + throw std::invalid_argument("Data dimension higher than 4 is not supported."); } } diff --git a/include/SZ3/compressor/SZGenericCompressor.hpp b/include/SZ3/compressor/SZGenericCompressor.hpp index f8fe2313..2edf59ba 100644 --- a/include/SZ3/compressor/SZGenericCompressor.hpp +++ b/include/SZ3/compressor/SZGenericCompressor.hpp @@ -39,6 +39,7 @@ class SZGenericCompressor : public concepts::CompressorInterface { std::vector quant_inds = decomposition.compress(conf, data); if (decomposition.get_out_range().first != 0) { + fprintf(stderr, "The output range of the decomposition must start from 0 for this compressor\n"); throw std::runtime_error("The output range of the decomposition must start from 0 for this compressor"); } encoder.preprocess_encode(quant_inds, decomposition.get_out_range().second); diff --git a/include/SZ3/compressor/SZIterateCompressor.hpp b/include/SZ3/compressor/SZIterateCompressor.hpp index 4d9d940b..9b209725 100644 --- a/include/SZ3/compressor/SZIterateCompressor.hpp +++ b/include/SZ3/compressor/SZIterateCompressor.hpp @@ -82,6 +82,7 @@ class SZIterateCompressor : public concepts::CompressorInterface { quantizer.postcompress_data(); if (quantizer.get_out_range().first != 0) { + fprintf(stderr, "The output range of the quantizer must start from 0 for this compressor\n"); throw std::runtime_error("The output range of the quantizer must start from 0 for this compressor"); } encoder.preprocess_encode(quant_inds, quantizer.get_out_range().second); diff --git a/include/SZ3/compressor/specialized/SZBlockInterpolationCompressor.hpp b/include/SZ3/compressor/specialized/SZBlockInterpolationCompressor.hpp index d4389d61..279c870e 100644 --- a/include/SZ3/compressor/specialized/SZBlockInterpolationCompressor.hpp +++ b/include/SZ3/compressor/specialized/SZBlockInterpolationCompressor.hpp @@ -135,6 +135,7 @@ class SZBlockInterpolationCompressor { // predictor.print(); if (quantizer.get_out_range().first != 0) { + fprintf(stderr, "The output range of the quantizer must start from 0 for this compressor\n"); throw std::runtime_error("The output range of the quantizer must start from 0 for this compressor"); } encoder.preprocess_encode(quant_inds, quantizer.get_out_range().second); diff --git a/include/SZ3/compressor/specialized/SZExaaltCompressor.hpp b/include/SZ3/compressor/specialized/SZExaaltCompressor.hpp index c36ad208..57cabebd 100644 --- a/include/SZ3/compressor/specialized/SZExaaltCompressor.hpp +++ b/include/SZ3/compressor/specialized/SZExaaltCompressor.hpp @@ -96,6 +96,7 @@ class SZExaaltCompressor : public SZ3::concepts::CompressorInterface { if (quantizer.get_out_range().first != 0) { + fprintf(stderr, "The output range of the quantizer must start from 0 for this compressor\n"); throw std::runtime_error("The output range of the quantizer must start from 0 for this compressor"); } encoder.preprocess_encode(quant_inds, quantizer.get_out_range().second); diff --git a/include/SZ3/decomposition/LorenzoRegressionDecomposition.hpp b/include/SZ3/decomposition/LorenzoRegressionDecomposition.hpp index e6c30f98..0ef5a892 100644 --- a/include/SZ3/decomposition/LorenzoRegressionDecomposition.hpp +++ b/include/SZ3/decomposition/LorenzoRegressionDecomposition.hpp @@ -31,6 +31,7 @@ class LorenzoRegressionDecomposition : public concepts::DecompositionInterface, Quantizer>::value, diff --git a/include/SZ3/encoder/HuffmanEncoder.hpp b/include/SZ3/encoder/HuffmanEncoder.hpp index 5859de8e..3c30e6ce 100644 --- a/include/SZ3/encoder/HuffmanEncoder.hpp +++ b/include/SZ3/encoder/HuffmanEncoder.hpp @@ -99,8 +99,8 @@ class HuffmanEncoder : public concepts::EncoderInterface { void preprocess_encode(const T *bins, size_t num_bin, int stateNum) { nodeCount = 0; if (num_bin == 0) { - printf("Huffman bins should not be empty\n"); - exit(0); + fprintf(stderr, "Huffman bins should not be empty\n"); + throw std::invalid_argument("Huffman bins should not be empty"); } init(bins, num_bin); for (int i = 0; i < huffmanTree->stateNum; i++) diff --git a/include/SZ3/lossless/Lossless_zstd.hpp b/include/SZ3/lossless/Lossless_zstd.hpp index 07a92452..d626e60f 100644 --- a/include/SZ3/lossless/Lossless_zstd.hpp +++ b/include/SZ3/lossless/Lossless_zstd.hpp @@ -26,6 +26,7 @@ class Lossless_zstd : public concepts::LosslessInterface { size_t compress(const uchar *src, size_t srcLen, uchar *dst, size_t dstCap) override { write(srcLen, dst); if (dstCap < ZSTD_compressBound(srcLen)) { + fprintf(stderr, SZ_ERROR_COMP_BUFFER_NOT_LARGE_ENOUGH); throw std::length_error(SZ_ERROR_COMP_BUFFER_NOT_LARGE_ENOUGH); } size_t dstLen = ZSTD_compress(dst, dstCap, src, srcLen, compression_level); diff --git a/include/SZ3/predictor/MetaRegressionPredictor.hpp b/include/SZ3/predictor/MetaRegressionPredictor.hpp index e1a839b4..9f87a073 100644 --- a/include/SZ3/predictor/MetaRegressionPredictor.hpp +++ b/include/SZ3/predictor/MetaRegressionPredictor.hpp @@ -198,7 +198,6 @@ inline void regression_predict_quantize_3d(const T *data_pos, const float *reg_p } type_pos += size_y * size_z; } - // exit(0); } template diff --git a/include/SZ3/preprocessor/Wavelet.hpp b/include/SZ3/preprocessor/Wavelet.hpp index 4c65939e..711b9607 100644 --- a/include/SZ3/preprocessor/Wavelet.hpp +++ b/include/SZ3/preprocessor/Wavelet.hpp @@ -34,8 +34,8 @@ namespace SZ3 { int status = gsl_wavelet_transform_forward(w, dwtdata.data(), 1, m, work); if (status != GSL_SUCCESS) { - printf("Error: wavelets transform failed.\n"); - exit(0); + fprintf(stderr, "Error: wavelets transform failed.\n"); + throw std::runtime_error("Error: wavelets transform failed."); } for (size_t i = 0; i < n; i++) { @@ -70,8 +70,8 @@ namespace SZ3 { int status = gsl_wavelet_transform_inverse(w, dwtdata.data(), 1, m, work); if (status != GSL_SUCCESS) { - printf("Error: wavelets transform failed.\n"); - exit(0); + fprintf(stderr, "Error: wavelets transform failed.\n"); + throw std::runtime_error("Error: wavelets transform failed."); } for (size_t i = 0; i < n; i++) { diff --git a/include/SZ3/utils/Config.hpp b/include/SZ3/utils/Config.hpp index 12684631..3f7e6a9f 100644 --- a/include/SZ3/utils/Config.hpp +++ b/include/SZ3/utils/Config.hpp @@ -53,8 +53,8 @@ const char *enum2Str(T e) { } else if (std::is_same::value) { return EB_STR[e]; } else { - printf("invalid enum type for enum2Str()\n "); - exit(0); + fprintf(stderr, "invalid enum type for enum2Str()\n "); + throw std::invalid_argument("invalid enum type for enum2Str()"); } } @@ -90,8 +90,8 @@ class Config { INIReader cfg(cfgpath); if (cfg.ParseError() != 0) { - std::cout << "Can't load cfg file " << cfgpath << std::endl; - exit(0); + std::cerr << "Can't load cfg file " << cfgpath << std::endl; + throw std::invalid_argument("Can't load cfg file"); } auto cmprAlgoStr = cfg.Get("GlobalSettings", "CmprAlgo", ""); @@ -107,8 +107,8 @@ class Config { } else if (cmprAlgoStr == ALGO_STR[ALGO_LOSSLESS]) { cmprAlgo = ALGO_LOSSLESS; } else { - printf("Unknown compression algorithm %s\n", cmprAlgoStr.data()); - exit(0); + fprintf(stderr, "Unknown compression algorithm %s\n", cmprAlgoStr.data()); + throw std::invalid_argument("Unknown compression algorithm"); } } auto ebModeStr = cfg.Get("GlobalSettings", "ErrorBoundMode", ""); @@ -126,8 +126,8 @@ class Config { } else if (ebModeStr == EB_STR[EB_ABS_OR_REL]) { errorBoundMode = EB_ABS_OR_REL; } else { - printf("Unknown error bound mode %s\n", ebModeStr.data()); - exit(0); + fprintf(stderr, "Unknown error bound mode %s\n", ebModeStr.data()); + throw std::invalid_argument("Unknown error bound mode"); } } absErrorBound = cfg.GetReal("GlobalSettings", "AbsErrorBound", absErrorBound); @@ -205,6 +205,7 @@ class Config { // auto c0 = c; read(sz3MagicNumber, c); if (sz3MagicNumber != SZ3_MAGIC_NUMBER) { + fprintf(stderr, "magic number mismatch, the input data is not compressed by SZ3\n"); throw std::invalid_argument("magic number mismatch, the input data is not compressed by SZ3"); } read(sz3DataVer, c); @@ -213,6 +214,7 @@ class Config { printf("program v%s , program-data %s , input data v%s\n", SZ3_VER, SZ3_DATA_VER, versionStr(sz3DataVer).data()); ss << "Please use SZ3 v" << versionStr(sz3DataVer) << " to decompress the data" << std::endl; + std::cerr<< ss.str(); throw std::invalid_argument(ss.str()); } diff --git a/include/SZ3/utils/FileUtil.hpp b/include/SZ3/utils/FileUtil.hpp index c5dca42c..5306c549 100644 --- a/include/SZ3/utils/FileUtil.hpp +++ b/include/SZ3/utils/FileUtil.hpp @@ -26,11 +26,12 @@ template void readfile(const char *file, const size_t num, Type *data) { std::ifstream fin(file, std::ios::binary); if (!fin) { - std::cout << " Error, Couldn't find the file: " << file << "\n"; - exit(0); + std::cerr << " Error, Couldn't find the file: " << file << "\n"; + throw std::invalid_argument("Couldn't find the file"); } fin.seekg(0, std::ios::end); if (fin.tellg() / sizeof(Type) != num) { + fprintf(stderr, "File size is not equal to the input setting\n"); throw std::invalid_argument("File size is not equal to the input setting"); } fin.seekg(0, std::ios::beg); @@ -49,8 +50,8 @@ template std::unique_ptr readfile(const char *file, size_t &num) { std::ifstream fin(file, std::ios::binary); if (!fin) { - std::cout << " Error, Couldn't find the file: " << file << std::endl; - exit(0); + std::cerr << " Error, Couldn't find the file: " << file << std::endl; + throw std::invalid_argument("Couldn't find the file"); } fin.seekg(0, std::ios::end); num = fin.tellg() / sizeof(Type); @@ -78,8 +79,8 @@ void writeTextFile(const char *file, Type *data, size_t num_elements) { } fout.close(); } else { - std::cout << "Error, unable to open file for output: " << file << std::endl; - exit(0); + std::cerr << "Error, unable to open file for output: " << file << std::endl; + throw std::invalid_argument("Couldn't open the file for output"); } } diff --git a/include/SZ3/utils/Iterator.hpp b/include/SZ3/utils/Iterator.hpp index 32ef50e3..de806b8a 100644 --- a/include/SZ3/utils/Iterator.hpp +++ b/include/SZ3/utils/Iterator.hpp @@ -198,8 +198,8 @@ class multi_dimensional_range : public std::enable_shared_from_this 0) ? range : data_range(data, conf.num))); } else { - printf("Error, error bound mode not supported\n"); - exit(0); + fprintf(stderr, "Error bound mode not supported\n"); + throw std::invalid_argument("Error bound mode not supported"); } } } diff --git a/tools/mdz/include/mdz.hpp b/tools/mdz/include/mdz.hpp index 58c41501..6bcc6fcc 100644 --- a/tools/mdz/include/mdz.hpp +++ b/tools/mdz/include/mdz.hpp @@ -125,8 +125,8 @@ template float *VQ(Config conf, size_t ts, T *data, size_t &compressed_size, bool decom, int method, float level_start, float level_offset, int level_num) { if (level_num == 0) { - printf("VQ/VQT not availble on current dataset, please use ADP or MT\n"); - exit(0); + fprintf(stderr, "VQ/VQT not availble on current dataset, please use ADP or MT\n"); + throw std::runtime_error("VQ/VQT not availble on current dataset, please use ADP or MT"); } auto sz = make_compressor_exaalt(LinearQuantizer(conf.absErrorBound, conf.quantbinCnt / 2), @@ -284,8 +284,8 @@ template uchar *LAMMPS_compress(Config conf, T *data, int method, size_t &compressed_size, float level_start, float level_offset, int level_num, T *ts0) { if ((method == 0 || method == 1) && level_num == 0) { - printf("VQ/VQT not available on current dataset, please use ADP or MT\n"); - exit(0); + fprintf(stderr, "VQ/VQT not available on current dataset, please use ADP or MT\n"); + throw std::runtime_error("VQ/VQT not available on current dataset, please use ADP or MT"); } compressed_size = conf.num * sizeof(T); auto compressed_data = new uchar[compressed_size];