Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::async::SubTaskGraph Class Reference

Dynamic task graph that can be created within the execution of a task. More...

#include <sub_task_graph.hpp>

Public Member Functions

 SubTaskGraph (const SubTaskGraph &)=delete
 
 SubTaskGraph (SubTaskGraph &&)=default
 
 ~SubTaskGraph ()=default
 
SubTaskGraphoperator= (const SubTaskGraph &)=delete
 
SubTaskGraphoperator= (SubTaskGraph &&)=delete
 
void Join ()
 Joins the subflow with its parent task.
 
void Retain (bool flag) noexcept
 Specifies whether to keep the sub task graph after it is joined.
 
template<StaticTask C>
Task EmplaceTask (C &&callable)
 Creates a static task with the given callable.
 
template<SubTask C>
Task EmplaceTask (C &&callable)
 Creates a dynamic task (nested subflow) with the given callable.
 
template<AnyTask... Cs>
requires (sizeof...(Cs) > 1)
auto EmplaceTasks (Cs &&... callables) -> std::array< Task, sizeof...(Cs)>
 Creates multiple tasks from a list of callables.
 
Task CreatePlaceholder ()
 Creates a placeholder task with no assigned work.
 
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
void Linearize (const R &tasks)
 Creates linear dependencies between tasks in the given range.
 
template<std::ranges::range R, std::invocable< std::ranges::range_reference_t< R > > C>
Task ForEach (const R &range, C &&callable)
 Creates a parallel for-each task over the given range.
 
template<std::integral I, std::invocable< I > C>
Task ForEachIndex (I start, I end, I step, C &&callable)
 Creates a parallel for-each task over an index range.
 
template<std::ranges::range InputRange, std::ranges::range OutputRange, std::invocable< std::ranges::range_reference_t< InputRange > > TransformFunc>
Task Transform (const InputRange &input_range, OutputRange &output_range, TransformFunc &&transform_func)
 Creates a parallel transform task that applies a function to each element.
 
template<std::ranges::range R, typename T , typename BinaryOp >
requires std::invocable<BinaryOp, T, std::ranges::range_reference_t<R>>
Task Reduce (const R &range, T &init, BinaryOp &&binary_op)
 Creates a parallel reduction task that combines elements using a binary operation.
 
template<std::ranges::random_access_range R, typename Compare = std::less<>>
requires std::predicate<Compare, std::ranges::range_reference_t<R>, std::ranges::range_reference_t<R>>
Task Sort (R &range, Compare &&comparator=Compare())
 Creates a parallel sort task for the given range.
 
void RemoveTask (const Task &task)
 Removes a task from this subflow.
 
template<typename T >
Task ComposedOf (T &other_graph)
 Creates a module task that encapsulates another task graph.
 
bool Joinable () const noexcept
 Checks if this subflow can be joined.
 
bool WillBeRetained () const noexcept
 Checks if this subflow will be retained.
 
auto Run (TaskGraph &graph) -> Future< void >
 Runs a task graph once.
 
auto Run (TaskGraph &&graph) -> Future< void >
 Runs a task graph once.
 
template<std::invocable C>
auto Run (TaskGraph &graph, C &&callable) -> Future< void >
 Runs a task graph once and invokes a callback upon completion.
 
template<std::invocable C>
auto Run (TaskGraph &&graph, C &&callable) -> Future< void >
 Runs a moved task graph once and invokes a callback upon completion.
 
auto RunN (TaskGraph &graph, size_t count) -> Future< void >
 Runs a task graph for the specified number of times.
 
auto RunN (TaskGraph &&graph, size_t count) -> Future< void >
 Runs a moved task graph for the specified number of times.
 
template<std::invocable C>
auto RunN (TaskGraph &graph, size_t count, C &&callable) -> Future< void >
 Runs a task graph for the specified number of times and invokes a callback.
 
template<std::invocable C>
auto RunN (TaskGraph &&graph, size_t count, C &&callable) -> Future< void >
 Runs a moved task graph for the specified number of times and invokes a callback.
 
template<std::predicate Predicate>
auto RunUntil (TaskGraph &graph, Predicate &&predicate) -> Future< void >
 Runs a task graph repeatedly until the predicate returns true.
 
