docs/classtf_1_1Subflow.html
class to construct a subflow graph from the execution of a dynamic task
tf::Subflow is spawned from the execution of a task to dynamically manage a child graph that may depend on runtime variables. You can explicitly join a subflow by calling tf::Subflow::join, respectively. By default, the Taskflow runtime will implicitly join a subflow it is is joinable.
The following example creates a taskflow graph that spawns a subflow from the execution of task B, and the subflow contains three tasks, B1, B2, and B3, where B3 runs after B1 and B2.
// create three static taskstf::Task A = taskflow.emplace([](){}).name("A");tf::Task C = taskflow.emplace([](){}).name("C");tf::Task D = taskflow.emplace([](){}).name("D");// create a subflow graph (dynamic tasking)tf::Task B = taskflow.emplace([] (tf::Subflow& subflow) {tf::Task B1 = subflow.emplace([](){}).name("B1");tf::Task B2 = subflow.emplace([](){}).name("B2");tf::Task B3 = subflow.emplace([](){}).name("B3");B1.precede(B3);B2.precede(B3);}).name("B");A.precede(B);// B runs after AA.precede(C);// C runs after AB.precede(D);// D runs after BC.precede(D);// D runs after C
class FlowBuilderclass to build a task dependency graph
void join()enables the subflow to join its parent taskauto joinable() const -> bool noexceptqueries if the subflow is joinableauto executor() -> Executor& noexceptacquires the associated executorauto graph() -> Graph&acquires the associated graphvoid retain(bool flag) noexceptspecifies whether to keep the subflow after it is joinedauto retain() const -> boolqueries if the subflow will be retained after it is joined
enables the subflow to join its parent task
Performs an immediate action to join the subflow. Once the subflow is joined, it is considered finished and you may not modify the subflow anymore.
taskflow.emplace([](tf::Subflow& sf){sf.emplace([](){});sf.join();// join the subflow of one task});
Only the worker that spawns this subflow can join it.
queries if the subflow is joinable
This member function queries if the subflow is joinable. When a subflow is joined, it becomes not joinable.
taskflow.emplace([](tf::Subflow& sf){sf.emplace([](){});std::cout \<\< sf.joinable() \<\< '\n';// truesf.join();std::cout \<\< sf.joinable() \<\< '\n';// false});
specifies whether to keep the subflow after it is joined
| Parameters |
|---|
| flag |
By default, the runtime automatically clears a spawned subflow once it is joined. Setting this flag to true allows the application to retain the subflow's structure for post-execution analysis like visualization.
queries if the subflow will be retained after it is joined
| Returns | true if the subflow will be retained after it is joined; false otherwise |
By default, the runtime automatically clears a spawned subflow once it is joined. Users can disable this before by explicitly calling tf::Subflow::retain.