From 7828b00268bf5907b34620bf03046c33b39f9bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Thu, 7 Mar 2024 12:27:13 +0100 Subject: [PATCH] Add OpenSSL dependency and implement MD5 hash function --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/Chemistry/SurrogateModels/DHT_Wrapper.cpp | 3 ++- .../SurrogateModels/HashFunctions.cpp | 21 +++++++++++++++++++ .../SurrogateModels/HashFunctions.hpp | 1 + 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4ad05c6e..ba6c76b08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ get_poet_version() find_package(MPI REQUIRED) find_package(OpenMP) find_package(RRuntime REQUIRED) +find_package(OpenSSL REQUIRED) add_subdirectory(src) add_subdirectory(bench) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d3d38786..3e443034e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(poetlib PUBLIC PhreeqcRM tug DHT_UCX + OpenSSL::Crypto ) target_compile_definitions(poetlib PUBLIC STRICT_R_HEADERS OMPI_SKIP_MPICXX) diff --git a/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp b/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp index 6b78c82af..30b3e5dd6 100644 --- a/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp +++ b/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp @@ -22,6 +22,7 @@ #include "DHT_Wrapper.hpp" #include "DHT_ucx/UCX_bcast_functions.h" +#include "HashFunctions.hpp" #include #include @@ -62,7 +63,7 @@ DHT_Wrapper::DHT_Wrapper(MPI_Comm dht_comm, std::uint64_t dht_size, .key_size = static_cast(key_size), .data_size = static_cast(data_size), .bucket_count = static_cast(buckets_per_process), - .hash_func = &poet::Murmur2_64A, + .hash_func = &poet::md5_sum, .bcast_func = UCX_INIT_BSTRAP_MPI, .bcast_func_args = &ucx_bcast_mpi_args}; dht_object = DHT_create(&dht_init); diff --git a/src/Chemistry/SurrogateModels/HashFunctions.cpp b/src/Chemistry/SurrogateModels/HashFunctions.cpp index d93702990..d76883f5b 100644 --- a/src/Chemistry/SurrogateModels/HashFunctions.cpp +++ b/src/Chemistry/SurrogateModels/HashFunctions.cpp @@ -25,6 +25,9 @@ */ #include "HashFunctions.hpp" +#include + +#include #if defined(_MSC_VER) @@ -93,3 +96,21 @@ uint64_t poet::Murmur2_64A(int len, const void *key) { return h; } + +uint64_t poet::md5_sum(int len, const void *key) { + MD5_CTX ctx; + unsigned char sum[MD5_DIGEST_LENGTH]; + uint64_t retval; + uint64_t *v1; + uint64_t *v2; + + MD5_Init(&ctx); + MD5_Update(&ctx, key, len); + MD5_Final(sum, &ctx); + + v1 = (uint64_t *)&sum[0]; + v2 = (uint64_t *)&sum[8]; + retval = *v1 ^ *v2; + + return retval; +} \ No newline at end of file diff --git a/src/Chemistry/SurrogateModels/HashFunctions.hpp b/src/Chemistry/SurrogateModels/HashFunctions.hpp index 49e86559a..438b86512 100644 --- a/src/Chemistry/SurrogateModels/HashFunctions.hpp +++ b/src/Chemistry/SurrogateModels/HashFunctions.hpp @@ -31,6 +31,7 @@ namespace poet { constexpr uint32_t HASH_SEED = 80 + 79 + 69 + 84; uint64_t Murmur2_64A(int len, const void *key); +uint64_t md5_sum(int len, const void *key); } // namespace poet