template<std::predicate Predicate>
auto RunUntil (TaskGraph &&graph, Predicate &&predicate) -> Future< void >
 Runs a moved task graph repeatedly until the predicate returns true.
 
template<std::predicate Predicate, std::invocable C>
auto RunUntil (TaskGraph &graph, Predicate &&predicate, C &&callable) -> Future< void >
 Runs a task graph repeatedly until the predicate returns true, then invokes a callback.
 
template<std::predicate Predicate, std::invocable C>
auto RunUntil (TaskGraph &&graph, Predicate &&predicate, C &&callable) -> Future< void >
 Runs a moved task graph repeatedly until the predicate returns true, then invokes a callback.
 
template<std::invocable C>
auto Async (C &&callable) -> std::future< std::invoke_result_t< C > >
 Creates an asynchronous task that runs the given callable.
 
template<std::invocable C>
auto Async (std::string name, C &&callable) -> std::future< std::invoke_result_t< C > >
 Creates a named asynchronous task that runs the given callable.
 
template<std::invocable C>
void SilentAsync (C &&callable)
 Creates an asynchronous task without returning a future.
 
template<std::invocable C>
void SilentAsync (std::string name, C &&callable)
 Creates a named asynchronous task without returning a future.
 
template<std::invocable C, std::ranges::range Dependencies>
requires std::same_as<std::ranges::range_value_t<Dependencies>, AsyncTask>
auto DependentAsync (C &&callable, const Dependencies &dependencies) -> std::pair< AsyncTask, std::future< std::invoke_result_t< C > > >
 Creates an asynchronous task that runs after specified dependencies complete.
 
template<std::invocable C, std::ranges::range Dependencies>
requires std::same_as<std::ranges::range_value_t<Dependencies>, AsyncTask>
AsyncTask SilentDependentAsync (C &&callable, const Dependencies &dependencies)
 Creates an asynchronous task that runs after dependencies complete, without returning a future.
 
void WaitForAll ()
 Blocks until all submitted tasks complete.
 
void CoRun (TaskGraph &graph)
 Runs a task graph cooperatively and waits until it completes using the current worker thread.
 
template<std::predicate Predicate>
void CoRunUntil (Predicate &&predicate)
 Keeps the current worker thread running until the predicate returns true.
 
bool IsWorkerThread () const
 Checks if the current thread is a worker thread of this executor.
 
int CurrentWorkerId () const
 Gets the ID of the current worker thread.
 
size_t WorkerCount () const noexcept
 Gets the total number of worker threads.
 
size_t IdleWorkerCount () const noexcept
 Gets the number of worker threads currently waiting for work.
 
size_t QueueCount () const noexcept
 Gets the number of task queues in the work-stealing scheduler.
 
size_t RunningTopologyCount () const
 Gets the number of task graphs currently being executed.
 

Friends

class TaskGraph
 
class Executor
 

Detailed Description

Dynamic task graph that can be created within the execution of a task.

Wraps tf::Subflow and provides methods to create tasks dynamically at runtime. SubTaskGraphs are spawned from the execution of a SubTask and allow for runtime-dependent task creation and dependency management.

Note
Partially thread-safe.
Warning
Only the worker thread that spawned the subflow should modify it.

Definition at line 41 of file sub_task_graph.hpp.

Constructor & Destructor Documentation

◆ SubTaskGraph() [1/2]

helios::async::SubTaskGraph::SubTaskGraph ( const SubTaskGraph )
delete

◆ SubTaskGraph() [2/2]

helios::async::SubTaskGraph::SubTaskGraph ( SubTaskGraph &&  )
default

◆ ~SubTaskGraph()

helios::async::SubTaskGraph::~SubTaskGraph ( )
default

Member Function Documentation

◆ Async() [1/2]

template<std::invocable C>
auto helios::async::SubTaskGraph::Async ( C &&  callable) -> std::future<std::invoke_result_t<C>>
inline

Creates an asynchronous task that runs the given callable.

The task is scheduled immediately and runs independently.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
callableFunction to execute asynchronously
Returns
Future that will hold the result of the execution

Definition at line 403 of file sub_task_graph.hpp.

