class to create a runtime task More...
#include <taskflow/core/runtime.hpp>
Public Member Functions | |
| Executor & | executor () |
| obtains the running executor | |
| Worker & | worker () |
| acquire a reference to the underlying worker | |
| void | schedule (Task task) |
| schedules an active task immediately to the worker's queue | |
| template<typename F > | |
| auto | async (F &&f) |
| runs the given callable asynchronously | |
| template<typename P , typename F > | |
| auto | async (P &¶ms, F &&f) |
| runs the given callable asynchronously | |
| template<typename F > | |
| void | silent_async (F &&f) |
| runs the given function asynchronously without returning any future object | |
| template<typename P , typename F > | |
| void | silent_async (P &¶ms, F &&f) |
| runs the given function asynchronously without returning any future object | |
| template<typename F , typename... Tasks> requires (std::same_as<std::decay_t<Tasks>, AsyncTask> && ...) | |
| auto | dependent_async (F &&func, Tasks &&... tasks) |
| runs the given function asynchronously when the given predecessors finish | |
| template<TaskParameters P, typename F , typename... Tasks> requires (std::same_as<std::decay_t<Tasks>, AsyncTask> && ...) | |
| auto | dependent_async (P &¶ms, F &&func, Tasks &&... tasks) |
| runs the given function asynchronously when the given predecessors finish | |
| template<typename F , typename I > requires (!std::same_as<std::decay_t<I>, AsyncTask>) | |
| auto | dependent_async (F &&func, I first, I last) |
| runs the given function asynchronously when the given range of predecessors finish | |
| template<TaskParameters P, typename F , typename I > requires (!std::same_as<std::decay_t<I>, AsyncTask>) | |
| auto | dependent_async (P &¶ms, F &&func, I first, I last) |
| runs the given function asynchronously when the given range of predecessors finish | |
| template<typename F , typename... Tasks> requires (std::same_as<std::decay_t<Tasks>, AsyncTask> && ...) | |
| tf::AsyncTask | silent_dependent_async (F &&func, Tasks &&... tasks) |
| runs the given function asynchronously when the given predecessors finish | |
| template<TaskParameters P, typename F , typename... Tasks> requires (std::same_as<std::decay_t<Tasks>, AsyncTask> && ...) | |
| tf::AsyncTask | silent_dependent_async (P &¶ms, F &&func, Tasks &&... tasks) |
| runs the given function asynchronously when the given predecessors finish | |
| template<typename F , typename I > requires (!std::same_as<std::decay_t<I>, AsyncTask>) | |
| tf::AsyncTask | silent_dependent_async (F &&func, I first, I last) |
| runs the given function asynchronously when the given range of predecessors finish | |
| template<TaskParameters P, typename F , typename I > requires (!std::same_as<std::decay_t<I>, AsyncTask>) | |
| tf::AsyncTask | silent_dependent_async (P &¶ms, F &&func, I first, I last) |
| runs the given function asynchronously when the given range of predecessors finish | |
| void | corun () |
| corun all tasks spawned by this runtime with other workers | |
| void | corun_all () |
| equivalent to tf::Runtime::corun - just an alias for legacy purpose | |
| bool | is_cancelled () |
| queries if this runtime task has been cancelled | |
Friends | |
| class | Executor |
| class | FlowBuilder |
| class | PreemptionGuard |
| class | Algorithm |
class to create a runtime task
A runtime object provides an interface for interacting with the scheduling system from within a task (i.e., the parent task of this runtime). It enables operations such as spawning asynchronous tasks, executing tasks cooperatively, and implementing recursive parallelism. The runtime guarantees an implicit join at the end of its scope, so all spawned tasks will finish before the parent runtime task continues to its successors.
| auto tf::Runtime::async | ( | F && | f | ) |
runs the given callable asynchronously
| F | callable type |
| f | callable object |
This method creates an asynchronous task that executes the given function with the specified arguments. Unlike tf::Executor::async, the task created here is parented to the runtime object and is implicitly synchronized at the end of the runtime's scope. Applications may also call tf::Runtime::corun explicitly to wait for all asynchronous tasks spawned from the runtime to complete. For example:
| auto tf::Runtime::async | ( | P && | params, |
| F && | f ) |
runs the given callable asynchronously
| F | callable type |
| P | task parameters type satisfying tf::TaskParameters |
| params | task parameters |
| f | callable |
Similar to tf::Runtime::async, but takes a parameter of type tf::TaskParams to initialize the asynchronous task.
|
inline |
corun all tasks spawned by this runtime with other workers
Coruns all tasks spawned by this runtime cooperatively with other workers in the same executor until all these tasks finish. Under cooperative execution, a worker is not preempted. Instead, it continues participating in the work-stealing loop, executing available tasks alongside other workers.
Only the parent worker of this runtime is allowed to call this corun.
| auto tf::Runtime::dependent_async | ( | F && | func, |
| I | first, | ||
| I | last ) |
runs the given function asynchronously when the given range of predecessors finish
| F | callable type |
| I | iterator type |
| func | callable object |
| first | iterator to the beginning (inclusive) |
| last | iterator to the end (exclusive) |
The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Task C returns a pair of its tf::AsyncTask handle and a std::future<int> that eventually will hold the result of the execution.
| auto tf::Runtime::dependent_async | ( | F && | func, |
| Tasks &&... | tasks ) |
runs the given function asynchronously when the given predecessors finish
| F | callable type |
| Tasks | tasks of type tf::AsyncTask |
| func | callable object |
| tasks | asynchronous tasks on which this execution depends |
The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Task C returns a pair of its tf::AsyncTask handle and a std::future<int> that eventually will hold the result of the execution.
| auto tf::Runtime::dependent_async | ( | P && | params, |
| F && | func, | ||
| I | first, | ||
| I | last ) |
runs the given function asynchronously when the given range of predecessors finish
| P | task parameters type satisfying tf::TaskParameters |
| F | callable type |
| I | iterator type |
| params | task parameters |
| func | callable object |
| first | iterator to the beginning (inclusive) |
| last | iterator to the end (exclusive) |
The example below creates three named asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Task C returns a pair of its tf::AsyncTask handle and a std::future<int> that eventually will hold the result of the execution. Assigned task names will appear in the observers of the executor.
| auto tf::Runtime::dependent_async | ( | P && | params, |
| F && | func, | ||
| Tasks &&... | tasks ) |
runs the given function asynchronously when the given predecessors finish
| P | task parameters type satisfying tf::TaskParameters |
| F | callable type |
| Tasks | tasks of type tf::AsyncTask |
| params | task parameters |
| func | callable object |
| tasks | asynchronous tasks on which this execution depends |
The example below creates three named asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Task C returns a pair of its tf::AsyncTask handle and a std::future<int> that eventually will hold the result of the execution. Assigned task names will appear in the observers of the executor.
|
inline |
obtains the running executor
The running executor of a runtime task is the executor that runs the parent taskflow of that runtime task.
|
inline |
schedules an active task immediately to the worker's queue
| task | the given active task to schedule immediately |
This member function immediately schedules an active task to the task queue of the associated worker in the runtime task. An active task is a task in a running taskflow. The task may or may not be running, and scheduling that task will immediately put the task into the task queue of the worker that is running the runtime task. Consider the following example:
The executor will first run the condition task A which returns 0 to inform the scheduler to go to the runtime task B. During the execution of B, it directly schedules task C without going through the normal taskflow graph scheduling process. At this moment, task C is active because its parent taskflow is running. When the taskflow finishes, we will see both B and C in the output.
| void tf::Runtime::silent_async | ( | F && | f | ) |
runs the given function asynchronously without returning any future object
| F | callable type |
| f | callable |
This function is more efficient than tf::Runtime::async and is recommended when the result of the asynchronous task does not need to be accessed via a std::future.
| void tf::Runtime::silent_async | ( | P && | params, |
| F && | f ) |
runs the given function asynchronously without returning any future object
| F | callable type |
| params | task parameters |
| f | callable |
Similar to tf::Runtime::silent_async, but takes a parameter of type tf::TaskParams to initialize the created asynchronous task.
| tf::AsyncTask tf::Runtime::silent_dependent_async | ( | F && | func, |
| I | first, | ||
| I | last ) |
runs the given function asynchronously when the given range of predecessors finish
| F | callable type |
| I | iterator type |
| func | callable object |
| first | iterator to the beginning (inclusive) |
| last | iterator to the end (exclusive) |
This member function is more efficient than tf::Runtime::dependent_async and is encouraged to use when you do not want a std::future to acquire the result or synchronize the execution. The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B.
| tf::AsyncTask tf::Runtime::silent_dependent_async | ( | F && | func, |
| Tasks &&... | tasks ) |
runs the given function asynchronously when the given predecessors finish
| F | callable type |
| Tasks | tasks of type tf::AsyncTask |
| func | callable object |
| tasks | asynchronous tasks on which this execution depends |
This member function is more efficient than tf::Runtime::dependent_async and is encouraged to use when you do not want a std::future to acquire the result or synchronize the execution. The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B.
| tf::AsyncTask tf::Runtime::silent_dependent_async | ( | P && | params, |
| F && | func, | ||
| I | first, | ||
| I | last ) |
runs the given function asynchronously when the given range of predecessors finish
| F | callable type |
| I | iterator type |
| params | tasks parameters |
| func | callable object |
| first | iterator to the beginning (inclusive) |
| last | iterator to the end (exclusive) |
This member function is more efficient than tf::Runtime::dependent_async and is encouraged to use when you do not want a std::future to acquire the result or synchronize the execution. The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Assigned task names will appear in the observers of the executor.
| tf::AsyncTask tf::Runtime::silent_dependent_async | ( | P && | params, |
| F && | func, | ||
| Tasks &&... | tasks ) |
runs the given function asynchronously when the given predecessors finish
| F | callable type |
| Tasks | tasks of type tf::AsyncTask |
| params | task parameters |
| func | callable object |
| tasks | asynchronous tasks on which this execution depends |
This member function is more efficient than tf::Runtime::dependent_async and is encouraged to use when you do not want a std::future to acquire the result or synchronize the execution. The example below creates three asynchronous tasks, A, B, and C, in which task C runs after task A and task B. Assigned task names will appear in the observers of the executor.