|
| 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<TaskParamsLike 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<TaskParamsLike P, typename F > |
| void | silent_async (P &¶ms, F &&f) |
| | runs the given function asynchronously without returning any future object
|
| |
| template<typename F , AsyncTaskHandleLike... Tasks> |
| auto | dependent_async (F &&func, Tasks &&... tasks) |
| | runs the given function asynchronously when the given predecessors finish
|
| |
| template<TaskParamsLike P, typename F , AsyncTaskHandleLike... Tasks> |
| auto | dependent_async (P &¶ms, F &&func, Tasks &&... tasks) |
| | runs the given function asynchronously when the given predecessors finish
|
| |
| template<typename F , std::input_iterator I> |
| auto | dependent_async (F &&func, I first, I last) |
| | runs the given function asynchronously when the given range of predecessors finish
|
| |
| template<TaskParamsLike P, typename F , std::input_iterator I> |
| 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 , AsyncTaskHandleLike... Tasks> |
| tf::AsyncTask | silent_dependent_async (F &&func, Tasks &&... tasks) |
| | runs the given function asynchronously when the given predecessors finish
|
| |
| template<TaskParamsLike P, typename F , AsyncTaskHandleLike... Tasks> |
| tf::AsyncTask | silent_dependent_async (P &¶ms, F &&func, Tasks &&... tasks) |
| | runs the given function asynchronously when the given predecessors finish
|
| |
| template<typename F , std::input_iterator I> |
| tf::AsyncTask | silent_dependent_async (F &&func, I first, I last) |
| | runs the given function asynchronously when the given range of predecessors finish
|
| |
| template<TaskParamsLike P, typename F , std::input_iterator I> |
| 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
|
| |
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.
std::atomic<size_t> counter(0);
for(size_t i=0; i<1000; i++) {
rt.
silent_async([&](){ counter.fetch_add(1, std::memory_order_relaxed); });
}
});
assert(counter.load(std::memory_order_relaxed) == 1000);
});
class to create an executor
Definition executor.hpp:62
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:1738
class to create a runtime task
Definition runtime.hpp:47
void silent_async(F &&f)
runs the given function asynchronously without returning any future object
Definition runtime.hpp:667
Executor & executor()
obtains the running executor
Definition runtime.hpp:617
class to create a task handle over a taskflow node
Definition task.hpp:569
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition task.hpp:1258
class to create a taskflow object
Definition taskflow.hpp:64
- Note
- To understand how Taskflow schedules a runtime task, please refer to Runtime Tasking.
template<TaskParamsLike P, typename F , std::input_iterator I>
| 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
- Template Parameters
-
- Parameters
-
| params | task parameters |
| func | callable object |
| first | iterator to the beginning (inclusive) |
| last | iterator to the end (exclusive) |
- Returns
- a pair of a tf::AsyncTask handle and a std::future that holds the result of the execution
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.
std::array<tf::AsyncTask, 2> array {
};
"C",
[](){
printf("C runs after A and B\n");
return 1;
},
array.begin(), array.end()
);
assert(fuC.get()==1);
});
| void tf::Runtime::schedule |
( |
Task | task | ) |
|
|
inline |
schedules an active task immediately to the worker's queue
- Parameters
-
| 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:
std::tie(A, B, C, D) = taskflow.emplace(
[] () { return 0; },
std::cout << "B\n";
rt.schedule(C);
},
[] () { std::cout << "C\n"; },
[] () { std::cout << "D\n"; }
);
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.
- Attention
- This method can only be called by the parent worker of this runtime, or the behavior is undefined. Furthermore, we currently do not support scheduling a runtime task.