403 {
404 return subflow_.executor().async(std::forward<C>(callable));
405 }

◆ Async() [2/2]

template<std::invocable C>
auto helios::async::SubTaskGraph::Async ( std::string  name,
C &&  callable 
) -> std::future<std::invoke_result_t<C>>
inline

Creates a named asynchronous task that runs the given callable.

The task is scheduled immediately and runs independently.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
nameName for the task (useful for debugging/profiling)
callableFunction to execute asynchronously
Returns
Future that will hold the result of the execution

Definition at line 417 of file sub_task_graph.hpp.

417 {
418 return subflow_.executor().async(std::move(name), std::forward<C>(callable));
419 }

◆ ComposedOf()

template<typename T >
Task helios::async::SubTaskGraph::ComposedOf ( T &  other_graph)
inline

Creates a module task that encapsulates another task graph.

Note
Not thread-safe
Parameters
other_graphTask graph to compose into this subflow
Returns
Task handle representing the composed graph

Definition at line 211 of file sub_task_graph.hpp.

211 {
212 return Task(subflow_.composed_of(other_graph.UnderlyingTaskflow()));
213 }

◆ CoRun()

void helios::async::SubTaskGraph::CoRun ( TaskGraph graph)
inline

Runs a task graph cooperatively and waits until it completes using the current worker thread.

Warning
Must be called from within a worker thread of this executor. Triggers assertion if called from a non-worker thread.
Parameters
graphTask graph to execute

Definition at line 626 of file sub_task_graph.hpp.

626 {
627 HELIOS_ASSERT(IsWorkerThread(), "Failed to co-run: Must be called from a worker thread");
628 subflow_.executor().corun(graph.UnderlyingTaskflow());
629}
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:140
bool IsWorkerThread() const
Checks if the current thread is a worker thread of this executor.

◆ CoRunUntil()

template<std::predicate Predicate>
void helios::async::SubTaskGraph::CoRunUntil ( Predicate &&  predicate)
inline

Keeps the current worker thread running until the predicate returns true.

Warning
Must be called from within a worker thread of this executor. Triggers assertion if called from a non-worker thread.
Template Parameters
PredicatePredicate type
Parameters
predicateBoolean predicate to determine when to stop

Definition at line 632 of file sub_task_graph.hpp.

632 {
633 HELIOS_ASSERT(IsWorkerThread(), "Failed to co-run until: Must be called from a worker thread");
634 subflow_.executor().corun_until(std::forward<Predicate>(predicate));
635}

◆ CreatePlaceholder()

Task helios::async::SubTaskGraph::CreatePlaceholder ( )
inline

Creates a placeholder task with no assigned work.

Note
Not thread-safe
Returns
Task handle that can later be assigned work

Definition at line 106 of file sub_task_graph.hpp.

106{ return Task(subflow_.placeholder()); }

◆ CurrentWorkerId()

int helios::async::SubTaskGraph::CurrentWorkerId ( ) const
inline

Gets the ID of the current worker thread.

Note
Thread-safe.
Returns
Worker ID (0 to N-1) or -1 if not a worker thread

Definition at line 512 of file sub_task_graph.hpp.

512{ return subflow_.executor().this_worker_id(); }

◆ DependentAsync()

template<std::invocable C, std::ranges::range Dependencies>
requires std::same_as<std::ranges::range_value_t<Dependencies>, AsyncTask>
auto helios::async::SubTaskGraph::DependentAsync ( C &&  callable,
const Dependencies &  dependencies 
) -> std::pair<AsyncTask, std::future<std::invoke_result_t<C>>>
inline

Creates an asynchronous task that runs after specified dependencies complete.

The task will only execute after all dependencies finish.

Note
Thread-safe.
Template Parameters
CCallable type
DependenciesRange type containing AsyncTask dependencies
Parameters
callableFunction to execute asynchronously
dependenciesTasks that must complete before this task runs
Returns
Pair containing AsyncTask handle and Future for the result

Definition at line 587 of file sub_task_graph.hpp.

