From 31152b0f071f3e696534544645bb1ee439d9533f Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Sun, 2 Feb 2025 18:34:52 +0100 Subject: [PATCH] Add access and setting pgs functions for partitioner library --- src/language/modules/CoreModule.cpp | 22 ++++++++++++++++++++++ src/utils/PartitionerOptions.hpp | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/language/modules/CoreModule.cpp b/src/language/modules/CoreModule.cpp index 47e018325..5b5753eb8 100644 --- a/src/language/modules/CoreModule.cpp +++ b/src/language/modules/CoreModule.cpp @@ -32,6 +32,7 @@ #include <language/utils/UnaryOperatorRegisterForRnxn.hpp> #include <language/utils/UnaryOperatorRegisterForZ.hpp> #include <utils/Messenger.hpp> +#include <utils/PartitionerOptions.hpp> #include <utils/PugsUtils.hpp> #include <utils/RandomEngine.hpp> #include <utils/Stop.hpp> @@ -94,6 +95,27 @@ CoreModule::CoreModule() : BuiltinModule(true) )); + this->_addBuiltinFunction("setPartitionerLibrary", std::function( + + [](const std::string& library_name) -> void { + PartitionerOptions::default_options.library() = + getPartitionerEnumFromName<PartitionerLibrary>(library_name); + } + + )); + + this->_addBuiltinFunction("getPartitionerOptions", std::function( + + []() -> std::string { + std::ostringstream os; + os << rang::fgB::yellow << "Partitioner options" + << rang::style::reset << '\n'; + os << PartitionerOptions::default_options; + return os.str(); + } + + )); + this->_addTypeDescriptor(ast_node_data_type_from<std::shared_ptr<const OStream>>); this->_addBuiltinFunction("ofstream", std::function( diff --git a/src/utils/PartitionerOptions.hpp b/src/utils/PartitionerOptions.hpp index 8ce9263b0..e4157f765 100644 --- a/src/utils/PartitionerOptions.hpp +++ b/src/utils/PartitionerOptions.hpp @@ -32,6 +32,20 @@ name(const PartitionerLibrary library) throw UnexpectedError("Linear system library name is not defined!"); } +template <typename PartitionerEnumType> +inline PartitionerEnumType +getPartitionerEnumFromName(const std::string& enum_name) +{ + using BaseT = std::underlying_type_t<PartitionerEnumType>; + for (BaseT enum_value = static_cast<BaseT>(PartitionerEnumType::PT__begin); + enum_value < static_cast<BaseT>(PartitionerEnumType::PT__end); ++enum_value) { + if (name(PartitionerEnumType{enum_value}) == enum_name) { + return PartitionerEnumType{enum_value}; + } + } + throw NormalError(std::string{"could not find '"} + enum_name + "' associate type!"); +} + class PartitionerOptions { private: -- GitLab