refactor: move key and data size calculation to DHT_Wrapper

This commit is contained in:
Max Lübke 2023-01-06 15:40:12 +01:00 committed by Max Luebke
parent f32a3f3342
commit 38d6b299a9
3 changed files with 24 additions and 20 deletions

View File

@ -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 &params, MPI_Comm dht_comm, int buckets_per_process,
int data_size, int key_size);
DHT_Wrapper(const poet::SimParams &params, MPI_Comm dht_comm,
uint32_t dht_size, uint32_t key_count, uint32_t data_count);
/**
* @brief Destroy the dht wrapper object
*

View File

@ -19,10 +19,12 @@
*/
#include "poet/ChemSimPar.hpp"
#include "poet/DHT_Wrapper.hpp"
#include "poet/SimParams.hpp"
#include <Rcpp.h>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <mpi.h>
@ -57,20 +59,20 @@ ChemWorker::ChemWorker(SimParams &params, 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;

View File

@ -19,8 +19,8 @@
*/
#include "poet/HashFunctions.hpp"
#include <cstddef>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <openssl/evp.h>
#include <poet/DHT_Wrapper.hpp>
@ -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 &params, MPI_Comm dht_comm,
int buckets_per_process, int data_size, int key_size) {
DHT_Wrapper::DHT_Wrapper(const poet::SimParams &params, 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();