Skip to content

Commit

Permalink
Adding local work stealing scheduler that is based on message passing…
Browse files Browse the repository at this point in the history
… internally

- Using uniform_int_distribution with proper bounds
- Removing queue index from thread_queues as it was unused
  - flyby: remove commented out options from .clang-format
- Renaming workstealing --> workrequesting
- Adding adaptive work stealing (steal half/steal one)
  - this makes this scheduler consistently (albeit only slightly) faster than
    the (default) local-priority scheduler
- Adding LIFO and FIFO variations of local work-stealing scheduler
  - flyby: fixing HPX_WITH_SWAP_CONTEXT_EMULATION
  - flyby: minor changes to fibonacci_local example
- Adding high- and low- priority queues
  - flyby: cache_line_data now does not generate warnings errors if padding is not needed
  • Loading branch information
hkaiser committed Apr 13, 2022
1 parent 85fdb87 commit b9472b7
Show file tree
Hide file tree
Showing 39 changed files with 2,057 additions and 255 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ jobs:
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DHPX_WITH_DOCUMENTATION=On \
-DHPX_WITH_DOCUMENTATION_OUTPUT_FORMATS="${DOCUMENTATION_OUTPUT_FORMATS}"
-DHPX_WITH_DOCUMENTATION_OUTPUT_FORMATS="${DOCUMENTATION_OUTPUT_FORMATS}" \
-DHPX_WITH_TESTS_COMMAND_LINE=--hpx:queuing=local-workrequesting-fifo
- persist_to_workspace:
root: /hpx
paths:
Expand Down
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2016 Thomas Heller
# Copyright (c) 2016-2018 Hartmut Kaiser
# Copyright (c) 2016-2019 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -105,7 +105,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
Expand Down
6 changes: 3 additions & 3 deletions .jenkins/cscs-perftests/launch_perftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ hpx_targets=(
hpx_test_options=(
"--hpx:ini=hpx.thread_queue.init_threads_count=100 \
--hpx:threads=4 --vector_size=10000 --work_delay=1 \
--chunk_size=0 --test_count=5000"
--chunk_size=0 --test_count=5000 --hpx:queuing=local-workrequesting-fifo"
"--hpx:ini=hpx.thread_queue.init_threads_count=100 \
--hpx:queuing=local-priority --hpx:threads=4 --test-all \
--repetitions=100 --futures=500000"
--repetitions=100 --futures=500000 --hpx:queuing=local-workrequesting-fifo"
"--hpx:ini=hpx.thread_queue.init_threads_count=100 \
--vector_size=1048576 --hpx:threads=4 --iterations=5000 \
--warmup_iterations=500")
--warmup_iterations=500 --hpx:queuing=local-workrequesting-fifo")

# Build binaries for performance tests
${perftests_dir}/driver.py -v -l $logfile build -b release -o build \
Expand Down
3 changes: 2 additions & 1 deletion .jenkins/lsu/env-clang-13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON"
configure_extra_options+=" -DHPX_WITH_PARCELPORT_MPI=ON"
configure_extra_options+=" -DHPX_WITH_PARCELPORT_LCI=ON"
configure_extra_options+=" -DHPX_WITH_FETCH_LCI=ON"
configure_extra_options+=" -DLCI_SERVER=ibv"
configure_extra_options+=" -DHPX_WITH_LOGGING=OFF"
configure_extra_options+=" -DHPX_WITH_TESTS_COMMAND_LINE=--hpx:queuing=local-workrequesting-fifo"
configure_extra_options+=" -DLCI_SERVER=ibv"

# Make sure HWLOC does not report 'cores'. This is purely an option to enable
# testing the topology code under conditions close to those on FreeBSD.
Expand Down
2 changes: 2 additions & 0 deletions .jenkins/lsu/env-gcc-11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module load openmpi
export HPXRUN_RUNWRAPPER=srun
export CXX_STD="20"

configure_extra_options+=" -DCMAKE_BUILD_TYPE=${build_type}"
configure_extra_options+=" -DHPX_WITH_CXX_STANDARD=${CXX_STD}"
configure_extra_options+=" -DHPX_WITH_MALLOC=system"
configure_extra_options+=" -DHPX_WITH_FETCH_ASIO=ON"
Expand All @@ -22,4 +23,5 @@ configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON"
configure_extra_options+=" -DHPX_WITH_PARCELPORT_MPI=ON"
configure_extra_options+=" -DHPX_WITH_PARCELPORT_LCI=ON"
configure_extra_options+=" -DHPX_WITH_FETCH_LCI=ON"
configure_extra_options+=" -DHPX_WITH_TESTS_COMMAND_LINE=--hpx:queuing=local-workrequesting-fifo"
configure_extra_options+=" -DLCI_SERVER=ibv"
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,13 @@ hpx_option(
ADVANCED
)

hpx_option(
HPX_WITH_TESTS_COMMAND_LINE STRING
"Add given command line options to all tests run" ""
CATEGORY "Debugging"
ADVANCED
)

hpx_option(
HPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY
STRING
Expand Down
5 changes: 5 additions & 0 deletions cmake/HPX_AddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function(add_hpx_test category name)
)
endif()

# add additional command line arguments to all test executions
if(NOT x${HPX_WITH_TESTS_COMMAND_LINE} STREQUAL x"")
set(args ${args} "${HPX_WITH_TESTS_COMMAND_LINE}")
endif()

if(${HPX_WITH_PARALLEL_TESTS_BIND_NONE}
AND NOT run_serial
AND NOT "${name}_RUNWRAPPER"
Expand Down
25 changes: 15 additions & 10 deletions examples/quickstart/fibonacci_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include <cstdint>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
//[fibonacci
Expand All @@ -26,22 +29,20 @@ std::uint64_t fibonacci(std::uint64_t n)
if (n < 2)
return n;

// Invoking the Fibonacci algorithm twice is inefficient.
// However, we intentionally demonstrate it this way to create some
// heavy workload.

hpx::future<std::uint64_t> n1 = hpx::async(fibonacci, n - 1);
hpx::future<std::uint64_t> n2 = hpx::async(fibonacci, n - 2);
std::uint64_t n2 = fibonacci(n - 2);

return n1.get() +
n2.get(); // wait for the Futures to return their values
return n1.get() + n2; // wait for the Future to return their values
}
//fibonacci]

///////////////////////////////////////////////////////////////////////////////
//[hpx_main
int hpx_main(hpx::program_options::variables_map& vm)
{
hpx::threads::add_scheduler_mode(
hpx::threads::policies::scheduler_mode::fast_idle_mode);

// extract command line argument, i.e. fib(N)
std::uint64_t n = vm["n-value"].as<std::uint64_t>();

Expand All @@ -67,9 +68,13 @@ int main(int argc, char* argv[])
hpx::program_options::options_description desc_commandline(
"Usage: " HPX_APPLICATION_STRING " [options]");

desc_commandline.add_options()("n-value",
hpx::program_options::value<std::uint64_t>()->default_value(10),
"n value for the Fibonacci function");
// clang-format off
desc_commandline.add_options()
("n-value",
hpx::program_options::value<std::uint64_t>()->default_value(10),
"n value for the Fibonacci function")
;
// clang-format on

// Initialize and run HPX
hpx::local::init_params init_args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ namespace hpx { namespace local { namespace detail {
("hpx:queuing", value<std::string>(),
"the queue scheduling policy to use, options are "
"'local', 'local-priority-fifo','local-priority-lifo', "
"'local-workrequesting-fifo', 'local-workrequesting-lifo' "
"'abp-priority-fifo', 'abp-priority-lifo', 'static', and "
"'static-priority' (default: 'local-priority'; "
"all option values can be abbreviated)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace hpx { namespace concurrency { namespace detail {
{
if (expected_range.empty())
{
return hpx::nullopt;
return hpx::optional<T>(hpx::nullopt);
}

index = expected_range.first;
Expand All @@ -166,7 +166,7 @@ namespace hpx { namespace concurrency { namespace detail {
{
if (expected_range.empty())
{
return hpx::nullopt;
return hpx::optional<T>(hpx::nullopt);
}

desired_range = expected_range.decrement_last();
Expand Down
23 changes: 16 additions & 7 deletions libs/core/concurrency/include/hpx/concurrency/spinlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include <hpx/modules/itt_notify.hpp>
#include <hpx/thread_support/spinlock.hpp>

#include <utility>

namespace hpx { namespace util {

/// Lockable spinlock class
// Lockable spinlock class
struct spinlock
{
public:
Expand All @@ -25,25 +27,32 @@ namespace hpx { namespace util {
hpx::util::detail::spinlock m;

public:
spinlock(char const* /*desc*/ = nullptr)
spinlock() noexcept
{
HPX_ITT_SYNC_CREATE(this, "util::spinlock", "");
HPX_ITT_SYNC_CREATE(this, "util::spinlock", nullptr);
}

explicit spinlock(char const* desc) noexcept
{
HPX_ITT_SYNC_CREATE(this, "util::spinlock", desc);
}

~spinlock()
{
HPX_ITT_SYNC_DESTROY(this);
}

void lock() noexcept
void lock() noexcept(
noexcept(util::register_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_PREPARE(this);
m.lock();
HPX_ITT_SYNC_ACQUIRED(this);
util::register_lock(this);
}

bool try_lock() noexcept
bool try_lock() noexcept(
noexcept(util::register_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_PREPARE(this);
if (m.try_lock())
Expand All @@ -56,13 +65,13 @@ namespace hpx { namespace util {
return false;
}

void unlock() noexcept
void unlock() noexcept(
noexcept(util::unregister_lock(std::declval<spinlock*>())))
{
HPX_ITT_SYNC_RELEASING(this);
m.unlock();
HPX_ITT_SYNC_RELEASED(this);
util::unregister_lock(this);
}
};

}} // namespace hpx::util
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ namespace hpx { namespace resource {
abp_priority_fifo = 5,
abp_priority_lifo = 6,
shared_priority = 7,
local_workrequesting_fifo = 8,
local_workrequesting_lifo = 9,
};
}} // namespace hpx::resource
18 changes: 18 additions & 0 deletions libs/core/resource_partitioner/src/detail_partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ namespace hpx { namespace resource { namespace detail {
case resource::local_priority_lifo:
sched = "local_priority_lifo";
break;
case resource::local_workrequesting_fifo:
sched = "local_workrequesting_fifo";
break;
case resource::local_workrequesting_lifo:
sched = "local_workrequesting_lifo";
break;
case resource::static_:
sched = "static";
break;
Expand Down Expand Up @@ -451,6 +457,18 @@ namespace hpx { namespace resource { namespace detail {
{
default_scheduler = scheduling_policy::local_priority_lifo;
}
else if (0 ==
std::string("local-workrequesting-fifo")
.find(default_scheduler_str))
{
default_scheduler = scheduling_policy::local_workrequesting_fifo;
}
else if (0 ==
std::string("local-workrequesting-lifo")
.find(default_scheduler_str))
{
default_scheduler = scheduling_policy::local_workrequesting_lifo;
}
else if (0 == std::string("static").find(default_scheduler_str))
{
default_scheduler = scheduling_policy::static_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace hpx { namespace util {
"localities = 1",
"first_pu = 0",
"runtime_mode = console",
"scheduler = local-priority-fifo",
"scheduler = local-workrequesting-fifo",
"affinity = core",
"pu_step = 1",
"pu_offset = 0",
Expand Down
4 changes: 4 additions & 0 deletions libs/core/schedulers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(schedulers_headers
hpx/schedulers/deadlock_detection.hpp
hpx/schedulers/local_priority_queue_scheduler.hpp
hpx/schedulers/local_queue_scheduler.hpp
hpx/schedulers/local_workrequesting_scheduler.hpp
hpx/schedulers/lockfree_queue_backends.hpp
hpx/schedulers/maintain_queue_wait_times.hpp
hpx/schedulers/queue_helpers.hpp
Expand Down Expand Up @@ -51,12 +52,15 @@ add_hpx_module(
COMPAT_HEADERS ${schedulers_compat_headers}
SOURCES ${schedulers_sources}
MODULE_DEPENDENCIES
hpx_affinity
hpx_concurrency
hpx_config
hpx_assertion
hpx_errors
hpx_format
hpx_functional
hpx_logging
hpx_synchronization
hpx_threading_base
CMAKE_SUBDIRS examples tests
)
5 changes: 2 additions & 3 deletions libs/core/schedulers/include/hpx/modules/schedulers.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) 2007-2013 Hartmut Kaiser
// Copyright (c) 2007-2022 Hartmut Kaiser
//
// 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)

#pragma once

#include <hpx/config.hpp>

#include <hpx/schedulers/local_priority_queue_scheduler.hpp>
#include <hpx/schedulers/local_queue_scheduler.hpp>
#include <hpx/schedulers/local_workrequesting_scheduler.hpp>
#include <hpx/schedulers/shared_priority_queue_scheduler.hpp>
#include <hpx/schedulers/static_priority_queue_scheduler.hpp>
#include <hpx/schedulers/static_queue_scheduler.hpp>
Loading

0 comments on commit b9472b7

Please sign in to comment.