Skip to content

Commit

Permalink
Rename create_topology to get_topology
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Aug 11, 2023
1 parent 4f7e69c commit 4633bb2
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion libs/pika/affinity/src/affinity_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
4 changes: 1 addition & 3 deletions libs/pika/affinity/src/parse_affinity_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions libs/pika/command_line_handling/src/command_line_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ 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(); }
}

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();

Expand Down
2 changes: 1 addition & 1 deletion libs/pika/resource_partitioner/src/detail_partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/pika/runtime/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex> lock(init_mutex);
if (!initialized_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace pika::threads::detail {
std::make_shared<pika::concurrency::detail::barrier>(pool_threads + 1);
try
{
topology const& topo = create_topology();
topology const& topo = get_topology();

for (/**/; thread_num != pool_threads; ++thread_num)
{
Expand Down Expand Up @@ -392,7 +392,7 @@ namespace pika::threads::detail {
pika::threads::detail::scheduled_thread_pool<Scheduler>::thread_func(std::size_t thread_num,
std::size_t global_thread_num, std::shared_ptr<pika::concurrency::detail::barrier> 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);
Expand Down
4 changes: 2 additions & 2 deletions libs/pika/threading_base/src/thread_pool_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/pika/topology/include/pika/topology/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ namespace pika::threads::detail {
#include <pika/config/warnings_suffix.hpp>

///////////////////////////////////////////////////////////////////////////
PIKA_EXPORT topology& create_topology();
PIKA_EXPORT topology& get_topology();

[[nodiscard]] PIKA_EXPORT unsigned int hardware_concurrency() noexcept;

Expand Down
10 changes: 5 additions & 5 deletions libs/pika/topology/src/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,17 @@ 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;
}

static struct init_topology_t
{
init_topology_t() { create_topology(); }
init_topology_t() { get_topology(); }
} init_topology{};

#if !defined(PIKA_HAVE_MAX_CPU_COUNT)
Expand Down Expand Up @@ -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<unsigned int>(concurrency);
}
Expand Down

0 comments on commit 4633bb2

Please sign in to comment.