588 {
589 std::vector<tf::AsyncTask> tf_deps;
590 if constexpr (std::ranges::sized_range<Dependencies>) {
591 tf_deps.reserve(std::ranges::size(dependencies));
592 }
593
594 for (const auto& dep : dependencies) {
595 tf_deps.push_back(dep.UnderlyingTask());
596 }
597
598 auto [task, future] = subflow_.executor().dependent_async(std::forward<C>(callable), tf_deps.begin(), tf_deps.end());
599 return std::make_pair(AsyncTask(std::move(task)), std::move(future));
600}

◆ EmplaceTask() [1/2]

template<SubTask C>
Task helios::async::SubTaskGraph::EmplaceTask ( C &&  callable)
inline

Creates a static task with the given callable.

Note
Not thread-safe
Template Parameters
CCallable type
Parameters
callableFunction to execute when the task runs
Returns
Task handle for the created task

Definition at line 74 of file sub_task_graph.hpp.

74 {
75 return Task(subflow_.emplace(std::forward<C>(callable)));
76 }

◆ EmplaceTask() [2/2]

template<SubTask C>
Task helios::async::SubTaskGraph::EmplaceTask ( C &&  callable)

Creates a dynamic task (nested subflow) with the given callable.

Note
Not thread-safe
Template Parameters
CCallable type that accepts a SubTaskGraph reference
Parameters
callableFunction to execute when the task runs
Returns
Task handle for the created task

◆ EmplaceTasks()

template<AnyTask... Cs>
requires (sizeof...(Cs) > 1)
auto helios::async::SubTaskGraph::EmplaceTasks ( Cs &&...  callables) -> std::array<Task, sizeof...(Cs)>
inline

Creates multiple tasks from a list of callables.

Note
Not thread-safe
Template Parameters
CsCallable types
Parameters
callablesFunctions to execute when the tasks run
Returns
Array of task handles for the created tasks

Definition at line 97 of file sub_task_graph.hpp.

97 {
98 return {EmplaceTask(std::forward<Cs>(callables))...};
99 }
Task EmplaceTask(C &&callable)
Creates a static task with the given callable.

◆ ForEach()

template<std::ranges::range R, std::invocable< std::ranges::range_reference_t< R > > C>
Task helios::async::SubTaskGraph::ForEach ( const R &  range,
C &&  callable 
)
inline

Creates a parallel for-each task over the given range.

Note
Not thread-safe
Template Parameters
RRange type
CCallable type
Parameters
rangeInput range to iterate over
callableFunction to apply to each element
Returns
Task handle for the parallel operation

Definition at line 128 of file sub_task_graph.hpp.

128 {
129 return Task(subflow_.for_each(std::ranges::begin(range), std::ranges::end(range), std::forward<C>(callable)));
130 }

◆ ForEachIndex()

template<std::integral I, std::invocable< I > C>
Task helios::async::SubTaskGraph::ForEachIndex ( start,
end,
step,
C &&  callable 
)
inline

Creates a parallel for-each task over an index range.

Note
Not thread-safe
Template Parameters
IIntegral type
CCallable type
Parameters
startStarting index (inclusive)
endEnding index (exclusive)
stepStep size
callableFunction to apply to each index
Returns
Task handle for the parallel operation

Definition at line 144 of file sub_task_graph.hpp.

144 {
145 return Task(subflow_.for_each_index(start, end, step, std::forward<C>(callable)));
146 }

◆ IdleWorkerCount()

size_t helios::async::SubTaskGraph::IdleWorkerCount ( ) const
inlinenoexcept

Gets the number of worker threads currently waiting for work.

Note
Thread safe.
Returns
Count of idle workers.

Definition at line 526 of file sub_task_graph.hpp.

526{ return subflow_.executor().num_waiters(); }

◆ IsWorkerThread()

bool helios::async::SubTaskGraph::IsWorkerThread ( ) const
inline

Checks if the current thread is a worker thread of this executor.

Note
Thread safe.
Returns
True if current thread is a worker, false otherwise

Definition at line 505 of file sub_task_graph.hpp.

505{ return CurrentWorkerId() != -1; }
int CurrentWorkerId() const
Gets the ID of the current worker thread.

◆ Join()

void helios::async::SubTaskGraph::Join ( )
inline

Joins the subflow with its parent task.

Called automatically when the SubTaskGraph goes out of scope, unless Join() has already been called.

