From a493054f9dcac96490626dcf77abae9ca2e91bcd Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Thu, 16 Feb 2023 14:30:51 +0100 Subject: [PATCH] refactor: In SimParams, relocate trivial getter/setters to header file refactor: change vector data types of dht_signif_vector and dht_prop_type_vector to both uint32 --- include/poet/SimParams.hpp | 86 +++++++------------------------------- src/SimParams.cpp | 43 ++++++++++--------- 2 files changed, 35 insertions(+), 94 deletions(-) diff --git a/include/poet/SimParams.hpp b/include/poet/SimParams.hpp index 3a10e612d..b68dbce5d 100644 --- a/include/poet/SimParams.hpp +++ b/include/poet/SimParams.hpp @@ -31,8 +31,8 @@ #include // BSD-licenced -/** Standard DHT Size (Defaults to 1 GiB) */ -#define DHT_SIZE_PER_PROCESS 1073741824 +/** Standard DHT Size. Defaults to 1 GB (1000 MB) */ +constexpr uint32_t DHT_SIZE_PER_PROCESS_MB = 1E3; /** Standard work package size */ #define WORK_PACKAGE_SIZE_DEFAULT 5 @@ -167,16 +167,6 @@ public: */ void initVectorParams(RInside &R, int col_count); - /** - * @brief Set if dt differs - * - * Set a boolean variable if the timestep differs between iterations of - * simulation. - * - * @param dt_differ Boolean value, if dt differs - */ - void setDtDiffer(bool dt_differ); - /** * @brief Get the numerical params struct * @@ -185,7 +175,7 @@ public: * * @return t_simparams Parameter struct */ - t_simparams getNumParams() const; + auto getNumParams() const { return this->simparams; }; /** * @brief Get the DHT_Signif_Vector @@ -196,7 +186,7 @@ public: * @return std::vector Vector of integers containing information about * significant digits */ - std::vector getDHTSignifVector() const; + auto getDHTSignifVector() const { return this->dht_signif_vector; }; /** * @brief Get the DHT_Prop_Type_Vector @@ -206,7 +196,7 @@ public: * @return std::vector Vector if strings defining a type of a * variable */ - std::vector getDHTPropTypeVector() const; + auto getDHTPropTypeVector() const { return this->dht_prop_type_vector; }; /** * @brief Return name of DHT snapshot. @@ -216,7 +206,7 @@ public: * * @return std::string Absolute paht to the DHT snapshot */ - std::string_view getDHTFile() const; + auto getDHTFile() const { return this->dht_file; }; /** * @brief Get the filesim name @@ -226,7 +216,7 @@ public: * * @return std::string Absolute path to R file */ - std::string_view getFilesim() const; + auto getFilesim() const { return this->filesim; }; /** * @brief Get the output directory @@ -236,71 +226,23 @@ public: * * @return std::string Absolute path to output path */ - std::string_view getOutDir() const; + auto getOutDir() const { return this->out_dir; }; private: - /** - * @brief Validate program parameters and flags - * - * Therefore this function iterates over the list of flags and parameters and - * compare them to the class member flagList and paramList. If a program - * argument is not included it is put to a list. This list will be returned. - * - * @return std::list List with all unknown parameters. Might be - * empty. - */ std::list validateOptions(argh::parser cmdl); - /** - * @brief Contains all valid program flags. - * - */ - std::set flaglist{"ignore-result", "dht", "dht-nolog"}; + const std::set flaglist{"ignore-result", "dht", "dht-nolog"}; + const std::set paramlist{"work-package-size", "dht-signif", + "dht-strategy", "dht-size", + "dht-snaps", "dht-file"}; - /** - * @brief Contains all valid program parameters. - * - */ - std::set paramlist{"work-package-size", "dht-signif", - "dht-strategy", "dht-size", - "dht-snaps", "dht-file"}; - - /** - * @brief Struct containing all simulation parameters - * - * Contains only those values which are standard arithmetic C types. - * - */ t_simparams simparams; - /** - * @brief Defines significant digits for each variable of a grid cell - * - */ - std::vector dht_signif_vector; + std::vector dht_signif_vector; + std::vector dht_prop_type_vector; - /** - * @brief Defines the type of a variable - * - */ - std::vector dht_prop_type_vector; - - /** - * @brief Absolute path to a DHT snapshot - * - */ std::string dht_file; - - /** - * @brief Absolute path to R file containing simulation definitions - * - */ std::string filesim; - - /** - * @brief Absolute path to output dir - * - */ std::string out_dir; }; } // namespace poet diff --git a/src/SimParams.cpp b/src/SimParams.cpp index b8b63c823..c7bb3b30a 100644 --- a/src/SimParams.cpp +++ b/src/SimParams.cpp @@ -18,6 +18,7 @@ ** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "poet/DHT_Types.hpp" #include #include @@ -130,7 +131,7 @@ int SimParams::parseFromCmdl(char *argv[], RInside &R) { // cout << "CPP: DHT logarithm before rounding: " << ( dht_logarithm ? "ON" // : "OFF" ) << endl; - cmdl("dht-size", DHT_SIZE_PER_PROCESS) >> simparams.dht_size_per_process; + cmdl("dht-size", DHT_SIZE_PER_PROCESS_MB) >> simparams.dht_size_per_process; // cout << "CPP: DHT size per process (Byte) = " << dht_size_per_process << // endl; @@ -196,17 +197,30 @@ void SimParams::initVectorParams(RInside &R, int col_count) { /*Load significance vector from R setup file (or set default)*/ bool signif_vector_exists = R.parseEval("exists('signif_vector')"); if (signif_vector_exists) { - dht_signif_vector = as>(R["signif_vector"]); - } else { - dht_signif_vector.assign(col_count, simparams.dht_significant_digits); + dht_signif_vector = as>(R["signif_vector"]); } /*Load property type vector from R setup file (or set default)*/ bool prop_type_vector_exists = R.parseEval("exists('prop_type')"); if (prop_type_vector_exists) { - dht_prop_type_vector = as>(R["prop_type"]); - } else { - dht_prop_type_vector.assign(col_count, "act"); + std::vector prop_type_R = + as>(R["prop_type"]); + this->dht_prop_type_vector.clear(); + this->dht_prop_type_vector.reserve(prop_type_R.size()); + + for (const auto &type : prop_type_R) { + if (type == "act") { + this->dht_prop_type_vector.push_back(DHT_TYPE_ACT); + continue; + } + + if (type == "ignore") { + this->dht_prop_type_vector.push_back(DHT_TYPE_IGNORE); + continue; + } + + this->dht_prop_type_vector.push_back(DHT_TYPE_DEFAULT); + } } if (simparams.world_rank == 0) { @@ -228,21 +242,6 @@ void SimParams::initVectorParams(RInside &R, int col_count) { } } -void SimParams::setDtDiffer(bool dt_differ) { simparams.dt_differ = dt_differ; } - -t_simparams SimParams::getNumParams() const { return this->simparams; } - -std::vector SimParams::getDHTSignifVector() const { - return this->dht_signif_vector; -} -std::vector SimParams::getDHTPropTypeVector() const { - return this->dht_prop_type_vector; -} -std::string_view SimParams::getDHTFile() const { return this->dht_file; } - -std::string_view SimParams::getFilesim() const { return this->filesim; } -std::string_view SimParams::getOutDir() const { return this->out_dir; } - std::list SimParams::validateOptions(argh::parser cmdl) { /* store all unknown parameters here */ std::list retList;