From 521937a52766ecbb2332e66cd1852f0b20d4701d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Tue, 17 Dec 2024 10:08:58 +0100 Subject: [PATCH] refactor: streamline WorkPackage constructor and improve DHT_Wrapper::fillDHT logic --- src/Chemistry/ChemistryDefs.hpp | 7 +- src/Chemistry/SurrogateModels/DHT_Wrapper.cpp | 71 ++++++++++--------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/Chemistry/ChemistryDefs.hpp b/src/Chemistry/ChemistryDefs.hpp index cc0aa5232..655eaf2d5 100644 --- a/src/Chemistry/ChemistryDefs.hpp +++ b/src/Chemistry/ChemistryDefs.hpp @@ -14,10 +14,7 @@ struct WorkPackage { std::vector> output; std::vector mapping; - WorkPackage(std::size_t _size) : size(_size) { - input.resize(size); - output.resize(size); - mapping.resize(size, CHEM_PQC); - } + WorkPackage(std::size_t _size) + : size(_size), input(size), output(size), mapping(size, CHEM_PQC) {} }; } // namespace poet \ No newline at end of file diff --git a/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp b/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp index 0d9d2d2f6..4aa697e3e 100644 --- a/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp +++ b/src/Chemistry/SurrogateModels/DHT_Wrapper.cpp @@ -129,42 +129,43 @@ void DHT_Wrapper::fillDHT(const WorkPackage &work_package) { dht_results.filledDHT = std::vector(length, false); for (int i = 0; i < length; i++) { // If true grid cell was simulated, needs to be inserted into dht - if (work_package.mapping[i] == CHEM_PQC) { - - // check if calcite or dolomite is absent and present, resp.n and vice - // versa in input/output. If this is the case -> Do not write to DHT! - // HACK: hardcoded, should be fixed! - if (hooks.dht_fill.isValid()) { - NamedVector old_values(output_names, work_package.input[i]); - NamedVector new_values(output_names, work_package.output[i]); - - if (hooks.dht_fill(old_values, new_values)) { - continue; - } - } - - uint32_t proc, index; - auto &key = dht_results.keys[i]; - const auto data = - (with_interp ? outputToInputAndRates(work_package.input[i], - work_package.output[i]) - : work_package.output[i]); - // void *data = (void *)&(work_package[i * this->data_count]); - // fuzz data (round, logarithm etc.) - - // insert simulated data with fuzzed key into DHT - int res = DHT_write(this->dht_object, key.data(), - const_cast(data.data()), &proc, &index); - - dht_results.locations[i] = {proc, index}; - - // if data was successfully written ... - if ((res != DHT_SUCCESS) && (res == DHT_WRITE_SUCCESS_WITH_EVICTION)) { - dht_evictions++; - } - - dht_results.filledDHT[i] = true; + if (work_package.mapping[i] != CHEM_PQC) { + continue; } + + // check if calcite or dolomite is absent and present, resp.n and vice + // versa in input/output. If this is the case -> Do not write to DHT! + // HACK: hardcoded, should be fixed! + if (hooks.dht_fill.isValid()) { + NamedVector old_values(output_names, work_package.input[i]); + NamedVector new_values(output_names, work_package.output[i]); + + if (hooks.dht_fill(old_values, new_values)) { + continue; + } + } + + uint32_t proc, index; + auto &key = dht_results.keys[i]; + const auto data = + (with_interp ? outputToInputAndRates(work_package.input[i], + work_package.output[i]) + : work_package.output[i]); + // void *data = (void *)&(work_package[i * this->data_count]); + // fuzz data (round, logarithm etc.) + + // insert simulated data with fuzzed key into DHT + int res = DHT_write(this->dht_object, key.data(), + const_cast(data.data()), &proc, &index); + + dht_results.locations[i] = {proc, index}; + + // if data was successfully written ... + if ((res != DHT_SUCCESS) && (res == DHT_WRITE_SUCCESS_WITH_EVICTION)) { + dht_evictions++; + } + + dht_results.filledDHT[i] = true; } }