From 4633bb2861f72e8806a36a29de270cd7a64c90d5 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Tue, 8 Aug 2023 17:07:56 +0200 Subject: [PATCH] Rename create_topology to get_topology --- libs/pika/affinity/src/affinity_data.cpp | 2 +- libs/pika/affinity/src/parse_affinity_options.cpp | 4 +--- .../src/command_line_handling.cpp | 4 ++-- .../resource_partitioner/src/detail_partitioner.cpp | 2 +- libs/pika/runtime/src/runtime.cpp | 2 +- .../pika/schedulers/local_priority_queue_scheduler.hpp | 2 +- .../include/pika/schedulers/local_queue_scheduler.hpp | 6 +++--- .../schedulers/shared_priority_queue_scheduler.hpp | 2 +- .../pika/thread_pools/scheduled_thread_pool_impl.hpp | 4 ++-- libs/pika/threading_base/src/thread_pool_base.cpp | 4 ++-- libs/pika/topology/include/pika/topology/topology.hpp | 2 +- libs/pika/topology/src/topology.cpp | 10 +++++----- 12 files changed, 21 insertions(+), 23 deletions(-) diff --git a/libs/pika/affinity/src/affinity_data.cpp b/libs/pika/affinity/src/affinity_data.cpp index 148bb265aa..21b6ce9ae2 100644 --- a/libs/pika/affinity/src/affinity_data.cpp +++ b/libs/pika/affinity/src/affinity_data.cpp @@ -71,7 +71,7 @@ namespace pika::detail { init_cached_pu_nums(num_system_pus); - auto const& topo = threads::detail::create_topology(); + auto const& topo = threads::detail::get_topology(); if (affinity_description == "none") { diff --git a/libs/pika/affinity/src/parse_affinity_options.cpp b/libs/pika/affinity/src/parse_affinity_options.cpp index f558a580b7..3072e73d94 100644 --- a/libs/pika/affinity/src/parse_affinity_options.cpp +++ b/libs/pika/affinity/src/parse_affinity_options.cpp @@ -481,9 +481,7 @@ namespace pika::detail { parse_mappings(spec, mappings, ec); if (ec) return; - // We need to instantiate a new topology object as the runtime has not - // been initialized yet - threads::detail::topology& t = threads::detail::create_topology(); + threads::detail::topology& t = threads::detail::get_topology(); decode_distribution(mappings, t, affinities, used_cores, max_cores, num_threads, num_pus, use_process_mask, ec); diff --git a/libs/pika/command_line_handling/src/command_line_handling.cpp b/libs/pika/command_line_handling/src/command_line_handling.cpp index 29e5acd2a7..ae51aceb7f 100644 --- a/libs/pika/command_line_handling/src/command_line_handling.cpp +++ b/libs/pika/command_line_handling/src/command_line_handling.cpp @@ -195,7 +195,7 @@ namespace pika::detail { { if (use_process_mask) { - threads::detail::topology& top = threads::detail::create_topology(); + threads::detail::topology& top = threads::detail::get_topology(); return threads::detail::count(top.get_cpubind_mask_main_thread()); } else { return threads::detail::hardware_concurrency(); } @@ -203,7 +203,7 @@ namespace pika::detail { std::size_t get_number_of_default_cores(bool use_process_mask) { - threads::detail::topology& top = threads::detail::create_topology(); + threads::detail::topology& top = threads::detail::get_topology(); std::size_t num_cores = top.get_number_of_cores(); diff --git a/libs/pika/resource_partitioner/src/detail_partitioner.cpp b/libs/pika/resource_partitioner/src/detail_partitioner.cpp index 49428cdd4f..39f233e9b9 100644 --- a/libs/pika/resource_partitioner/src/detail_partitioner.cpp +++ b/libs/pika/resource_partitioner/src/detail_partitioner.cpp @@ -182,7 +182,7 @@ namespace pika::resource::detail { : rtcfg_() , first_core_(std::size_t(-1)) , mode_(mode_default) - , topo_(threads::detail::create_topology()) + , topo_(threads::detail::get_topology()) , default_scheduler_mode_(threads::scheduler_mode::default_mode) { // allow only one partitioner instance diff --git a/libs/pika/runtime/src/runtime.cpp b/libs/pika/runtime/src/runtime.cpp index 350a90ab98..c8718af5ee 100644 --- a/libs/pika/runtime/src/runtime.cpp +++ b/libs/pika/runtime/src/runtime.cpp @@ -998,7 +998,7 @@ namespace pika { namespace detail { void handle_print_bind(std::size_t num_threads) { - threads::detail::topology& top = threads::detail::create_topology(); + threads::detail::topology& top = threads::detail::get_topology(); auto const& rp = pika::resource::get_partitioner(); auto const& tm = get_runtime().get_thread_manager(); diff --git a/libs/pika/schedulers/include/pika/schedulers/local_priority_queue_scheduler.hpp b/libs/pika/schedulers/include/pika/schedulers/local_priority_queue_scheduler.hpp index 6d1d074448..096792b43e 100644 --- a/libs/pika/schedulers/include/pika/schedulers/local_priority_queue_scheduler.hpp +++ b/libs/pika/schedulers/include/pika/schedulers/local_priority_queue_scheduler.hpp @@ -1084,7 +1084,7 @@ namespace pika::threads::detail { queues_[num_thread].data_->on_start_thread(num_thread); std::size_t num_threads = num_queues_; - auto const& topo = ::pika::threads::detail::create_topology(); + auto const& topo = ::pika::threads::detail::get_topology(); // get NUMA domain masks of all queues... std::vector<::pika::threads::detail::mask_type> numa_masks(num_threads); diff --git a/libs/pika/schedulers/include/pika/schedulers/local_queue_scheduler.hpp b/libs/pika/schedulers/include/pika/schedulers/local_queue_scheduler.hpp index aefb3cabb0..e468e01c2e 100644 --- a/libs/pika/schedulers/include/pika/schedulers/local_queue_scheduler.hpp +++ b/libs/pika/schedulers/include/pika/schedulers/local_queue_scheduler.hpp @@ -98,9 +98,9 @@ namespace pika::threads::detail { , steals_in_numa_domain_() , steals_outside_numa_domain_() , numa_domain_masks_(init.num_queues_, - ::pika::threads::detail::create_topology().get_machine_affinity_mask()) + ::pika::threads::detail::get_topology().get_machine_affinity_mask()) , outside_numa_domain_masks_(init.num_queues_, - ::pika::threads::detail::create_topology().get_machine_affinity_mask()) + ::pika::threads::detail::get_topology().get_machine_affinity_mask()) { ::pika::threads::detail::resize( steals_in_numa_domain_, threads::detail::hardware_concurrency()); @@ -781,7 +781,7 @@ namespace pika::threads::detail { queues_[num_thread]->on_start_thread(num_thread); - auto const& topo = ::pika::threads::detail::create_topology(); + auto const& topo = ::pika::threads::detail::get_topology(); // pre-calculate certain constants for the given thread number std::size_t num_pu = affinity_data_.get_pu_num(num_thread); diff --git a/libs/pika/schedulers/include/pika/schedulers/shared_priority_queue_scheduler.hpp b/libs/pika/schedulers/include/pika/schedulers/shared_priority_queue_scheduler.hpp index 0a74c17310..ef41361c65 100644 --- a/libs/pika/schedulers/include/pika/schedulers/shared_priority_queue_scheduler.hpp +++ b/libs/pika/schedulers/include/pika/schedulers/shared_priority_queue_scheduler.hpp @@ -903,7 +903,7 @@ namespace pika::threads::detail { using namespace pika::debug::detail; PIKA_DETAIL_DP(spq_deb<5>, debug(str<>("start_thread"), "local_thread", local_thread)); - auto const& topo = ::pika::threads::detail::create_topology(); + auto const& topo = ::pika::threads::detail::get_topology(); // the main initialization can be done by any one thread std::unique_lock lock(init_mutex); if (!initialized_) diff --git a/libs/pika/thread_pools/include/pika/thread_pools/scheduled_thread_pool_impl.hpp b/libs/pika/thread_pools/include/pika/thread_pools/scheduled_thread_pool_impl.hpp index 4be6a57f8e..4aca1229cf 100644 --- a/libs/pika/thread_pools/include/pika/thread_pools/scheduled_thread_pool_impl.hpp +++ b/libs/pika/thread_pools/include/pika/thread_pools/scheduled_thread_pool_impl.hpp @@ -283,7 +283,7 @@ namespace pika::threads::detail { std::make_shared(pool_threads + 1); try { - topology const& topo = create_topology(); + topology const& topo = get_topology(); for (/**/; thread_num != pool_threads; ++thread_num) { @@ -392,7 +392,7 @@ namespace pika::threads::detail { pika::threads::detail::scheduled_thread_pool::thread_func(std::size_t thread_num, std::size_t global_thread_num, std::shared_ptr startup) { - topology const& topo = create_topology(); + topology const& topo = get_topology(); // Set the affinity for the current thread. threads::detail::mask_cref_type mask = affinity_data_.get_pu_mask(topo, global_thread_num); diff --git a/libs/pika/threading_base/src/thread_pool_base.cpp b/libs/pika/threading_base/src/thread_pool_base.cpp index 0a5c6117ef..e6376508f5 100644 --- a/libs/pika/threading_base/src/thread_pool_base.cpp +++ b/libs/pika/threading_base/src/thread_pool_base.cpp @@ -38,7 +38,7 @@ namespace pika::threads::detail { /////////////////////////////////////////////////////////////////////////// mask_type thread_pool_base::get_used_processing_units() const { - auto const& topo = create_topology(); + auto const& topo = get_topology(); auto const sched = get_scheduler(); mask_type used_processing_units = mask_type(); @@ -58,7 +58,7 @@ namespace pika::threads::detail { hwloc_bitmap_ptr thread_pool_base::get_numa_domain_bitmap() const { - auto const& topo = create_topology(); + auto const& topo = get_topology(); mask_type used_processing_units = get_used_processing_units(); return topo.cpuset_to_nodeset(used_processing_units); } diff --git a/libs/pika/topology/include/pika/topology/topology.hpp b/libs/pika/topology/include/pika/topology/topology.hpp index 16c6feae18..bd75c4b23e 100644 --- a/libs/pika/topology/include/pika/topology/topology.hpp +++ b/libs/pika/topology/include/pika/topology/topology.hpp @@ -368,7 +368,7 @@ namespace pika::threads::detail { #include /////////////////////////////////////////////////////////////////////////// - PIKA_EXPORT topology& create_topology(); + PIKA_EXPORT topology& get_topology(); [[nodiscard]] PIKA_EXPORT unsigned int hardware_concurrency() noexcept; diff --git a/libs/pika/topology/src/topology.cpp b/libs/pika/topology/src/topology.cpp index 7e75bb1cf8..32fcab126a 100644 --- a/libs/pika/topology/src/topology.cpp +++ b/libs/pika/topology/src/topology.cpp @@ -181,9 +181,9 @@ namespace pika::threads::detail { // initialization order between TUs happening in a particular order and we guarantee that the // object has been created before access. However, we also want to initialize the topology // object early so that we can read the CPU mask of the main thread in case OpenMP wants to - // reset it, so we also have a global object call create_topology so that we don't depend on - // others calling create_topology early for us. - topology& create_topology() + // reset it, so we also have a global object call get_topology so that we don't depend on others + // calling get_topology early for us. + topology& get_topology() { static topology topo; return topo; @@ -191,7 +191,7 @@ namespace pika::threads::detail { static struct init_topology_t { - init_topology_t() { create_topology(); } + init_topology_t() { get_topology(); } } init_topology{}; #if !defined(PIKA_HAVE_MAX_CPU_COUNT) @@ -1447,7 +1447,7 @@ namespace pika::threads::detail { #if defined(__ANDROID__) && defined(ANDROID) static auto concurrency = ::android_getCpuCount(); #else - static auto concurrency = create_topology().get_number_of_pus(); + static auto concurrency = get_topology().get_number_of_pus(); #endif return static_cast(concurrency); }