diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c60c39b45..8f43971e67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,10 @@ if(ZSTD_FOUND) target_link_libraries(mgard PRIVATE ZSTD::ZSTD ${CMAKE_DL_LIBS}) endif() +option(DEFINE_MGARD_TIMING "Enable/disable MGARD timing" OFF) +if(DEFINE_MGARD_TIMING) + add_definitions(-DMGARD_TIMING) +endif() # Make sure we require C++11. Use meta-compile features if available, # otherwise use specific language features diff --git a/src/mgard.tpp b/src/mgard.tpp index d4f4bef8b4..d94ddb3869 100644 --- a/src/mgard.tpp +++ b/src/mgard.tpp @@ -21,6 +21,10 @@ #include #include +#ifdef MGARD_TIMING +#include +#endif + #include "mgard_compress.hpp" #include "mgard_mesh.hpp" #include "mgard_nuni.h" @@ -342,7 +346,9 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) { if (dims.is_2kplus1()) { // to be clean up. - +#ifdef MGARD_TIMING + auto start = std::chrono::high_resolution_clock::now(); +#endif tol /= dims.nlevel + 1; const int l_target = dims.nlevel - 1; @@ -354,6 +360,11 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) { int size_ratio = sizeof(Real) / sizeof(int); std::vector qv(ncol + size_ratio); +#ifdef MGARD_TIMING + auto stop = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(stop - start); + std::cout << "Refactor Time = " << (double)duration.count()/1000000 << "\n"; +#endif quantize_interleave(hierarchy, v.data(), qv.data(), norm, tol); std::vector out_data; @@ -367,7 +378,9 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) { tol /= dims.nlevel + 1; const int l_target = dims.nlevel - 1; - +#ifdef MGARD_TIMING + auto start = std::chrono::high_resolution_clock::now(); +#endif mgard_2d::mgard_gen::prep_1D(dims.rnded[0], dims.input[0], l_target, v.data(), work, coords_x, row_vec); @@ -380,6 +393,11 @@ unsigned char *refactor_qz_1D(int ncol, const Real *u, int &outsize, Real tol) { const int size_ratio = sizeof(Real) / sizeof(int); std::vector qv(ncol + size_ratio); +#ifdef MGARD_TIMING + auto stop = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(stop - start); + std::cout << "Refactor Time = " << duration.count() << "\n"; +#endif quantize_interleave(hierarchy, v.data(), qv.data(), norm, tol); std::vector out_data; diff --git a/src/mgard_compress.cpp b/src/mgard_compress.cpp index 7d905ea7a1..84581a855a 100644 --- a/src/mgard_compress.cpp +++ b/src/mgard_compress.cpp @@ -9,6 +9,10 @@ #include #include +#ifdef MGARD_TIMING +#include +#endif + #include #ifdef MGARD_ZSTD @@ -280,10 +284,17 @@ unsigned char *compress_memory_huffman(std::vector &qv, size_t out_data_miss_size; unsigned char *out_tree = 0; size_t out_tree_size; +#ifdef MGARD_TIMING + auto huff_time1 = std::chrono::high_resolution_clock::now(); +#endif mgard::huffman_encoding(qv.data(), qv.size(), &out_data_hit, &out_data_hit_size, &out_data_miss, &out_data_miss_size, &out_tree, &out_tree_size); - +#ifdef MGARD_TIMING + auto huff_time2 = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(huff_time2 - huff_time1); + std::cout << "Huffman tree time = " << (double)duration.count()/1000000 << "\n"; +#endif size_t total_size = out_data_hit_size / 8 + 4 + out_data_miss_size + out_tree_size; unsigned char *payload = (unsigned char *)malloc(total_size); @@ -302,9 +313,25 @@ unsigned char *compress_memory_huffman(std::vector &qv, free(out_data_hit); free(out_data_miss); #ifndef MGARD_ZSTD +#ifdef MGARD_TIMING + auto z_time1 = std::chrono::high_resolution_clock::now(); +#endif mgard::compress_memory_z(payload, total_size, out_data); +#ifdef MGARD_TIMING + auto z_time2 = std::chrono::high_resolution_clock::now(); + auto z_duration = std::chrono::duration_cast(z_time2 - z_time1); + std::cout << "ZLIB compression time = " << (double)z_duration.count()/1000000 << "\n"; +#endif #else +#ifdef MGARD_TIMING + auto zstd_time1 = std::chrono::high_resolution_clock::now(); +#endif mgard::compress_memory_zstd(payload, total_size, out_data); +#ifdef MGARD_TIMING + auto zstd_time2 = std::chrono::high_resolution_clock::now(); + auto zstd_duration = std::chrono::duration_cast(zstd_time2 - zstd_time1); + std::cout << "ZSTD compression time = " << (double)zstd_duration.count()/1000000 << "\n"; +#endif #endif outsize = out_data.size() + 3 * sizeof(size_t); unsigned char *buffer = (unsigned char *)malloc(outsize); diff --git a/src/mgard_mesh.cpp b/src/mgard_mesh.cpp index 53e1548eaf..566bb9a90c 100644 --- a/src/mgard_mesh.cpp +++ b/src/mgard_mesh.cpp @@ -39,6 +39,7 @@ int get_lindex(const int n, const int no, const int i) { : no - 1); } + std::size_t stride_from_index_difference(const std::size_t index_difference) { return 1 << index_difference; } diff --git a/tests/test_1d/test_1d.cpp b/tests/test_1d/test_1d.cpp index a075f20f7a..f74ee025ec 100644 --- a/tests/test_1d/test_1d.cpp +++ b/tests/test_1d/test_1d.cpp @@ -3,6 +3,9 @@ #include #include #include +#ifdef MGARD_TIMING +#include +#endif using namespace std; @@ -29,14 +32,21 @@ int main(int argc, char **argv) { std::vector data(num_elements); datafile.read(reinterpret_cast(&data[0]), num_elements * sizeof(double)); - +#ifdef MGARD_TIMING + auto start = chrono::high_resolution_clock::now(); +#endif compressed_data = - mgard_compress(data.data(), out_size, 1, num_elements, 1, tol); + mgard_compress(0, data.data(), out_size, 1, num_elements, 1, tol); +#ifdef MGARD_TIMING + auto stop = chrono::high_resolution_clock::now(); + auto duration = chrono::duration_cast(stop - start); cout << "Original size = " << num_elements * 8 << " out_size = " << out_size - << " CR = " << num_elements * 8.0 / out_size << endl; - - double *decompressed_data = - mgard_decompress(compressed_data, out_size, 1, num_elements, 1); + << " CR = " << num_elements * 8.0 / out_size + << " Time = " << (double) duration.count() / 1000000<< endl; +#endif + double quantizer; + double *decompressed_data = mgard_decompress(0, quantizer, compressed_data, + out_size, 1, num_elements, 1); double abserr = 0.0; double max_abserr = 0.0;