Warning
Must be called by the same worker thread that created this subflow.

Definition at line 55 of file sub_task_graph.hpp.

55{ subflow_.join(); }

◆ Joinable()

bool helios::async::SubTaskGraph::Joinable ( ) const
inlinenoexcept

Checks if this subflow can be joined.

A subflow is joinable if it has not yet been joined with its parent task.

Returns
True if the subflow is joinable, false otherwise

Definition at line 220 of file sub_task_graph.hpp.

220{ return subflow_.joinable(); }

◆ Linearize()

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, Task>
void helios::async::SubTaskGraph::Linearize ( const R &  tasks)
inline

Creates linear dependencies between tasks in the given range.

Note
Not thread-safe
Template Parameters
RRange type containing Task objects
Parameters
tasksRange of tasks to linearize (first->second->third->...)

Definition at line 564 of file sub_task_graph.hpp.

564 {
565 std::vector<tf::Task> tf_tasks;
566 tf_tasks.reserve(std::ranges::size(tasks));
567
568 for (const auto& task : tasks) {
569 tf_tasks.push_back(task.UnderlyingTask());
570 }
571
572 subflow_.linearize(tf_tasks);
573}

◆ operator=() [1/2]

SubTaskGraph & helios::async::SubTaskGraph::operator= ( const SubTaskGraph )
delete

◆ operator=() [2/2]

SubTaskGraph & helios::async::SubTaskGraph::operator= ( SubTaskGraph &&  )
delete

◆ QueueCount()

size_t helios::async::SubTaskGraph::QueueCount ( ) const
inlinenoexcept

Gets the number of task queues in the work-stealing scheduler.

Note
Thread safe.
Returns
Count of queues.

Definition at line 533 of file sub_task_graph.hpp.

533{ return subflow_.executor().num_queues(); }

◆ Reduce()

template<std::ranges::range R, typename T , typename BinaryOp >
requires std::invocable<BinaryOp, T, std::ranges::range_reference_t<R>>
Task helios::async::SubTaskGraph::Reduce ( const R &  range,
T &  init,
BinaryOp &&  binary_op 
)
inline

Creates a parallel reduction task that combines elements using a binary operation.

Note
Not thread-safe
Template Parameters
RRange type
TResult type
BinaryOpBinary operation type
Parameters
rangeRange of elements to reduce
initInitial value and storage for the result
binary_opBinary function to combine elements
Returns
Task handle for the parallel operation

Definition at line 179 of file sub_task_graph.hpp.

179 {
180 return Task(
181 subflow_.reduce(std::ranges::begin(range), std::ranges::end(range), init, std::forward<BinaryOp>(binary_op)));
182 }

◆ RemoveTask()

void helios::async::SubTaskGraph::RemoveTask ( const Task task)
inline

Removes a task from this subflow.

Note
Not thread-safe
Parameters
taskTask to remove

Definition at line 202 of file sub_task_graph.hpp.

202{ subflow_.erase(task.UnderlyingTask()); }

◆ Retain()

void helios::async::SubTaskGraph::Retain ( bool  flag)
inlinenoexcept

Specifies whether to keep the sub task graph after it is joined.

By default, a sub task graph is destroyed after being joined. Retaining it allows it to remain valid after being joined.

Warning
Must be called by the same worker thread that created this subflow.
Parameters
flagTrue to retain, false otherwise

Definition at line 64 of file sub_task_graph.hpp.

64{ subflow_.retain(flag); }

◆ Run() [1/4]

auto helios::async::SubTaskGraph::Run ( TaskGraph &&  graph) -> Future<void>
inline

Runs a task graph once.

Note
Thread-safe.
Parameters
graphTask graph to execute (moved)
Returns
Future that completes when execution finishes

Definition at line 248 of file sub_task_graph.hpp.

248 {
249 return Future<void>(subflow_.executor().run(std::move(std::move(graph).UnderlyingTaskflow())));
250 }

◆ Run() [2/4]

template<std::invocable C>
auto helios::async::SubTaskGraph::Run ( TaskGraph &&  graph,
C &&  callable 
) -> Future<void>
inline

