From 9f6c51d349c388db05232f2e25c56ce13ba93a65 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Tue, 10 Nov 2020 12:10:07 +0100 Subject: [PATCH 1/2] Refactor command line handling out of resource partitioner Rely on runtime configuration for getting configuration values, instead of command line handling struct. Command line handling is managed in hpx_init.cpp instead. --- hpx/runtime/agas/addressing_service.hpp | 5 +- .../include/hpx/affinity/affinity_data.hpp | 8 +- libs/core/affinity/src/affinity_data.cpp | 10 +- .../command_line_handling.hpp | 34 ++-- .../src/command_line_handling.cpp | 141 ++++++------- libs/full/init_runtime/src/hpx_init.cpp | 77 ++++--- .../detail/create_partitioner.hpp | 12 +- .../detail/partitioner.hpp | 25 +-- .../hpx/resource_partitioner/partitioner.hpp | 62 ++---- .../src/detail_partitioner.cpp | 116 ++++------- .../resource_partitioner/src/partitioner.cpp | 65 +----- .../hpx/runtime_local/runtime_local.hpp | 2 +- libs/full/runtime_local/src/runtime_local.cpp | 75 ++----- .../include/hpx/modules/threadmanager.hpp | 9 +- libs/full/threadmanager/src/threadmanager.cpp | 192 ++++++++---------- src/runtime/agas/addressing_service.cpp | 4 +- src/runtime_distributed.cpp | 15 +- 17 files changed, 332 insertions(+), 520 deletions(-) diff --git a/hpx/runtime/agas/addressing_service.hpp b/hpx/runtime/agas/addressing_service.hpp index 50c511752325..0f60918fae8d 100644 --- a/hpx/runtime/agas/addressing_service.hpp +++ b/hpx/runtime/agas/addressing_service.hpp @@ -124,10 +124,7 @@ struct HPX_EXPORT addressing_service resolved_localities_type; resolved_localities_type resolved_localities_; - addressing_service( - util::runtime_configuration const& ini_ - , runtime_mode runtime_type_ - ); + explicit addressing_service(util::runtime_configuration const& ini_); #if defined(HPX_HAVE_NETWORKING) ~addressing_service() diff --git a/libs/core/affinity/include/hpx/affinity/affinity_data.hpp b/libs/core/affinity/include/hpx/affinity/affinity_data.hpp index faceb27515c5..ccda6fed3181 100644 --- a/libs/core/affinity/include/hpx/affinity/affinity_data.hpp +++ b/libs/core/affinity/include/hpx/affinity/affinity_data.hpp @@ -27,7 +27,7 @@ namespace hpx { namespace threads { namespace policies { namespace detail { affinity_data(); ~affinity_data(); - std::size_t init(std::size_t num_threads = 1, std::size_t max_cores = 1, + void init(std::size_t num_threads = 1, std::size_t max_cores = 1, std::size_t pu_offset = 0, std::size_t pu_step = 1, std::size_t used_cores = 0, std::string affinity_domain = "pu", std::string const& affinity_description = "balanced", @@ -79,6 +79,11 @@ namespace hpx { namespace threads { namespace policies { namespace detail { void add_punit(std::size_t virt_core, std::size_t thread_num); void init_cached_pu_nums(std::size_t hardware_concurrency); + std::size_t get_num_pus_needed() const + { + return num_pus_needed_; + } + protected: std::size_t get_pu_num( std::size_t num_thread, std::size_t hardware_concurrency) const; @@ -96,6 +101,7 @@ namespace hpx { namespace threads { namespace policies { namespace detail { no_affinity_; ///< mask of processing units which have no affinity bool use_process_mask_; ///< use the process CPU mask to limit available PUs + std::size_t num_pus_needed_; static std::atomic instance_number_counter_; ///< counter for instance numbers }; diff --git a/libs/core/affinity/src/affinity_data.cpp b/libs/core/affinity/src/affinity_data.cpp index e6c7d5615a2c..90ddb1101078 100644 --- a/libs/core/affinity/src/affinity_data.cpp +++ b/libs/core/affinity/src/affinity_data.cpp @@ -41,6 +41,7 @@ namespace hpx { namespace threads { namespace policies { namespace detail { , pu_nums_() , no_affinity_() , use_process_mask_(false) + , num_pus_needed_(0) { threads::resize(no_affinity_, hardware_concurrency()); } @@ -50,9 +51,9 @@ namespace hpx { namespace threads { namespace policies { namespace detail { --instance_number_counter_; } - std::size_t affinity_data::init(std::size_t num_threads, - std::size_t max_cores, std::size_t pu_offset, std::size_t pu_step, - std::size_t used_cores, std::string affinity_domain, // -V813 + void affinity_data::init(std::size_t num_threads, std::size_t max_cores, + std::size_t pu_offset, std::size_t pu_step, std::size_t used_cores, + std::string affinity_domain, // -V813 std::string const& affinity_description, bool use_process_mask) { num_threads_ = num_threads; @@ -143,7 +144,8 @@ namespace hpx { namespace threads { namespace policies { namespace detail { cores.erase(it, cores.end()); std::size_t num_unique_cores = cores.size(); - return (std::max)(num_unique_cores, max_cores); + + num_pus_needed_ = (std::max)(num_unique_cores, max_cores); } mask_cref_type affinity_data::get_pu_mask( diff --git a/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp b/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp index f3d2f87996f5..a3f5f32fd825 100644 --- a/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp +++ b/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp @@ -21,28 +21,16 @@ /////////////////////////////////////////////////////////////////////////////// namespace hpx { namespace util { - struct command_line_handling; - - /////////////////////////////////////////////////////////////////////////// - // Helper functions for retrieving command line options (with error - // checking) - std::size_t get_num_high_priority_queues( - util::command_line_handling const& cfg, std::size_t num_threads); - - std::string get_affinity_domain(util::command_line_handling const& cfg); - - std::size_t get_affinity_description( - util::command_line_handling const& cfg, std::string& affinity_desc); - - std::size_t get_pu_offset(util::command_line_handling const& cfg); - - std::size_t get_pu_step(util::command_line_handling const& cfg); - /////////////////////////////////////////////////////////////////////////// struct command_line_handling { - command_line_handling() - : rtcfg_(nullptr, runtime_mode::default_) + command_line_handling(runtime_configuration rtcfg, + std::vector ini_config, + function_nonser + hpx_main_f) + : rtcfg_(rtcfg) + , ini_config_(ini_config) + , hpx_main_f_(hpx_main_f) , node_(std::size_t(-1)) , num_threads_(1) , num_cores_(1) @@ -54,7 +42,6 @@ namespace hpx { namespace util { , cmd_line_parsed_(false) , info_printed_(false) , version_printed_(false) - , parse_result_(0) { } @@ -84,9 +71,14 @@ namespace hpx { namespace util { bool cmd_line_parsed_; bool info_printed_; bool version_printed_; - int parse_result_; protected: + // Helper functions for checking command line options + void check_affinity_domain() const; + void check_affinity_description() const; + void check_pu_offset() const; + void check_pu_step() const; + bool handle_arguments(util::manage_config& cfgmap, hpx::program_options::variables_map& vm, std::vector& ini_config, std::size_t& node, diff --git a/libs/full/command_line_handling/src/command_line_handling.cpp b/libs/full/command_line_handling/src/command_line_handling.cpp index ce4d4337bc37..200b5fd962e1 100644 --- a/libs/full/command_line_handling/src/command_line_handling.cpp +++ b/libs/full/command_line_handling/src/command_line_handling.cpp @@ -562,37 +562,14 @@ namespace hpx { namespace util { } // namespace detail /////////////////////////////////////////////////////////////////////// - std::size_t get_num_high_priority_queues( - util::command_line_handling const& cfg, std::size_t num_threads) + void command_line_handling::check_affinity_domain() const { - std::size_t num_high_priority_queues = num_threads; - if (cfg.vm_.count("hpx:high-priority-threads")) + if (affinity_domain_ != "pu") { - num_high_priority_queues = - cfg.vm_["hpx:high-priority-threads"].as(); - if (num_high_priority_queues > num_threads) - { - throw hpx::detail::command_line_error( - "Invalid command line option: " - "number of high priority threads (" - "--hpx:high-priority-threads), should not be larger " - "than number of threads (--hpx:threads)"); - } - } - return num_high_priority_queues; - } - - /////////////////////////////////////////////////////////////////////// - std::string get_affinity_domain(util::command_line_handling const& cfg) - { - std::string affinity_domain("pu"); - if (cfg.affinity_domain_ != "pu") - { - affinity_domain = cfg.affinity_domain_; - if (0 != std::string("pu").find(affinity_domain) && - 0 != std::string("core").find(affinity_domain) && - 0 != std::string("numa").find(affinity_domain) && - 0 != std::string("machine").find(affinity_domain)) + if (0 != std::string("pu").find(affinity_domain_) && + 0 != std::string("core").find(affinity_domain_) && + 0 != std::string("numa").find(affinity_domain_) && + 0 != std::string("machine").find(affinity_domain_)) { throw hpx::detail::command_line_error( "Invalid command line option " @@ -600,66 +577,47 @@ namespace hpx { namespace util { "or machine."); } } - return affinity_domain; } - std::size_t get_affinity_description( - util::command_line_handling const& cfg, std::string& affinity_desc) + void command_line_handling::check_affinity_description() const { - if (cfg.affinity_bind_.empty()) - return cfg.numa_sensitive_; + if (affinity_bind_.empty()) + { + return; + } - if (!(cfg.pu_offset_ == std::size_t(-1) || - cfg.pu_offset_ == std::size_t(0)) || - cfg.pu_step_ != 1 || cfg.affinity_domain_ != "pu") + if (!(pu_offset_ == std::size_t(-1) || pu_offset_ == std::size_t(0)) || + pu_step_ != 1 || affinity_domain_ != "pu") { throw hpx::detail::command_line_error( "Command line option --hpx:bind " "should not be used with --hpx:pu-step, --hpx:pu-offset, " "or --hpx:affinity."); } - - affinity_desc = cfg.affinity_bind_; - return cfg.numa_sensitive_; } - std::size_t get_pu_offset(util::command_line_handling const& cfg) + void command_line_handling::check_pu_offset() const { - std::size_t pu_offset = std::size_t(-1); - - if (cfg.pu_offset_ != std::size_t(-1)) + if (pu_offset_ != std::size_t(-1) && + pu_offset_ >= hpx::threads::hardware_concurrency()) { - pu_offset = cfg.pu_offset_; - if (pu_offset >= hpx::threads::hardware_concurrency()) - { - throw hpx::detail::command_line_error( - "Invalid command line option " - "--hpx:pu-offset, value must be smaller than number of " - "available processing units."); - } + throw hpx::detail::command_line_error( + "Invalid command line option " + "--hpx:pu-offset, value must be smaller than number of " + "available processing units."); } - - return pu_offset; } - std::size_t get_pu_step(util::command_line_handling const& cfg) + void command_line_handling::check_pu_step() const { - std::size_t pu_step = 1; - - if (cfg.pu_step_ != 1) + if (pu_step_ == 0 || pu_step_ >= hpx::threads::hardware_concurrency()) { - pu_step = cfg.pu_step_; - if (pu_step == 0 || pu_step >= hpx::threads::hardware_concurrency()) - { - throw hpx::detail::command_line_error( - "Invalid command line option " - "--hpx:pu-step, value must be non-zero and smaller " - "than " - "number of available processing units."); - } + throw hpx::detail::command_line_error( + "Invalid command line option " + "--hpx:pu-step, value must be non-zero and smaller " + "than " + "number of available processing units."); } - - return pu_step; } /////////////////////////////////////////////////////////////////////////// @@ -794,6 +752,9 @@ namespace hpx { namespace util { } #endif + ini_config.emplace_back( + "hpx.use_process_mask!=" + std::to_string(use_process_mask_)); + #if defined(HPX_HAVE_MODULE_MPI_BASE) bool have_mpi = util::mpi_environment::check_mpi_environment(rtcfg_); #else @@ -1021,6 +982,8 @@ namespace hpx { namespace util { affinity_domain_ = detail::handle_affinity(cfgmap, vm, "pu"); ini_config.emplace_back("hpx.affinity=" + affinity_domain_); + check_affinity_domain(); + affinity_bind_ = detail::handle_affinity_bind(cfgmap, vm, ""); if (!affinity_bind_.empty()) { @@ -1048,6 +1011,8 @@ namespace hpx { namespace util { #endif ini_config.emplace_back("hpx.pu_step=" + std::to_string(pu_step_)); + check_pu_step(); + pu_offset_ = detail::handle_pu_offset(cfgmap, vm, std::size_t(-1)); // NOLINTNEXTLINE(bugprone-branch-clone) @@ -1070,6 +1035,8 @@ namespace hpx { namespace util { ini_config.emplace_back("hpx.pu_offset=0"); } + check_pu_offset(); + numa_sensitive_ = detail::handle_numa_sensitive( cfgmap, vm, affinity_bind_.empty() ? 0 : 1); ini_config.emplace_back( @@ -1088,6 +1055,8 @@ namespace hpx { namespace util { ini_config.emplace_back("hpx.bind!=" + affinity_bind_); } + check_affinity_description(); + // handle number of cores and threads num_threads_ = detail::handle_num_threads(cfgmap, rtcfg_, vm, env, using_nodelist, initial, use_process_mask_); @@ -1099,6 +1068,32 @@ namespace hpx { namespace util { "hpx.os_threads=" + std::to_string(num_threads_)); ini_config.emplace_back("hpx.cores=" + std::to_string(num_cores_)); + if (vm_.count("hpx:high-priority-threads")) + { + std::size_t num_high_priority_queues = + vm_["hpx:high-priority-threads"].as(); + if (num_high_priority_queues != std::size_t(-1) && + num_high_priority_queues > num_threads_) + { + throw hpx::detail::command_line_error( + "Invalid command line option: " + "number of high priority threads (" + "--hpx:high-priority-threads), should not be larger " + "than number of threads (--hpx:threads)"); + } + + if (!(queuing_ == "local-priority" || queuing_ == "abp-priority")) + { + throw hpx::detail::command_line_error( + "Invalid command line option --hpx:high-priority-threads, " + "valid for --hpx:queuing=local-priority and " + "--hpx:queuing=abp-priority only"); + } + + ini_config.emplace_back("hpx.thread_queue.high_priority_queues!=" + + std::to_string(num_high_priority_queues)); + } + // map host names to ip addresses, if requested hpx_host = mapnames.map(hpx_host, hpx_port); agas_host = mapnames.map(agas_host, agas_port); @@ -1541,7 +1536,9 @@ namespace hpx { namespace util { // handle all --hpx:foo options, determine node std::vector ini_config; // discard if (!handle_arguments(cfgmap, prevm, ini_config, node_, true)) + { return -2; + } // re-initialize runtime configuration object if (prevm.count("hpx:config")) @@ -1619,7 +1616,9 @@ namespace hpx { namespace util { // handle all --hpx:foo and --hpx:*:foo options if (!handle_arguments(cfgmap, vm_, ini_config_, node_)) + { return -2; + } // store unregistered command line and arguments store_command_line(argc, argv); @@ -1630,7 +1629,9 @@ namespace hpx { namespace util { // help can be printed only after the runtime mode has been set if (handle_help_options(help)) + { return 1; // exit application gracefully + } // print version/copyright information if (vm_.count("hpx:version")) @@ -1640,6 +1641,7 @@ namespace hpx { namespace util { detail::print_version(std::cout); version_printed_ = true; } + return 1; } @@ -1651,6 +1653,7 @@ namespace hpx { namespace util { detail::print_info(std::cout, *this); info_printed_ = true; } + return 1; } diff --git a/libs/full/init_runtime/src/hpx_init.cpp b/libs/full/init_runtime/src/hpx_init.cpp index 3188742c6ff4..77fe9821e5ab 100644 --- a/libs/full/init_runtime/src/hpx_init.cpp +++ b/libs/full/init_runtime/src/hpx_init.cpp @@ -360,18 +360,18 @@ namespace hpx { /////////////////////////////////////////////////////////////////////// void activate_global_options( - util::command_line_handling& cms, int argc, char** argv) + util::command_line_handling& cmdline, int argc, char** argv) { #if defined(__linux) || defined(linux) || defined(__linux__) || \ defined(__FreeBSD__) threads::coroutines::detail::posix::use_guard_pages = - cms.rtcfg_.use_stack_guard_pages(); + cmdline.rtcfg_.use_stack_guard_pages(); #endif #ifdef HPX_HAVE_VERIFY_LOCKS - if (cms.rtcfg_.enable_lock_detection()) + if (cmdline.rtcfg_.enable_lock_detection()) { util::enable_lock_detection(); - util::trace_depth_lock_detection(cms.rtcfg_.trace_depth()); + util::trace_depth_lock_detection(cmdline.rtcfg_.trace_depth()); } else { @@ -380,7 +380,7 @@ namespace hpx { #endif #if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) && \ defined(HPX_HAVE_VERIFY_LOCKS_GLOBALLY) - if (cms.rtcfg_.enable_global_lock_detection()) + if (cmdline.rtcfg_.enable_global_lock_detection()) { util::enable_global_lock_detection(); } @@ -391,26 +391,26 @@ namespace hpx { #endif #ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION threads::policies::set_minimal_deadlock_detection_enabled( - cms.rtcfg_.enable_minimal_deadlock_detection()); + cmdline.rtcfg_.enable_minimal_deadlock_detection()); #endif #ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION util::detail::set_spinlock_break_on_deadlock_enabled( - cms.rtcfg_.enable_spinlock_deadlock_detection()); + cmdline.rtcfg_.enable_spinlock_deadlock_detection()); util::detail::set_spinlock_deadlock_detection_limit( - cms.rtcfg_.get_spinlock_deadlock_detection_limit()); + cmdline.rtcfg_.get_spinlock_deadlock_detection_limit()); #endif // initialize logging #if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) util::detail::init_logging( - cms.rtcfg_, cms.rtcfg_.mode_ == runtime_mode::console); + cmdline.rtcfg_, cmdline.rtcfg_.mode_ == runtime_mode::console); #endif #if defined(HPX_HAVE_NETWORKING) - if (cms.num_localities_ != 1 || cms.node_ != 0 || - cms.rtcfg_.enable_networking()) + if (cmdline.num_localities_ != 1 || cmdline.node_ != 0 || + cmdline.rtcfg_.enable_networking()) { - parcelset::parcelhandler::init(&argc, &argv, cms); + parcelset::parcelhandler::init(&argc, &argv, cmdline); } #endif HPX_UNUSED(argc); @@ -810,23 +810,42 @@ namespace hpx { return result; } + hpx::util::command_line_handling cmdline{ + hpx::util::runtime_configuration(argv[0], params.mode), + hpx_startup::user_main_config(params.cfg), f}; + // scope exception handling to resource partitioner initialization // any exception thrown during run_or_start below are handled // separately try { - // Construct resource partitioner if this has not been done - // yet and get a handle to it (if the command-line parsing - // has not yet been done, do it now) std::vector< std::shared_ptr> component_registries; + + result = cmdline.call( + params.desc_cmdline, argc, argv, component_registries); + + hpx::threads::policies::detail::affinity_data + affinity_data{}; + affinity_data.init(hpx::util::get_entry_as( + cmdline.rtcfg_, "hpx.os_threads", 0), + hpx::util::get_entry_as( + cmdline.rtcfg_, "hpx.cores", 0), + hpx::util::get_entry_as( + cmdline.rtcfg_, "hpx.pu_offset", 0), + hpx::util::get_entry_as( + cmdline.rtcfg_, "hpx.pu_step", 0), + static_cast( + cmdline.rtcfg_.get_first_used_core()), + cmdline.rtcfg_.get_entry("hpx.affinity", ""), + cmdline.rtcfg_.get_entry("hpx.bind", ""), + hpx::util::get_entry_as( + cmdline.rtcfg_, "hpx.use_process_mask", 0)); + hpx::resource::partitioner rp = - hpx::resource::detail::make_partitioner(f, - params.desc_cmdline, argc, argv, - hpx_startup::user_main_config(params.cfg), - params.rp_mode, params.mode, false, - component_registries, &result); + hpx::resource::detail::make_partitioner( + params.rp_mode, cmdline.rtcfg_, affinity_data); for (auto& registry : component_registries) { @@ -835,8 +854,7 @@ namespace hpx { }); } - activate_global_options( - rp.get_command_line_switches(), argc, argv); + activate_global_options(cmdline, argc, argv); // check whether HPX should be exited at this point // (parse_result is returning a result > 0, if the program options @@ -867,31 +885,28 @@ namespace hpx { // Initialize and start the HPX runtime. LPROGRESS_ << "run_local: create runtime"; - util::command_line_handling& cms = - resource::get_partitioner().get_command_line_switches(); - // Build and configure this runtime instance. std::unique_ptr rt; // Command line handling should have updated this by now. - HPX_ASSERT(cms.rtcfg_.mode_ != runtime_mode::default_); - switch (cms.rtcfg_.mode_) + HPX_ASSERT(cmdline.rtcfg_.mode_ != runtime_mode::default_); + switch (cmdline.rtcfg_.mode_) { case runtime_mode::local: { LPROGRESS_ << "creating local runtime"; - rt.reset(new hpx::runtime(cms.rtcfg_)); + rt.reset(new hpx::runtime(cmdline.rtcfg_)); break; } default: { #if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) LPROGRESS_ << "creating distributed runtime"; - rt.reset(new hpx::runtime_distributed(cms.rtcfg_)); + rt.reset(new hpx::runtime_distributed(cmdline.rtcfg_)); break; #else char const* mode_name = - get_runtime_mode_name(cms.rtcfg_.mode_); + get_runtime_mode_name(cmdline.rtcfg_.mode_); std::ostringstream s; s << "Attempted to start the runtime in the mode \"" << mode_name @@ -908,7 +923,7 @@ namespace hpx { } } - result = run_or_start(blocking, std::move(rt), cms, + result = run_or_start(blocking, std::move(rt), cmdline, std::move(params.startup), std::move(params.shutdown)); } catch (detail::command_line_error const& e) diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp index fe6a27c90331..55f3c07cc7fe 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -34,13 +35,8 @@ namespace hpx { namespace detail { namespace hpx { namespace resource { namespace detail { HPX_EXPORT partitioner& create_partitioner( - util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, int argc, - char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result); + resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data); }}} // namespace hpx::resource::detail diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp index 37ae4d16191c..12946ad3e480 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp @@ -9,10 +9,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -117,7 +117,6 @@ namespace hpx { namespace resource { namespace detail { void add_resource(const std::vector& ndv, std::string const& pool_name, bool exclusive = true); - // called by constructor of scheduler_base threads::policies::detail::affinity_data const& get_affinity_data() const { @@ -141,9 +140,6 @@ namespace hpx { namespace resource { namespace detail { //////////////////////////////////////////////////////////////////////// scheduling_policy which_scheduler(std::string const& pool_name); threads::topology& get_topology() const; - util::command_line_handling& get_command_line_switches(); - - std::size_t get_num_distinct_pus() const; std::size_t get_num_pools() const; @@ -161,15 +157,9 @@ namespace hpx { namespace resource { namespace detail { threads::mask_cref_type get_pu_mask( std::size_t global_thread_num) const; - bool cmd_line_parsed() const; - int parse(util::function_nonser const& f, - hpx::program_options::options_description desc_cmdline, int argc, - char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, - std::vector>& - component_registries, - bool fill_internal_topology); + void init(resource::partitioner_mode rpmode, + hpx::util::runtime_configuration cfg, + hpx::threads::policies::detail::affinity_data affinity_data); scheduler_function get_pool_creator(size_t index) const; @@ -178,11 +168,6 @@ namespace hpx { namespace resource { namespace detail { return numa_domains_; } - int parse_result() const - { - return cfg_.parse_result_; - } - std::size_t assign_cores(std::size_t first_core); // manage dynamic footprint of pools @@ -237,7 +222,7 @@ namespace hpx { namespace resource { namespace detail { static std::atomic instance_number_counter_; // holds all of the command line switches - util::command_line_handling cfg_; + util::runtime_configuration rtcfg_; std::size_t first_core_; std::size_t pus_needed_; diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp index 927eb3bc2788..251d1d369e4a 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp @@ -8,9 +8,9 @@ #include #include -#include #include #include +#include #include #include @@ -129,40 +129,24 @@ namespace hpx { namespace resource { /////////////////////////////////////////////////////////////////////////// namespace detail { inline ::hpx::resource::partitioner make_partitioner( - util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, - int argc, char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result); + resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data); } class partitioner { private: friend ::hpx::resource::partitioner detail::make_partitioner( - util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, - int argc, char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result); - - partitioner(util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, - int argc, char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result) - : partitioner_(detail::create_partitioner(f, desc_cmdline, argc, argv, - std::move(ini_config), rpmode, mode, check, - component_registries, result)) + resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data); + + partitioner(resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data) + : partitioner_( + detail::create_partitioner(rpmode, rtcfg, affinity_data)) { } @@ -216,33 +200,21 @@ namespace hpx { namespace resource { // return the topology object managed by the internal partitioner HPX_EXPORT hpx::threads::topology const& get_topology() const; - // access the command line options - HPX_EXPORT util::command_line_handling& get_command_line_switches(); - // Does initialization of all resources and internal data of the // resource partitioner called in hpx_init HPX_EXPORT void configure_pools(); - // Return the initialization result for this resource_partitioner - HPX_EXPORT int parse_result() const; - private: detail::partitioner& partitioner_; }; namespace detail { ::hpx::resource::partitioner make_partitioner( - util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, - int argc, char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result) + resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data) { - return ::hpx::resource::partitioner(f, desc_cmdline, argc, argv, - ini_config, rpmode, mode, check, component_registries, result); + return ::hpx::resource::partitioner(rpmode, rtcfg, affinity_data); } } // namespace detail }} // namespace hpx::resource diff --git a/libs/full/resource_partitioner/src/detail_partitioner.cpp b/libs/full/resource_partitioner/src/detail_partitioner.cpp index 0c211ed9e39f..0afe629b099b 100644 --- a/libs/full/resource_partitioner/src/detail_partitioner.cpp +++ b/libs/full/resource_partitioner/src/detail_partitioner.cpp @@ -6,18 +6,19 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -205,8 +206,8 @@ namespace hpx { namespace resource { namespace detail { //////////////////////////////////////////////////////////////////////// partitioner::partitioner() - : first_core_(std::size_t(-1)) - , pus_needed_(std::size_t(-1)) + : rtcfg_(nullptr, runtime_mode::default_) + , first_core_(std::size_t(-1)) , mode_(mode_default) , topo_(threads::create_topology()) , default_scheduler_mode_(threads::policies::scheduler_mode::default_mode) @@ -233,7 +234,7 @@ namespace hpx { namespace resource { namespace detail { #endif std::string default_scheduler_mode_str = - cfg_.rtcfg_.get_entry("hpx.default_scheduler_mode", std::string()); + rtcfg_.get_entry("hpx.default_scheduler_mode", std::string()); if (!default_scheduler_mode_str.empty()) { default_scheduler_mode_ = threads::policies::scheduler_mode( @@ -367,9 +368,8 @@ namespace hpx { namespace resource { namespace detail { reconfigure_affinities_locked(); } - // should have been initialized by now - HPX_ASSERT(pus_needed_ != std::size_t(-1)); - return pus_needed_; + HPX_ASSERT(affinity_data_.get_num_pus_needed() != std::size_t(-1)); + return affinity_data_.get_num_pus_needed(); } // This function is called in hpx_init, before the instantiation of the @@ -434,35 +434,44 @@ namespace hpx { namespace resource { namespace detail { // select the default scheduler scheduling_policy default_scheduler; - if (0 == std::string("local").find(cfg_.queuing_)) + std::string default_scheduler_str = + rtcfg_.get_entry("hpx.scheduler", std::string()); + + if (0 == std::string("local").find(default_scheduler_str)) { default_scheduler = scheduling_policy::local; } - else if (0 == std::string("local-priority-fifo").find(cfg_.queuing_)) + else if (0 == + std::string("local-priority-fifo").find(default_scheduler_str)) { default_scheduler = scheduling_policy::local_priority_fifo; } - else if (0 == std::string("local-priority-lifo").find(cfg_.queuing_)) + else if (0 == + std::string("local-priority-lifo").find(default_scheduler_str)) { default_scheduler = scheduling_policy::local_priority_lifo; } - else if (0 == std::string("static").find(cfg_.queuing_)) + else if (0 == std::string("static").find(default_scheduler_str)) { default_scheduler = scheduling_policy::static_; } - else if (0 == std::string("static-priority").find(cfg_.queuing_)) + else if (0 == + std::string("static-priority").find(default_scheduler_str)) { default_scheduler = scheduling_policy::static_priority; } - else if (0 == std::string("abp-priority-fifo").find(cfg_.queuing_)) + else if (0 == + std::string("abp-priority-fifo").find(default_scheduler_str)) { default_scheduler = scheduling_policy::abp_priority_fifo; } - else if (0 == std::string("abp-priority-lifo").find(cfg_.queuing_)) + else if (0 == + std::string("abp-priority-lifo").find(default_scheduler_str)) { default_scheduler = scheduling_policy::abp_priority_lifo; } - else if (0 == std::string("shared-priority").find(cfg_.queuing_)) + else if (0 == + std::string("shared-priority").find(default_scheduler_str)) { default_scheduler = scheduling_policy::shared_priority; } @@ -667,13 +676,12 @@ namespace hpx { namespace resource { namespace detail { // Make sure the total number of requested threads does not exceed // the number of threads requested on the command line - if (detail::init_pool_data::num_threads_overall > cfg_.num_threads_) + std::size_t num_threads = + util::get_entry_as(rtcfg_, "hpx.os_threads", 0); + HPX_ASSERT(num_threads != 0); + + if (detail::init_pool_data::num_threads_overall > num_threads) { - //! FIXME add allow_empty_default_pool policy - /* if (rp-policy == allow_empty_default_pool - && detail::init_pool_data::num_threads_overall == cfg_.num_threads_) { - // then it's all fine - } else {*/ l.unlock(); throw std::runtime_error("partitioner::add_resource: " "Creation of " + @@ -681,9 +689,8 @@ namespace hpx { namespace resource { namespace detail { detail::init_pool_data::num_threads_overall) + " threads requested by the resource partitioner, but " "only " + - std::to_string(cfg_.num_threads_) + + std::to_string(num_threads) + " provided on the command-line."); - // } } } else @@ -775,16 +782,6 @@ namespace hpx { namespace resource { namespace detail { return topo_; } - util::command_line_handling& partitioner::get_command_line_switches() - { - return cfg_; - } - - std::size_t partitioner::get_num_distinct_pus() const - { - return cfg_.num_threads_; - } - std::size_t partitioner::get_num_threads() const { std::size_t num_threads = 0; @@ -801,7 +798,9 @@ namespace hpx { namespace resource { namespace detail { // the number of allocated threads should be the same as the number of // threads to create (if no over-subscription is allowed) HPX_ASSERT(mode_ & mode_allow_oversubscription || - num_threads == cfg_.num_threads_); + num_threads == + util::get_entry_as( + rtcfg_, "hpx.os_threads", std::size_t(-1))); return num_threads; } @@ -870,52 +869,15 @@ namespace hpx { namespace resource { namespace detail { return affinity_data_.get_pu_mask(topo_, global_thread_num); } - bool partitioner::cmd_line_parsed() const - { - return (cfg_.cmd_line_parsed_ == true); - } - - int partitioner::parse( - util::function_nonser const& f, - hpx::program_options::options_description desc_cmdline, int argc, - char** argv, std::vector ini_config, // -V813 - resource::partitioner_mode rpmode, runtime_mode mode, - std::vector>& - component_registries, - bool fill_internal_topology) + void partitioner::init(resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data) { mode_ = rpmode; + rtcfg_ = rtcfg; + affinity_data_ = affinity_data; - // set internal parameters of runtime configuration - cfg_.rtcfg_ = util::runtime_configuration(argv[0], mode); - cfg_.ini_config_ = std::move(ini_config); - cfg_.hpx_main_f_ = f; - - // parse command line and set options - // terminate set if program options contain --hpx:help or --hpx:version ... - cfg_.parse_result_ = - cfg_.call(desc_cmdline, argc, argv, component_registries); - - // set all parameters related to affinity data - std::string affinity_description; - get_affinity_description(cfg_, affinity_description); - - pus_needed_ = affinity_data_.init(cfg_.num_threads_, - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.cores", 0), 0), - get_pu_offset(cfg_), get_pu_step(cfg_), - static_cast(cfg_.rtcfg_.get_first_used_core()), - get_affinity_domain(cfg_), affinity_description, - cfg_.use_process_mask_); - - if (fill_internal_topology) - { - // set data describing internal topology back-end - fill_topology_vectors(); - } - - return cfg_.parse_result_; + fill_topology_vectors(); } scheduler_function partitioner::get_pool_creator(std::size_t index) const diff --git a/libs/full/resource_partitioner/src/partitioner.cpp b/libs/full/resource_partitioner/src/partitioner.cpp index 0411b35a2856..5547bb294b9c 100644 --- a/libs/full/resource_partitioner/src/partitioner.cpp +++ b/libs/full/resource_partitioner/src/partitioner.cpp @@ -103,10 +103,6 @@ namespace hpx { namespace resource { } // namespace detail /////////////////////////////////////////////////////////////////////////// - struct partitioner_tag - { - }; - detail::partitioner& get_partitioner() { std::unique_ptr& rp = detail::get_partitioner(); @@ -121,14 +117,6 @@ namespace hpx { namespace resource { "been initialized and before it has been deleted."); } - if (!rp->cmd_line_parsed()) - { - HPX_THROW_EXCEPTION(invalid_status, - "hpx::resource::get_partitioner", - "can be called only after the resource partitioner has " - "been allowed to parse the command line options."); - } - return *rp; } @@ -139,48 +127,15 @@ namespace hpx { namespace resource { namespace detail { detail::partitioner& create_partitioner( - util::function_nonser const& f, - hpx::program_options::options_description const& desc_cmdline, - int argc, char** argv, std::vector ini_config, - resource::partitioner_mode rpmode, runtime_mode mode, bool check, - std::vector>& - component_registries, - int* result) + resource::partitioner_mode rpmode, + hpx::util::runtime_configuration rtcfg, + hpx::threads::policies::detail::affinity_data affinity_data) { std::unique_ptr& rp = detail::get_partitioner(); - if (rp->cmd_line_parsed()) - { - if (check) - { - // if the resource partitioner is not accessed for the - // first time if the command-line parsing has not yet - // been done - HPX_THROW_EXCEPTION(invalid_status, - "hpx::resource::get_partitioner", - "can be called only after the resource partitioner " - "has been allowed to parse the command line " - "options."); - } + rp->init(rpmode, rtcfg, affinity_data); - // no need to parse a second time - if (result != nullptr) - { - *result = 0; - } - } - else - { - int r = rp->parse(f, desc_cmdline, argc, argv, - std::move(ini_config), rpmode, mode, component_registries, - true); - if (result != nullptr) - { - *result = r; - } - } return *rp; } } // namespace detail @@ -260,22 +215,10 @@ namespace hpx { namespace resource { return partitioner_.threads_needed(); } - util::command_line_handling& partitioner::get_command_line_switches() - { - return partitioner_.get_command_line_switches(); - } - // Does initialization of all resources and internal data of the // resource partitioner called in hpx_init void partitioner::configure_pools() { partitioner_.configure_pools(); } - - // Return the initialization result for this resource_partitioner - int partitioner::parse_result() const - { - return partitioner_.parse_result(); - } - }} // namespace hpx::resource diff --git a/libs/full/runtime_local/include/hpx/runtime_local/runtime_local.hpp b/libs/full/runtime_local/include/hpx/runtime_local/runtime_local.hpp index 541a236c9910..f7f612a32829 100644 --- a/libs/full/runtime_local/include/hpx/runtime_local/runtime_local.hpp +++ b/libs/full/runtime_local/include/hpx/runtime_local/runtime_local.hpp @@ -404,7 +404,7 @@ namespace hpx { on_exit_type on_exit_functions_; mutable std::mutex mtx_; - util::runtime_configuration ini_; + util::runtime_configuration rtcfg_; long instance_number_; static std::atomic instance_number_counter_; diff --git a/libs/full/runtime_local/src/runtime_local.cpp b/libs/full/runtime_local/src/runtime_local.cpp index 91935b13209d..e1191e9641e5 100644 --- a/libs/full/runtime_local/src/runtime_local.cpp +++ b/libs/full/runtime_local/src/runtime_local.cpp @@ -7,13 +7,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -260,7 +260,7 @@ namespace hpx { /////////////////////////////////////////////////////////////////////////// runtime::runtime(util::runtime_configuration& rtcfg, bool initialize) - : ini_(rtcfg) + : rtcfg_(rtcfg) , instance_number_(++instance_number_counter_) , thread_support_(new util::thread_mapper) , topology_(resource::get_partitioner().get_topology()) @@ -274,18 +274,18 @@ namespace hpx { #ifdef HPX_HAVE_IO_POOL , io_pool_notifier_(runtime::get_notification_policy( "io-thread", runtime_local::os_thread_type::io_thread)) - , io_pool_( - rtcfg.get_thread_pool_size("io_pool"), io_pool_notifier_, "io_pool") + , io_pool_(rtcfg_.get_thread_pool_size("io_pool"), io_pool_notifier_, + "io_pool") #endif #ifdef HPX_HAVE_TIMER_POOL , timer_pool_notifier_(runtime::get_notification_policy( "timer-thread", runtime_local::os_thread_type::timer_thread)) - , timer_pool_(rtcfg.get_thread_pool_size("timer_pool"), + , timer_pool_(rtcfg_.get_thread_pool_size("timer_pool"), timer_pool_notifier_, "timer_pool") #endif , notifier_(runtime::get_notification_policy( "worker-thread", runtime_local::os_thread_type::worker_thread)) - , thread_manager_(new hpx::threads::threadmanager( + , thread_manager_(new hpx::threads::threadmanager(rtcfg_, #ifdef HPX_HAVE_TIMER_POOL timer_pool_, #endif @@ -325,7 +325,7 @@ namespace hpx { #endif , bool initialize) - : ini_(rtcfg) + : rtcfg_(rtcfg) , instance_number_(++instance_number_counter_) , thread_support_(new util::thread_mapper) , topology_(resource::get_partitioner().get_topology()) @@ -338,16 +338,16 @@ namespace hpx { , main_pool_(1, main_pool_notifier_, "main_pool") #ifdef HPX_HAVE_IO_POOL , io_pool_notifier_(std::move(io_pool_notifier)) - , io_pool_( - rtcfg.get_thread_pool_size("io_pool"), io_pool_notifier_, "io_pool") + , io_pool_(rtcfg_.get_thread_pool_size("io_pool"), io_pool_notifier_, + "io_pool") #endif #ifdef HPX_HAVE_TIMER_POOL , timer_pool_notifier_(std::move(timer_pool_notifier)) - , timer_pool_(rtcfg.get_thread_pool_size("timer_pool"), + , timer_pool_(rtcfg_.get_thread_pool_size("timer_pool"), timer_pool_notifier_, "timer_pool") #endif , notifier_(std::move(notifier)) - , thread_manager_(new hpx::threads::threadmanager( + , thread_manager_(new hpx::threads::threadmanager(rtcfg_, #ifdef HPX_HAVE_TIMER_POOL timer_pool_, #endif @@ -463,12 +463,12 @@ namespace hpx { util::runtime_configuration& runtime::get_config() { - return ini_; + return rtcfg_; } util::runtime_configuration const& runtime::get_config() const { - return ini_; + return rtcfg_; } std::size_t runtime::get_instance_number() const @@ -803,20 +803,12 @@ namespace hpx { std::string get_config_entry( std::string const& key, std::string const& dflt) { - //! FIXME runtime_configuration should probs be a member of - // hpx::runtime only, not command_line_handling - //! FIXME change functions in this section accordingly if (get_runtime_ptr() != nullptr) { return get_runtime().get_config().get_entry(key, dflt); } - if (!resource::is_partitioner_valid()) - { - return dflt; - } - return resource::get_partitioner() - .get_command_line_switches() - .rtcfg_.get_entry(key, dflt); + + return dflt; } std::string get_config_entry(std::string const& key, std::size_t dflt) @@ -825,13 +817,8 @@ namespace hpx { { return get_runtime().get_config().get_entry(key, dflt); } - if (!resource::is_partitioner_valid()) - { - return std::to_string(dflt); - } - return resource::get_partitioner() - .get_command_line_switches() - .rtcfg_.get_entry(key, dflt); + + return std::to_string(dflt); } // set entries @@ -842,30 +829,11 @@ namespace hpx { get_runtime_ptr()->get_config().add_entry(key, value); return; } - if (resource::is_partitioner_valid()) - { - resource::get_partitioner() - .get_command_line_switches() - .rtcfg_.add_entry(key, value); - return; - } } void set_config_entry(std::string const& key, std::size_t value) { - if (get_runtime_ptr() != nullptr) - { - get_runtime_ptr()->get_config().add_entry( - key, std::to_string(value)); - return; - } - if (resource::is_partitioner_valid()) - { - resource::get_partitioner() - .get_command_line_switches() - .rtcfg_.add_entry(key, std::to_string(value)); - return; - } + set_config_entry(key, std::to_string(value)); } void set_config_entry_callback(std::string const& key, @@ -878,13 +846,6 @@ namespace hpx { key, callback); return; } - if (resource::is_partitioner_valid()) - { - resource::get_partitioner() - .get_command_line_switches() - .rtcfg_.add_notification_callback(key, callback); - return; - } } namespace util { diff --git a/libs/full/threadmanager/include/hpx/modules/threadmanager.hpp b/libs/full/threadmanager/include/hpx/modules/threadmanager.hpp index 11ed710a3025..a806c4808787 100644 --- a/libs/full/threadmanager/include/hpx/modules/threadmanager.hpp +++ b/libs/full/threadmanager/include/hpx/modules/threadmanager.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,7 @@ namespace hpx { namespace threads { typedef threads::policies::scheduler_base scheduler_type; typedef std::vector pool_vector; - threadmanager( + threadmanager(util::runtime_configuration& rtcfg_, #ifdef HPX_HAVE_TIMER_POOL util::io_service_pool& timer_pool, #endif @@ -393,11 +394,7 @@ namespace hpx { namespace threads { private: mutable mutex_type mtx_; // mutex protecting the members - // specified by the user in command line, or all cores by default - // represents the total number of OS threads, irrespective of how many - // are in which pool. - std::size_t num_threads_; - + util::runtime_configuration& rtcfg_; std::vector threads_lookup_; #ifdef HPX_HAVE_TIMER_POOL diff --git a/libs/full/threadmanager/src/threadmanager.cpp b/libs/full/threadmanager/src/threadmanager.cpp index 0f07daa2f2c1..e488eabb6f35 100644 --- a/libs/full/threadmanager/src/threadmanager.cpp +++ b/libs/full/threadmanager/src/threadmanager.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -43,55 +42,33 @@ #include #include -/////////////////////////////////////////////////////////////////////////////// -namespace hpx { namespace detail { - - // helper functions testing option compatibility - void ensure_high_priority_compatibility( - hpx::program_options::variables_map const& vm) - { - if (vm.count("hpx:high-priority-threads")) - { - throw detail::command_line_error( - "Invalid command line option " - "--hpx:high-priority-threads, valid for " - "--hpx:queuing=local-priority and " - "--hpx:queuing=abp-priority only"); - } - } - - void ensure_numa_sensitivity_compatibility( - hpx::program_options::variables_map const& vm) - { - if (vm.count("hpx:numa-sensitive")) +namespace hpx { namespace threads { + namespace detail { + void check_num_high_priority_queues( + std::size_t num_threads, std::size_t num_high_priority_queues) { - throw detail::command_line_error( - "Invalid command line option " - "--hpx:numa-sensitive, valid for " - "--hpx:queuing=local, --hpx:queuing=local-priority, or " - "--hpx:queuing=abp-priority only"); + if (num_high_priority_queues > num_threads) + { + throw hpx::detail::command_line_error( + "Invalid command line option: " + "number of high priority threads (" + "--hpx:high-priority-threads), should not be larger " + "than number of threads (--hpx:threads)"); + } } - } - - void ensure_queuing_option_compatibility( - hpx::program_options::variables_map const& vm) - { - ensure_high_priority_compatibility(vm); - ensure_numa_sensitivity_compatibility(vm); - } -}} // namespace hpx::detail + } // namespace detail -namespace hpx { namespace threads { /////////////////////////////////////////////////////////////////////////// - threadmanager::threadmanager( + threadmanager::threadmanager(util::runtime_configuration& rtcfg, #ifdef HPX_HAVE_TIMER_POOL util::io_service_pool& timer_pool, #endif notification_policy_type& notifier, detail::network_background_callback_type network_background_callback) - : num_threads_(hpx::resource::get_partitioner().get_num_distinct_pus()) + : rtcfg_(rtcfg) + , #ifdef HPX_HAVE_TIMER_POOL - , timer_pool_(timer_pool) + timer_pool_(timer_pool) #endif , notifier_(notifier) , network_background_callback_(network_background_callback) @@ -116,65 +93,62 @@ namespace hpx { namespace threads { { auto& rp = hpx::resource::get_partitioner(); size_t num_pools = rp.get_num_pools(); - util::command_line_handling const& cfg_ = - rp.get_command_line_switches(); std::size_t thread_offset = 0; std::size_t max_background_threads = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.max_background_threads", - (std::numeric_limits::max)())); + hpx::util::get_entry_as(rtcfg_, + "hpx.max_background_threads", + (std::numeric_limits::max)()); std::size_t const max_idle_loop_count = - hpx::util::from_string(cfg_.rtcfg_.get_entry( - "hpx.max_idle_loop_count", HPX_IDLE_LOOP_COUNT_MAX)); + hpx::util::get_entry_as( + rtcfg_, "hpx.max_idle_loop_count", HPX_IDLE_LOOP_COUNT_MAX); std::size_t const max_busy_loop_count = - hpx::util::from_string(cfg_.rtcfg_.get_entry( - "hpx.max_busy_loop_count", HPX_BUSY_LOOP_COUNT_MAX)); + hpx::util::get_entry_as( + rtcfg_, "hpx.max_busy_loop_count", HPX_BUSY_LOOP_COUNT_MAX); std::int64_t const max_thread_count = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.max_thread_count", - std::to_string(HPX_THREAD_QUEUE_MAX_THREAD_COUNT))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.max_thread_count", + HPX_THREAD_QUEUE_MAX_THREAD_COUNT); std::int64_t const min_tasks_to_steal_pending = - hpx::util::from_string(cfg_.rtcfg_.get_entry( + hpx::util::get_entry_as(rtcfg_, "hpx.thread_queue.min_tasks_to_steal_pending", - std::to_string(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING))); + HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING); std::int64_t const min_tasks_to_steal_staged = - hpx::util::from_string(cfg_.rtcfg_.get_entry( + hpx::util::get_entry_as(rtcfg_, "hpx.thread_queue.min_tasks_to_steal_staged", - std::to_string(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED))); + HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED); std::int64_t const min_add_new_count = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.min_add_new_count", - std::to_string(HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.min_add_new_count", + HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT); std::int64_t const max_add_new_count = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.max_add_new_count", - std::to_string(HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.max_add_new_count", + HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT); std::int64_t const min_delete_count = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.min_delete_count", - std::to_string(HPX_THREAD_QUEUE_MIN_DELETE_COUNT))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.min_delete_count", + HPX_THREAD_QUEUE_MIN_DELETE_COUNT); std::int64_t const max_delete_count = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.max_delete_count", - std::to_string(HPX_THREAD_QUEUE_MAX_DELETE_COUNT))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.max_delete_count", + HPX_THREAD_QUEUE_MAX_DELETE_COUNT); std::int64_t const max_terminated_threads = - hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.thread_queue.max_terminated_threads", - std::to_string(HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS))); - double const max_idle_backoff_time = hpx::util::from_string( - cfg_.rtcfg_.get_entry("hpx.max_idle_backoff_time", - std::to_string(HPX_IDLE_BACKOFF_TIME_MAX))); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.max_terminated_threads", + HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS); + double const max_idle_backoff_time = hpx::util::get_entry_as( + rtcfg_, "hpx.max_idle_backoff_time", HPX_IDLE_BACKOFF_TIME_MAX); std::ptrdiff_t small_stacksize = - cfg_.rtcfg_.get_stack_size(thread_stacksize::small_); + rtcfg_.get_stack_size(thread_stacksize::small_); std::ptrdiff_t medium_stacksize = - cfg_.rtcfg_.get_stack_size(thread_stacksize::medium); + rtcfg_.get_stack_size(thread_stacksize::medium); std::ptrdiff_t large_stacksize = - cfg_.rtcfg_.get_stack_size(thread_stacksize::large); + rtcfg_.get_stack_size(thread_stacksize::large); std::ptrdiff_t huge_stacksize = - cfg_.rtcfg_.get_stack_size(thread_stacksize::huge); + rtcfg_.get_stack_size(thread_stacksize::huge); policies::thread_queue_init_parameters thread_queue_init( max_thread_count, min_tasks_to_steal_pending, @@ -183,7 +157,7 @@ namespace hpx { namespace threads { max_idle_backoff_time, small_stacksize, medium_stacksize, large_stacksize, huge_stacksize); - if (!cfg_.rtcfg_.enable_networking()) + if (!rtcfg_.enable_networking()) { max_background_threads = 0; } @@ -203,8 +177,8 @@ namespace hpx { namespace threads { { throw std::invalid_argument("Trying to instantiate pool " + name + - " as first thread pool, but first thread pool must be " - "named " + + " as first thread pool, but first thread pool must " + "be named " + rp.get_default_pool_name()); } } @@ -215,9 +189,8 @@ namespace hpx { namespace threads { max_background_threads, max_idle_loop_count, max_busy_loop_count); - std::string affinity_desc; - std::size_t numa_sensitive = - hpx::util::get_affinity_description(cfg_, affinity_desc); + std::size_t numa_sensitive = hpx::util::get_entry_as( + rtcfg_, "hpx.numa_sensitive", 0); switch (sched_type) { @@ -238,10 +211,6 @@ namespace hpx { namespace threads { case resource::local: { #if defined(HPX_HAVE_LOCAL_SCHEDULER) - // set parameters for scheduler and pool instantiation and - // perform compatibility checks - hpx::detail::ensure_high_priority_compatibility(cfg_.vm_); - // instantiate the scheduler using local_sched_type = hpx::threads::policies::local_queue_scheduler<>; @@ -279,8 +248,11 @@ namespace hpx { namespace threads { // set parameters for scheduler and pool instantiation and // perform compatibility checks std::size_t num_high_priority_queues = - hpx::util::get_num_high_priority_queues( - cfg_, rp.get_num_threads(name)); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.high_priority_queues", + thread_pool_init.num_threads_); + detail::check_num_high_priority_queues( + thread_pool_init.num_threads_, num_high_priority_queues); // instantiate the scheduler using local_sched_type = @@ -316,8 +288,11 @@ namespace hpx { namespace threads { // set parameters for scheduler and pool instantiation and // perform compatibility checks std::size_t num_high_priority_queues = - hpx::util::get_num_high_priority_queues( - cfg_, rp.get_num_threads(name)); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.high_priority_queues", + thread_pool_init.num_threads_); + detail::check_num_high_priority_queues( + thread_pool_init.num_threads_, num_high_priority_queues); // instantiate the scheduler using local_sched_type = @@ -357,10 +332,6 @@ namespace hpx { namespace threads { case resource::static_: { #if defined(HPX_HAVE_STATIC_SCHEDULER) - // set parameters for scheduler and pool instantiation and - // perform compatibility checks - hpx::detail::ensure_high_priority_compatibility(cfg_.vm_); - // instantiate the scheduler using local_sched_type = hpx::threads::policies::static_queue_scheduler<>; @@ -399,8 +370,11 @@ namespace hpx { namespace threads { // set parameters for scheduler and pool instantiation and // perform compatibility checks std::size_t num_high_priority_queues = - hpx::util::get_num_high_priority_queues( - cfg_, rp.get_num_threads(name)); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.high_priority_queues", + thread_pool_init.num_threads_); + detail::check_num_high_priority_queues( + thread_pool_init.num_threads_, num_high_priority_queues); // instantiate the scheduler using local_sched_type = @@ -429,7 +403,8 @@ namespace hpx { namespace threads { throw hpx::detail::command_line_error( "Command line option --hpx:queuing=static-priority " "is not configured in this build. Please rebuild with " - "'cmake -DHPX_WITH_THREAD_SCHEDULERS=static-priority'."); + "'cmake " + "-DHPX_WITH_THREAD_SCHEDULERS=static-priority'."); #endif break; } @@ -440,8 +415,11 @@ namespace hpx { namespace threads { // set parameters for scheduler and pool instantiation and // perform compatibility checks std::size_t num_high_priority_queues = - hpx::util::get_num_high_priority_queues( - cfg_, rp.get_num_threads(name)); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.high_priority_queues", + thread_pool_init.num_threads_); + detail::check_num_high_priority_queues( + thread_pool_init.num_threads_, num_high_priority_queues); // instantiate the scheduler using local_sched_type = @@ -485,8 +463,11 @@ namespace hpx { namespace threads { // set parameters for scheduler and pool instantiation and // perform compatibility checks std::size_t num_high_priority_queues = - hpx::util::get_num_high_priority_queues( - cfg_, rp.get_num_threads(name)); + hpx::util::get_entry_as(rtcfg_, + "hpx.thread_queue.high_priority_queues", + thread_pool_init.num_threads_); + detail::check_num_high_priority_queues( + thread_pool_init.num_threads_, num_high_priority_queues); // instantiate the scheduler using local_sched_type = @@ -552,7 +533,8 @@ namespace hpx { namespace threads { throw hpx::detail::command_line_error( "Command line option --hpx:queuing=shared-priority " "is not configured in this build. Please rebuild with " - "'cmake -DHPX_WITH_THREAD_SCHEDULERS=shared-priority'."); + "'cmake " + "-DHPX_WITH_THREAD_SCHEDULERS=shared-priority'."); #endif break; } diff --git a/src/runtime/agas/addressing_service.cpp b/src/runtime/agas/addressing_service.cpp index 393a080ace36..66a7824a21d3 100644 --- a/src/runtime/agas/addressing_service.cpp +++ b/src/runtime/agas/addressing_service.cpp @@ -139,7 +139,7 @@ namespace hpx { namespace agas }; // }}} addressing_service::addressing_service( - util::runtime_configuration const& ini_, runtime_mode runtime_type_) + util::runtime_configuration const& ini_) : gva_cache_(new gva_cache_type) , console_cache_(naming::invalid_locality_id) , max_refcnt_requests_(ini_.get_agas_max_pending_refcnt_requests()) @@ -147,7 +147,7 @@ namespace hpx { namespace agas , enable_refcnt_caching_(true) , refcnt_requests_(new refcnt_requests_type) , service_type(ini_.get_agas_service_mode()) - , runtime_type(runtime_type_) + , runtime_type(ini_.mode_) , caching_(ini_.get_agas_caching_mode()) , range_caching_(caching_ ? ini_.get_agas_range_caching_mode() : false) , action_priority_(threads::thread_priority::boost) diff --git a/src/runtime_distributed.cpp b/src/runtime_distributed.cpp index 12553f9ca8cc..95bc7d6275f4 100644 --- a/src/runtime_distributed.cpp +++ b/src/runtime_distributed.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -387,18 +386,18 @@ namespace hpx { &detail::network_background_callback, #endif false) - , mode_(rtcfg.mode_) + , mode_(rtcfg_.mode_) #if defined(HPX_HAVE_NETWORKING) , parcel_handler_notifier_(runtime_distributed::get_notification_policy( "parcel-thread", runtime_local::os_thread_type::parcel_thread)) - , parcel_handler_(rtcfg, thread_manager_.get(), parcel_handler_notifier_) - , agas_client_(ini_, rtcfg.mode_) + , parcel_handler_(rtcfg_, thread_manager_.get(), parcel_handler_notifier_) + , agas_client_(rtcfg_) , applier_(parcel_handler_, *thread_manager_) #else - , agas_client_(ini_, rtcfg.mode_) + , agas_client_(rtcfg_) , applier_(*thread_manager_) #endif - , runtime_support_(new components::server::runtime_support(ini_)) + , runtime_support_(new components::server::runtime_support(rtcfg_)) { // This needs to happen first runtime::init(); @@ -415,9 +414,9 @@ namespace hpx { LPROGRESS_; #if defined(HPX_HAVE_NETWORKING) - agas_client_.bootstrap(parcel_handler_, ini_); + agas_client_.bootstrap(parcel_handler_, rtcfg_); #else - agas_client_.bootstrap(ini_); + agas_client_.bootstrap(rtcfg_); #endif components::server::get_error_dispatcher().set_error_sink( From de22c4fe3615d529988fcc481c34eae4be16090f Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 2 Dec 2020 09:11:23 +0100 Subject: [PATCH 2/2] Remove program_options dependency from command_line_handling module --- libs/full/resource_partitioner/CMakeLists.txt | 4 ++-- .../detail/create_partitioner.hpp | 13 ------------- .../hpx/resource_partitioner/detail/partitioner.hpp | 1 - .../hpx/resource_partitioner/partitioner.hpp | 2 -- libs/full/resource_partitioner/src/partitioner.cpp | 2 -- 5 files changed, 2 insertions(+), 20 deletions(-) diff --git a/libs/full/resource_partitioner/CMakeLists.txt b/libs/full/resource_partitioner/CMakeLists.txt index 1ed0902e9d49..50e08d0b9979 100644 --- a/libs/full/resource_partitioner/CMakeLists.txt +++ b/libs/full/resource_partitioner/CMakeLists.txt @@ -39,7 +39,7 @@ add_hpx_module( HEADERS ${resource_partitioner_headers} COMPAT_HEADERS ${resource_partitioner_compat_headers} DEPENDENCIES hpx_core hpx_parallelism - MODULE_DEPENDENCIES hpx_command_line_handling hpx_program_options - hpx_runtime_configuration ${MPI_DEPS} + MODULE_DEPENDENCIES hpx_command_line_handling hpx_runtime_configuration + ${MPI_DEPS} CMAKE_SUBDIRS examples tests ) diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp index 55f3c07cc7fe..1d3023c8e429 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/create_partitioner.hpp @@ -14,25 +14,12 @@ #include #include -#include - #include #include #include #include #include -#if !defined(HPX_EXPORTS) -// This function must be implemented by the application. -int hpx_main(hpx::program_options::variables_map& vm); -typedef int (*hpx_main_type)(hpx::program_options::variables_map&); -#endif - -namespace hpx { namespace detail { - HPX_EXPORT int init_helper(hpx::program_options::variables_map&, - util::function_nonser const&); -}} // namespace hpx::detail - namespace hpx { namespace resource { namespace detail { HPX_EXPORT partitioner& create_partitioner( resource::partitioner_mode rpmode, diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp index 12946ad3e480..2b0fc9670038 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/detail/partitioner.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp b/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp index 251d1d369e4a..3ec4b1d3dd0e 100644 --- a/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp +++ b/libs/full/resource_partitioner/include/hpx/resource_partitioner/partitioner.hpp @@ -14,8 +14,6 @@ #include #include -#include - #include #include #include diff --git a/libs/full/resource_partitioner/src/partitioner.cpp b/libs/full/resource_partitioner/src/partitioner.cpp index 5547bb294b9c..31d8a52e4740 100644 --- a/libs/full/resource_partitioner/src/partitioner.cpp +++ b/libs/full/resource_partitioner/src/partitioner.cpp @@ -9,8 +9,6 @@ #include #include -#include - #include #include #include