From 38d6b299a9d3029603144ea30c5490f911adccd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Fri, 6 Jan 2023 15:40:12 +0100 Subject: [PATCH] refactor: move key and data size calculation to DHT_Wrapper --- include/poet/DHT_Wrapper.hpp | 8 ++++---- src/ChemWorker.cpp | 24 +++++++++++++----------- src/DHT_Wrapper.cpp | 12 +++++++----- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/include/poet/DHT_Wrapper.hpp b/include/poet/DHT_Wrapper.hpp index 67b963178..91b7bc6b0 100644 --- a/include/poet/DHT_Wrapper.hpp +++ b/include/poet/DHT_Wrapper.hpp @@ -76,11 +76,11 @@ public: * @param dht_comm Communicator which addresses all participating DHT * processes * @param buckets_per_process Count of buckets to allocate for each process - * @param data_size Size of data in bytes - * @param key_size Size of key in bytes + * @param key_count Count of key entries + * @param data_count Count of data entries */ - DHT_Wrapper(SimParams ¶ms, MPI_Comm dht_comm, int buckets_per_process, - int data_size, int key_size); + DHT_Wrapper(const poet::SimParams ¶ms, MPI_Comm dht_comm, + uint32_t dht_size, uint32_t key_count, uint32_t data_count); /** * @brief Destroy the dht wrapper object * diff --git a/src/ChemWorker.cpp b/src/ChemWorker.cpp index 7f2bcf3d3..51726ac90 100644 --- a/src/ChemWorker.cpp +++ b/src/ChemWorker.cpp @@ -19,10 +19,12 @@ */ #include "poet/ChemSimPar.hpp" +#include "poet/DHT_Wrapper.hpp" #include "poet/SimParams.hpp" #include #include +#include #include #include #include @@ -57,20 +59,20 @@ ChemWorker::ChemWorker(SimParams ¶ms, RInside &R_, Grid &grid_, << endl; if (this->dht_enabled) { - int data_size = this->prop_names.size() * sizeof(double); - int key_size = (this->prop_names.size() - 1) * sizeof(double) + - (dt_differ * sizeof(double)); - int dht_buckets_per_process = - dht_size_per_process / (1 + data_size + key_size); + + uint32_t iKeyCount = this->prop_names.size() - 1 + (dt_differ); + uint32_t iDataCount = this->prop_names.size(); if (world_rank == 1) - cout << "CPP: Worker: data size: " << data_size << " bytes" << endl - << "CPP: Worker: key size: " << key_size << " bytes" << endl - << "CPP: Worker: buckets per process " << dht_buckets_per_process - << endl; + cout << "CPP: Worker: data count: " << iDataCount << " entries" << endl + << "CPP: Worker: key count: " << iKeyCount << " entries" << endl + << "CPP: Worker: memory per process " + << params.getNumParams().dht_size_per_process / std::pow(10, 6) + << " MByte" << endl; - dht = new DHT_Wrapper(params, dht_comm, dht_buckets_per_process, data_size, - key_size); + dht = new DHT_Wrapper(params, dht_comm, + params.getNumParams().dht_size_per_process, iKeyCount, + iDataCount); if (world_rank == 1) cout << "CPP: Worker: DHT created!" << endl; diff --git a/src/DHT_Wrapper.cpp b/src/DHT_Wrapper.cpp index f5123e77d..13234b385 100644 --- a/src/DHT_Wrapper.cpp +++ b/src/DHT_Wrapper.cpp @@ -19,8 +19,8 @@ */ #include "poet/HashFunctions.hpp" -#include #include +#include #include #include #include @@ -38,14 +38,16 @@ inline double round_signif(double value, int32_t signif) { return .0 + std::trunc(value * multiplier) / multiplier; } -DHT_Wrapper::DHT_Wrapper(SimParams ¶ms, MPI_Comm dht_comm, - int buckets_per_process, int data_size, int key_size) { +DHT_Wrapper::DHT_Wrapper(const poet::SimParams ¶ms, MPI_Comm dht_comm, + uint32_t dht_size, uint32_t key_count, + uint32_t data_count) { poet::initHashCtx(EVP_md5()); // initialize DHT object + uint32_t key_size = key_count * sizeof(double); + uint32_t data_size = data_count * sizeof(double); + uint32_t buckets_per_process = dht_size / (1 + data_size + key_size); dht_object = DHT_create(dht_comm, buckets_per_process, data_size, key_size, &poet::hashDHT); - // allocate memory for fuzzing buffer - fuzzing_buffer = (double *)malloc(key_size); // extract needed values from sim_param struct t_simparams tmp = params.getNumParams();