Runs a moved task graph once and invokes a callback upon completion.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
graphTask graph to execute (moved)
callableCallback to invoke after execution completes
Returns
Future that completes when execution finishes

Definition at line 275 of file sub_task_graph.hpp.

275 {
276 return Future<void>(
277 subflow_.executor().run(std::move(std::move(graph).UnderlyingTaskflow()), std::forward<C>(callable)));
278 }

◆ Run() [3/4]

auto helios::async::SubTaskGraph::Run ( TaskGraph graph) -> Future<void>
inline

Runs a task graph once.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Parameters
graphTask graph to execute
Returns
Future that completes when execution finishes

Definition at line 238 of file sub_task_graph.hpp.

238 {
239 return Future<void>(subflow_.executor().run(graph.UnderlyingTaskflow()));
240 }

◆ Run() [4/4]

template<std::invocable C>
auto helios::async::SubTaskGraph::Run ( TaskGraph graph,
C &&  callable 
) -> Future<void>
inline

Runs a task graph once and invokes a callback upon completion.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
graphTask graph to execute
callableCallback to invoke after execution completes
Returns
Future that completes when execution finishes

Definition at line 262 of file sub_task_graph.hpp.

262 {
263 return Future<void>(subflow_.executor().run(graph.UnderlyingTaskflow(), std::forward<C>(callable)));
264 }

◆ RunN() [1/4]

auto helios::async::SubTaskGraph::RunN ( TaskGraph &&  graph,
size_t  count 
) -> Future<void>
inline

Runs a moved task graph for the specified number of times.

Note
Thread-safe.
Parameters
graphTask graph to execute (moved)
countNumber of times to run the graph
Returns
Future that completes when all executions finish

Definition at line 299 of file sub_task_graph.hpp.

299 {
300 return Future<void>(subflow_.executor().run_n(std::move(std::move(graph).UnderlyingTaskflow()), count));
301 }

◆ RunN() [2/4]

template<std::invocable C>
auto helios::async::SubTaskGraph::RunN ( TaskGraph &&  graph,
size_t  count,
C &&  callable 
) -> Future<void>
inline

Runs a moved task graph for the specified number of times and invokes a callback.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
graphTask graph to execute (moved)
countNumber of times to run the graph
callableCallback to invoke after all executions complete
Returns
Future that completes when all executions finish

Definition at line 328 of file sub_task_graph.hpp.

328 {
329 return Future<void>(
330 subflow_.executor().run_n(std::move(std::move(graph).UnderlyingTaskflow()), count, std::forward<C>(callable)));
331 }

◆ RunN() [3/4]

auto helios::async::SubTaskGraph::RunN ( TaskGraph graph,
size_t  count 
) -> Future<void>
inline

Runs a task graph for the specified number of times.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Parameters
graphTask graph to execute
countNumber of times to run the graph
Returns
Future that completes when all executions finish

Definition at line 288 of file sub_task_graph.hpp.

288 {
289 return Future<void>(subflow_.executor().run_n(graph.UnderlyingTaskflow(), count));
290 }

◆ RunN() [4/4]

template<std::invocable C>
auto helios::async::SubTaskGraph::RunN ( TaskGraph graph,
size_t  count,
C &&  callable 
) -> Future<void>
inline

Runs a task graph for the specified number of times and invokes a callback.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
graphTask graph to execute
countNumber of times to run the graph
callableCallback to invoke after all executions complete
Returns
Future that completes when all executions finish

Definition at line 314 of file sub_task_graph.hpp.

314 {
315 return Future<void>(subflow_.executor().run_n(graph.UnderlyingTaskflow(), count, std::forward<C>(callable)));
316 }

◆ RunningTopologyCount()

size_t helios::async::SubTaskGraph::RunningTopologyCount ( ) const
inline

Gets the number of task graphs currently being executed.

Note
Thread safe.
Returns
Count of running topologies.

Definition at line 540 of file sub_task_graph.hpp.

540{ return subflow_.executor().num_topologies(); }

◆ RunUntil() [1/4]

template<std::predicate Predicate>
auto helios::async::SubTaskGraph::RunUntil ( TaskGraph &&  graph,
Predicate &&  predicate 
) -> Future<void>
inline

