Skip to content

Commit

Permalink
Merge #6235
Browse files Browse the repository at this point in the history
6235: Modernize more modules (levels 12-16) r=hkaiser a=hkaiser



Co-authored-by: Hartmut Kaiser <[email protected]>
  • Loading branch information
StellarBot and hkaiser committed May 9, 2023
2 parents 0527180 + 4dfaec9 commit ad3ac76
Show file tree
Hide file tree
Showing 61 changed files with 1,034 additions and 997 deletions.
7 changes: 4 additions & 3 deletions cmake/HPX_PrintSummary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function(create_configuration_summary message module_name)
if(NOT ${__pos} EQUAL -1)
set(hpx_config_information
"${hpx_config_information}"
"\n \"${_variableName}=${_value}\","
"\n \"${_variableName}=${_value}\","
)
elseif(NOT ${_variableName}Category STREQUAL "Generic"
AND NOT ${_variableName}Category STREQUAL "Build Targets"
Expand All @@ -88,8 +88,9 @@ function(create_configuration_summary message module_name)
PROPERTY TYPE
)
if(_type STREQUAL "BOOL")
set(hpx_config_information "${hpx_config_information}"
"\n \"${_variableName}=OFF\","
set(hpx_config_information
"${hpx_config_information}"
"\n \"${_variableName}=OFF\","
)
endif()
endif()
Expand Down
10 changes: 8 additions & 2 deletions libs/core/affinity/include/hpx/affinity/affinity_data.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -26,6 +26,12 @@ namespace hpx::threads::policies::detail {
struct HPX_CORE_EXPORT affinity_data
{
affinity_data();

affinity_data(affinity_data const&);
affinity_data(affinity_data&&) noexcept;
affinity_data& operator=(affinity_data const&);
affinity_data& operator=(affinity_data&&) noexcept;

~affinity_data();

void init(std::size_t num_threads = 1, std::size_t max_cores = 1,
Expand Down Expand Up @@ -56,7 +62,7 @@ namespace hpx::threads::policies::detail {
}

mask_type get_pu_mask(
threads::topology const& topo, std::size_t num_thread) const;
threads::topology const& topo, std::size_t global_thread_num) const;

mask_type get_used_pus_mask(
threads::topology const& topo, std::size_t pu_num) const;
Expand Down
30 changes: 13 additions & 17 deletions libs/core/affinity/include/hpx/affinity/detail/partlit.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2001-2022 Hartmut Kaiser
Copyright (c) 2001-2023 Hartmut Kaiser
Copyright (c) 2010 Bryce Lelbach
// SPDX-License-Identifier: BSL-1.0
SPDX-License-Identifier: BSL-1.0
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
Expand All @@ -17,13 +17,12 @@
#include <boost/spirit/home/x3/support/traits/move_to.hpp>
#include <boost/spirit/home/x3/support/unused.hpp>

#include <string>
#include <type_traits>

namespace hpx::threads::detail {

template <typename Char, typename Iterator>
inline bool partial_string_parse(
constexpr bool partial_string_parse(
Char const* str, Iterator& first, Iterator const& last) noexcept
{
Iterator i = first;
Expand All @@ -45,14 +44,13 @@ namespace hpx::threads::detail {
}

template <typename String, typename Iterator>
inline bool partial_string_parse(
constexpr bool partial_string_parse(
String const& str, Iterator& first, Iterator const& last) noexcept
{
Iterator i = first;
typename String::const_iterator stri = str.begin();
typename String::const_iterator str_last = str.end();
auto const str_last = str.end();

for (; stri != str_last; ++stri, ++i)
for (auto stri = str.begin(); stri != str_last; ++stri, ++i)
{
if (i == last || (*stri != *i))
{
Expand All @@ -67,7 +65,7 @@ namespace hpx::threads::detail {
}

template <typename Char, typename Iterator>
inline bool partial_string_parse(Char const* uc_i, Char const* lc_i,
constexpr bool partial_string_parse(Char const* uc_i, Char const* lc_i,
Iterator& first, Iterator const& last) noexcept
{
Iterator i = first;
Expand All @@ -87,15 +85,13 @@ namespace hpx::threads::detail {
}

template <typename String, typename Iterator>
inline bool partial_string_parse(String const& ucstr, String const& lcstr,
Iterator& first, Iterator const& last) noexcept
constexpr bool partial_string_parse(String const& ucstr,
String const& lcstr, Iterator& first, Iterator const& last) noexcept
{
typename String::const_iterator uc_i = ucstr.begin();
typename String::const_iterator uc_last = ucstr.end();
typename String::const_iterator lc_i = lcstr.begin();
Iterator i = first;

for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
auto const uc_last = ucstr.end();
auto lc_i = lcstr.begin();
for (auto uc_i = ucstr.begin(); uc_i != uc_last; ++uc_i, ++lc_i, ++i)
{
if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
{
Expand All @@ -115,7 +111,7 @@ namespace hpx::threads::detail {
{
using attribute_type = Attribute;

static constexpr bool const has_attribute =
static constexpr bool has_attribute =
!std::is_same_v<boost::spirit::x3::unused_type, attribute_type>;

constexpr partlit_parser(String const& str, Attribute const& value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2008-2009 Chirag Dekate, Anshul Tandon
// Copyright (c) 2012-2013 Thomas Heller
//
Expand Down Expand Up @@ -62,10 +62,9 @@ namespace hpx::threads {
{
}

spec_type(type t, std::int64_t min = all_entities(),
explicit spec_type(type t, std::int64_t min = all_entities(),
std::int64_t max = all_entities())
: type_(t)
, index_bounds_()
{
if (t != type::unknown)
{
Expand Down
48 changes: 25 additions & 23 deletions libs/core/affinity/src/affinity_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -34,20 +34,22 @@ namespace hpx::threads::policies::detail {

affinity_data::affinity_data()
: num_threads_(0)
, pu_offset_(std::size_t(-1))
, pu_offset_(static_cast<std::size_t>(-1))
, pu_step_(1)
, used_cores_(0)
, affinity_domain_("pu")
, affinity_masks_()
, pu_nums_()
, no_affinity_()
, use_process_mask_(false)
, num_pus_needed_(0)
{
threads::resize(
no_affinity_, static_cast<std::size_t>(hardware_concurrency()));
}

affinity_data::affinity_data(affinity_data const&) = default;
affinity_data::affinity_data(affinity_data&&) noexcept = default;
affinity_data& affinity_data::operator=(affinity_data const&) = default;
affinity_data& affinity_data::operator=(affinity_data&&) noexcept = default;

affinity_data::~affinity_data()
{
--instance_number_counter_;
Expand All @@ -64,10 +66,10 @@ namespace hpx::threads::policies::detail {

use_process_mask_ = use_process_mask;
num_threads_ = num_threads;
std::size_t num_system_pus =
std::size_t const num_system_pus =
static_cast<std::size_t>(hardware_concurrency());

if (pu_offset == std::size_t(-1))
if (pu_offset == static_cast<std::size_t>(-1))
{
pu_offset_ = 0;
}
Expand Down Expand Up @@ -107,8 +109,9 @@ namespace hpx::threads::policies::detail {
used_cores, max_cores, num_threads_, pu_nums_,
use_process_mask_);

std::size_t num_initialized = count_initialized(affinity_masks_);
if (num_initialized != num_threads_)
if (std::size_t const num_initialized =
count_initialized(affinity_masks_);
num_initialized != num_threads_)
{
HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
"affinity_data::affinity_data",
Expand All @@ -117,7 +120,7 @@ namespace hpx::threads::policies::detail {
num_threads_, num_initialized);
}
}
else if (pu_offset == std::size_t(-1))
else if (pu_offset == static_cast<std::size_t>(-1))
{
// calculate the pu offset based on the used cores, but only if its
// not explicitly specified
Expand All @@ -139,17 +142,15 @@ namespace hpx::threads::policies::detail {
cores.reserve(num_threads_);
for (std::size_t i = 0; i != num_threads_; ++i)
{
std::size_t add_me = topo.get_core_number(get_pu_num(i));
std::size_t const add_me = topo.get_core_number(get_pu_num(i));
cores.push_back(add_me);
}

std::sort(cores.begin(), cores.end());
std::vector<std::size_t>::iterator it =
std::unique(cores.begin(), cores.end());
auto const it = std::unique(cores.begin(), cores.end());
cores.erase(it, cores.end());

std::size_t num_unique_cores = cores.size();

std::size_t const num_unique_cores = cores.size();
num_pus_needed_ = (std::max)(num_unique_cores, max_cores);
}

Expand All @@ -171,7 +172,7 @@ namespace hpx::threads::policies::detail {
return affinity_masks_[global_thread_num];

// otherwise return mask based on affinity domain
std::size_t pu_num = get_pu_num(global_thread_num);
std::size_t const pu_num = get_pu_num(global_thread_num);
if (0 == std::string("pu").find(affinity_domain_))
{
// The affinity domain is 'processing unit', just convert the
Expand Down Expand Up @@ -202,9 +203,10 @@ namespace hpx::threads::policies::detail {
mask_type affinity_data::get_used_pus_mask(
threads::topology const& topo, std::size_t pu_num) const
{
auto overall_threads = static_cast<std::size_t>(hardware_concurrency());
auto const overall_threads =
static_cast<std::size_t>(hardware_concurrency());

mask_type ret = mask_type();
auto ret = mask_type();
threads::resize(ret, overall_threads);

// --hpx:bind=none disables all affinity
Expand Down Expand Up @@ -260,7 +262,7 @@ namespace hpx::threads::policies::detail {
// means of adding a processing unit after initialization
void affinity_data::add_punit(std::size_t virt_core, std::size_t thread_num)
{
std::size_t num_system_pus =
std::size_t const num_system_pus =
static_cast<std::size_t>(hardware_concurrency());

// initialize affinity_masks and set the mask for the given virt_core
Expand All @@ -273,13 +275,13 @@ namespace hpx::threads::policies::detail {
threads::set(affinity_masks_[virt_core], thread_num);

// find first used pu, which is then stored as the pu_offset
std::size_t first_pu = std::size_t(-1);
std::size_t first_pu = static_cast<std::size_t>(-1);
for (std::size_t i = 0; i != num_threads_; ++i)
{
std::size_t first = threads::find_first(affinity_masks_[i]);
first_pu = (std::min)(first_pu, first);
}
if (first_pu != std::size_t(-1))
if (first_pu != static_cast<std::size_t>(-1))
pu_offset_ = first_pu;

init_cached_pu_nums(num_system_pus);
Expand Down Expand Up @@ -312,13 +314,13 @@ namespace hpx::threads::policies::detail {
//
// The base line processing unit number is computed from the given
// pu-offset and pu-step.
std::size_t num_pu = pu_offset_ + pu_step_ * num_thread;
std::size_t const num_pu = pu_offset_ + pu_step_ * num_thread;

// We add an additional offset, which allows to 'roll over' if the
// pu number would get larger than the number of available
// processing units. Note that it does not make sense to 'roll over'
// farther than the given pu-step.
std::size_t offset = (num_pu / hardware_concurrency) % pu_step_;
std::size_t const offset = (num_pu / hardware_concurrency) % pu_step_;

// The resulting pu number has to be smaller than the available
// number of processing units.
Expand Down
Loading

0 comments on commit ad3ac76

Please sign in to comment.