Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ The primary use of <code>affine</code> is implementing scheduler affinity for <c
<details>
<summary><code>bulk(<i>sndr</i>, <i>policy</i>, <i>shape</i>, <i>fun</i>) -&gt; <i>sender</i></code></summary>
<a id='bulk'></a>
The algorithm <code>bulk</code> is used to execute <code>fun</code>
</details>
<details>
Expand Down Expand Up @@ -952,6 +953,33 @@ Note that `write_env` affects the sender passed as first argument or, when using
<a id='spawn'></a>
</details>

## Schedulers

- `inline_scheduler`
- `parallel_scheduler`

<details>
<summary><code>parallel_scheduler_replacement::parallel_scheduler_backend</code></summary>
The class <code>parallel_scheduler_replacement::parallel_scheduler_backend</code> defines an
abstract interface to a <code>parallel_scheduler</code>. It has the following members:

<dl>
<dt><code>virtual ~parallel_scheduler_backend() = default</code></dt>
<dd>A <code>virtual</code> destructor</dd>
<dt><code>virtual void schedule(<a href="#receiver_proxy">receiver_proxy</a>&amp; <i>rcvr</i>, span&lt;byte&gt;) noexcept = 0</code></dt>
<dd>A pure <code>virtual</code> member function used to call <code><i>rcvr</i>.set_value()</code> on the corresponding execution and
<code><i>rcvr</i>.set_error(<i>ex_ptr</i>)</code> upon error or <code><i>rcvr</i>.set_stopped()</code> upon cancellation of the operation.</dd>
<dt><code>virtual void schedule_bulk_chunked(size_t, <a href="#bulk_item_receiver_proxy">bulk_item_receiver_proxy</a>&amp;,
span&lt;byte&gt;) noexcept = 0</code></dt>
<dd>A pure <code>virtual</code> member function TODO</dd>
<dt><code>virtual void schedule_bulk_unchunked(size_t, <a href="#bulk_item_receiver_proxy">bulk_item_receiver_proxy</a>&amp;,
span&lt;byte&gt;) noexcept = 0</code></dt>
<dd>A pure <code>virtual</code> member function TODO</dd>
</dl>
</details>

- `task_scheduler`

## Helpers

- `apply_sender`
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(TODO suspend_never) #-dk:TODO including that causes ASAN errors

set(EXAMPLES
allocator
bulk
doc_just
doc_just_error
doc_just_stopped
Expand Down
66 changes: 66 additions & 0 deletions examples/bulk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// examples/bulk.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/detail/common.hpp>
#ifdef BEMAN_HAS_IMPORT_STD
import std;
#else
#include <iostream>
#include <string_view>
#endif
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution.hpp>
#endif

using namespace std::string_view_literals;
namespace ex = beman::execution;

// ----------------------------------------------------------------------------

namespace {
struct backend : ex::parallel_scheduler_replacement::parallel_scheduler_backend {
using receiver_proxy = ex::parallel_scheduler_replacement::receiver_proxy;
using bulk_item_receiver_proxy = ex::parallel_scheduler_replacement::bulk_item_receiver_proxy;

~backend() override = default;

auto schedule(receiver_proxy& rcvr, ::std::span<::std::byte>) noexcept -> void override { rcvr.set_value(); }
auto schedule_bulk_chunked(::std::size_t shape, bulk_item_receiver_proxy& rcvr, ::std::span<::std::byte>) noexcept
-> void override {
rcvr.execute(0, shape);
rcvr.set_value();
}
auto schedule_bulk_unchunked(::std::size_t shape,
bulk_item_receiver_proxy& rcvr,
::std::span<::std::byte>) noexcept -> void override {
for (std::size_t i{}; i != shape; ++i)
rcvr.execute(i, i + 1u);
rcvr.set_value();
}
};
} // namespace

namespace beman::execution::parallel_scheduler_replacement {
auto query_parallel_scheduler_backend()
-> ::std::shared_ptr<::beman::execution::parallel_scheduler_replacement::parallel_scheduler_backend> {
static auto rc = ::std::make_shared<backend>();
return rc;
}
} // namespace beman::execution::parallel_scheduler_replacement

// ----------------------------------------------------------------------------

int main() {
ex::sync_wait(ex::starts_on(ex::get_parallel_scheduler(), ex::just("arg"sv, 2, 3)) |
ex::bulk(ex::par, 10, [](auto... values) { ((std::cout << values << " "), ...) << "\n"; }) |
ex::then([](auto&&... values) { ((std::cout << values << " "), ...) << ": done\n"; }));
ex::sync_wait(ex::starts_on(ex::get_parallel_scheduler(), ex::just("arg"sv, 2, 3)) |
ex::bulk_chunked(ex::par, 10, [](auto... values) { ((std::cout << values << " "), ...) << "\n"; }) |
ex::then([](auto&&... values) { ((std::cout << values << " "), ...) << ": done\n"; }));
ex::sync_wait(
ex::starts_on(ex::get_parallel_scheduler(), ex::just("arg"sv, 2, 3)) |
ex::bulk_unchunked(ex::par, 10, [](auto... values) { ((std::cout << values << " "), ...) << "\n"; }) |
ex::then([](auto&&... values) { ((std::cout << values << " "), ...) << ": done\n"; }));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_DEFAULT_PARALLEL_SCHEDULER_BACKEND
#define INCLUDED_BEMAN_EXECUTION_DETAIL_DEFAULT_PARALLEL_SCHEDULER_BACKEND
#if BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND

#include <beman/execution/detail/common.hpp>
#ifdef BEMAN_HAS_IMPORT_STD
Expand All @@ -22,13 +21,9 @@ import beman.execution.detail.thread_pool_backend;
// ----------------------------------------------------------------------------

namespace beman::execution::parallel_scheduler_replacement {
inline auto query_parallel_scheduler_backend() -> ::std::shared_ptr<parallel_scheduler_backend> {
static auto backend = ::std::make_shared<::beman::execution::detail::thread_pool_backend>();
return backend;
}
auto query_parallel_scheduler_backend() -> ::std::shared_ptr<parallel_scheduler_backend>;
} // namespace beman::execution::parallel_scheduler_replacement

// ----------------------------------------------------------------------------

#endif // BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND
#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_DEFAULT_PARALLEL_SCHEDULER_BACKEND
1 change: 1 addition & 0 deletions include/beman/execution/detail/parallel_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import beman.execution.detail.stop_token_of_t;
#include <beman/execution/detail/stop_token_of_t.hpp>
#include <beman/execution/detail/tag_of_t.hpp>
#endif
#include <beman/execution/detail/default_parallel_scheduler_backend.hpp> // note: unconditional!

// ----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ struct parallel_scheduler_backend {
-> void = 0;
};

auto query_parallel_scheduler_backend() -> ::std::shared_ptr<parallel_scheduler_backend>;

} // namespace beman::execution::parallel_scheduler_replacement
Comment on lines 68 to 70