Runs a moved task graph repeatedly until the predicate returns true.

Note
Thread-safe.
Template Parameters
PredicatePredicate type
Parameters
graphTask graph to execute (moved)
predicateBoolean predicate to determine when to stop
Returns
Future that completes when predicate returns true

Definition at line 356 of file sub_task_graph.hpp.

356 {
357 return Future<void>(subflow_.executor().run_until(std::move(std::move(graph).UnderlyingTaskflow()),
358 std::forward<Predicate>(predicate)));
359 }

◆ RunUntil() [2/4]

template<std::predicate Predicate, std::invocable C>
auto helios::async::SubTaskGraph::RunUntil ( TaskGraph &&  graph,
Predicate &&  predicate,
C &&  callable 
) -> Future<void>
inline

Runs a moved task graph repeatedly until the predicate returns true, then invokes a callback.

Note
Thread-safe.
Template Parameters
PredicatePredicate type
CCallable type
Parameters
graphTask graph to execute (moved)
predicateBoolean predicate to determine when to stop
callableCallback to invoke after execution completes
Returns
Future that completes when predicate returns true and callback finishes

Definition at line 389 of file sub_task_graph.hpp.

389 {
390 return Future<void>(subflow_.executor().run_until(std::move(std::move(graph).UnderlyingTaskflow()),
391 std::forward<Predicate>(predicate), std::forward<C>(callable)));
392 }

◆ RunUntil() [3/4]

template<std::predicate Predicate>
auto helios::async::SubTaskGraph::RunUntil ( TaskGraph graph,
Predicate &&  predicate 
) -> Future<void>
inline

Runs a task graph repeatedly until the predicate returns true.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Template Parameters
PredicatePredicate type
Parameters
graphTask graph to execute
predicateBoolean predicate to determine when to stop
Returns
Future that completes when predicate returns true

Definition at line 343 of file sub_task_graph.hpp.

343 {
344 return Future<void>(subflow_.executor().run_until(graph.UnderlyingTaskflow(), std::forward<Predicate>(predicate)));
345 }

◆ RunUntil() [4/4]

template<std::predicate Predicate, std::invocable C>
auto helios::async::SubTaskGraph::RunUntil ( TaskGraph graph,
Predicate &&  predicate,
C &&  callable 
) -> Future<void>
inline

Runs a task graph repeatedly until the predicate returns true, then invokes a callback.

Task graph is not owned - ensure it remains alive during execution.

Note
Thread-safe.
Template Parameters
PredicatePredicate type
CCallable type
Parameters
graphTask graph to execute
predicateBoolean predicate to determine when to stop
callableCallback to invoke after execution completes
Returns
Future that completes when predicate returns true and callback finishes

Definition at line 373 of file sub_task_graph.hpp.

373 {
374 return Future<void>(subflow_.executor().run_until(graph.UnderlyingTaskflow(), std::forward<Predicate>(predicate),
375 std::forward<C>(callable)));
376 }

◆ SilentAsync() [1/2]

template<std::invocable C>
void helios::async::SubTaskGraph::SilentAsync ( C &&  callable)
inline

Creates an asynchronous task without returning a future.

More efficient than Async when you don't need the result.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
callableFunction to execute asynchronously

Definition at line 429 of file sub_task_graph.hpp.

429 {
430 subflow_.executor().silent_async(std::forward<C>(callable));
431 }

◆ SilentAsync() [2/2]

template<std::invocable C>
void helios::async::SubTaskGraph::SilentAsync ( std::string  name,
C &&  callable 
)
inline

Creates a named asynchronous task without returning a future.

More efficient than Async when you don't need the result.

Note
Thread-safe.
Template Parameters
CCallable type
Parameters
nameName for the task (useful for debugging/profiling)
callableFunction to execute asynchronously

Definition at line 442 of file sub_task_graph.hpp.

442 {
443 subflow_.executor().silent_async(std::move(name), std::forward<C>(callable));
444 }

◆ SilentDependentAsync()

template<std::invocable C, std::ranges::range Dependencies>
requires std::same_as<std::ranges::range_value_t<Dependencies>, AsyncTask>
AsyncTask helios::async::SubTaskGraph::SilentDependentAsync ( C &&  callable,
const Dependencies &  dependencies 
)
inline

Creates an asynchronous task that runs after dependencies complete, without returning a future.

More efficient than DependentAsync when you don't need the result.

Note
Thread-safe.
Template Parameters
CCallable type
DependenciesRange type containing AsyncTask dependencies
Parameters
callableFunction to execute asynchronously
dependenciesTasks that must complete before this task runs
Returns
AsyncTask handle

Definition at line 604 of file sub_task_graph.hpp.

604 {
605 std::vector<tf::AsyncTask> tf_deps;
606 if constexpr (std::ranges::sized_range<Dependencies>) {
607 tf_deps.reserve(std::ranges::size(dependencies));
608 }
609
610 for (const auto& dep : dependencies) {
611 tf_deps.push_back(dep.UnderlyingTask());
612 }
613
614 return AsyncTask(
615 subflow_.executor().silent_dependent_async(std::forward<C>(callable), tf_deps.begin(), tf_deps.end()));
616}

◆ Sort()

template<std::ranges::random_access_range R, typename Compare >
requires std::predicate<Compare, std::ranges::range_reference_t<R>, std::ranges::range_reference_t<R>>
Task helios::async::SubTaskGraph::Sort ( R &  range,
Compare &&  comparator = Compare() 
)
inline

Creates a parallel sort task for the given range.

Note
Not thread-safe
Template Parameters
RRandom access range type
CompareComparator type
Parameters
rangeRange of elements to sort
comparatorComparison function (default: std::less<>)
Returns
Task handle for the parallel operation

Definition at line 577 of file sub_task_graph.hpp.

577 {
578 if constexpr (std::same_as<std::remove_cvref_t<Compare>, std::less<>>) {
579 return Task(subflow_.sort(std::ranges::begin(range), std::ranges::end(range)));
580 } else {
581 return Task(subflow_.sort(std::ranges::begin(range), std::ranges::end(range), std::forward<Compare>(comparator)));
582 }
583}

◆ Transform()

template<std::ranges::range InputRange, std::ranges::range OutputRange, std::invocable< std::ranges::range_reference_t< InputRange > > TransformFunc>
Task helios::async::SubTaskGraph::Transform ( const InputRange &  input_range,
OutputRange &  output_range,
TransformFunc &&  transform_func 
)
inline

Creates a parallel transform task that applies a function to each element.

Note
Not thread-safe
Template Parameters
InputRangeInput range type
OutputRangeOutput range type
TransformFuncTransform function type
Parameters
input_rangeRange of input elements
output_rangeRange to store transformed results
transform_funcFunction to apply to each input element
Returns
Task handle for the parallel operation

Definition at line 161 of file sub_task_graph.hpp.

161 {
162 return Task(subflow_.transform(std::ranges::begin(input_range), std::ranges::end(input_range),
163 std::ranges::begin(output_range), std::forward<TransformFunc>(transform_func)));
164 }

◆ WaitForAll()

void helios::async::SubTaskGraph::WaitForAll ( )
inline

Blocks until all submitted tasks complete.

Waits for all taskflows and async tasks to finish.

Note
Thread-safe.

Definition at line 480 of file sub_task_graph.hpp.

480{ subflow_.executor().wait_for_all(); }

◆ WillBeRetained()

bool helios::async::SubTaskGraph::WillBeRetained ( ) const
inlinenoexcept

Checks if this subflow will be retained.

A retained subflow remains valid after being joined.

Returns
True if the subflow will be retained, false otherwise

Definition at line 227 of file sub_task_graph.hpp.

227{ return subflow_.retain(); }

◆ WorkerCount()

size_t helios::async::SubTaskGraph::WorkerCount ( ) const
inlinenoexcept

Gets the total number of worker threads.

Note
Thread safe.
Returns
Count of workers.

Definition at line 519 of file sub_task_graph.hpp.

519{ return subflow_.executor().num_workers(); }

Friends And Related Symbol Documentation

◆ Executor

friend class Executor
friend

Definition at line 551 of file sub_task_graph.hpp.

◆ TaskGraph

friend class TaskGraph
friend

Definition at line 550 of file sub_task_graph.hpp.