// ----------------------------------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion src/beman/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# gersemi: on

add_library(${BEMAN_EXECUTION_TARGET_NAME} INTERFACE)
add_library(${BEMAN_EXECUTION_TARGET_NAME})
add_library(beman::execution_headers ALIAS ${BEMAN_EXECUTION_TARGET_NAME})
target_compile_features(
${BEMAN_EXECUTION_TARGET_NAME}
PUBLIC cxx_std_${CMAKE_CXX_STANDARD}
)
find_package(Threads REQUIRED)
target_link_libraries(${BEMAN_EXECUTION_TARGET_NAME} PUBLIC Threads::Threads)

target_sources(
${BEMAN_EXECUTION_TARGET_NAME}
Expand Down Expand Up @@ -249,6 +255,13 @@ target_sources(
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/write_env.hpp
)

if(BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND)
target_sources(
${BEMAN_EXECUTION_TARGET_NAME}
PRIVATE default_parallel_scheduler_backend.cpp
)
endif()

target_compile_definitions(
${BEMAN_EXECUTION_TARGET_NAME}
INTERFACE
Expand Down
15 changes: 15 additions & 0 deletions src/beman/execution/default_parallel_scheduler_backend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// src/beman/execution/default_parallel_scheduler_backend.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/detail/default_parallel_scheduler_backend.hpp>
#include <iostream>

// ----------------------------------------------------------------------------

#if BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND
auto ::beman::execution::parallel_scheduler_replacement::query_parallel_scheduler_backend()
-> ::std::shared_ptr<::beman::execution::parallel_scheduler_replacement::parallel_scheduler_backend> {
static auto backend = ::std::make_shared<::beman::execution::detail::thread_pool_backend>();
return backend;
}
#endif // BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND
1 change: 0 additions & 1 deletion src/beman/execution/execution.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ namespace parallel_scheduler_replacement {
export using ::beman::execution::parallel_scheduler_replacement::receiver_proxy;
export using ::beman::execution::parallel_scheduler_replacement::bulk_item_receiver_proxy;
export using ::beman::execution::parallel_scheduler_replacement::parallel_scheduler_backend;
export using ::beman::execution::parallel_scheduler_replacement::query_parallel_scheduler_backend;
} // namespace parallel_scheduler_replacement

// [exec.consumers], consumers
Expand Down
1 change: 0 additions & 1 deletion src/beman/execution/parallel_scheduler_replacement.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ namespace beman::execution::parallel_scheduler_replacement {
export using beman::execution::parallel_scheduler_replacement::receiver_proxy;
export using beman::execution::parallel_scheduler_replacement::bulk_item_receiver_proxy;
export using beman::execution::parallel_scheduler_replacement::parallel_scheduler_backend;
export using beman::execution::parallel_scheduler_replacement::query_parallel_scheduler_backend;
} // namespace beman::execution::parallel_scheduler_replacement
1 change: 1 addition & 0 deletions tests/beman/execution/exec-parallel-scheduler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import beman.execution.detail.thread_pool_backend;
#include <beman/execution.hpp>
#include <beman/execution/detail/thread_pool_backend.hpp>
#endif
#include <beman/execution/detail/default_parallel_scheduler_backend.hpp> // note: unconditional!

namespace {
namespace replaceability = test_std::parallel_scheduler_replacement;
Expand Down