class
#include <src/taskflow/core/taskflow.hpp>
Taskflow main entry to create a task dependency graph
Contents
A taskflow manages a task dependency graph where each task represents a callable object (e.g., , ) and an edge represents a dependency between two tasks. A task is one of the following types:
- static task: the callable constructible from
std::function<void()>
- dynamic task: the callable constructible from
std::function<void(tf::Subflow&)>
- condition task: the callable constructible from
std::function<int()>
- module task: the task constructed from tf::
Taskflow:: composed_of - cudaFlow task: the callable constructible from
std::function<void(tf::cudaFlow&)>
orstd::function<void(tf::cudaFlowCapturer&)>
Each task is a basic computation unit and is run by one worker thread from an executor. The following example creates a simple taskflow graph of four static tasks, A
, B
, C
, and D
, where A
runs before B
and C
and D
runs after B
and C
.
tf::Executor executor; tf::Taskflow taskflow("simple"); tf::Task A = taskflow.emplace([](){ std::cout << "TaskA\n"; }); tf::Task B = taskflow.emplace([](){ std::cout << "TaskB\n"; }); tf::Task C = taskflow.emplace([](){ std::cout << "TaskC\n"; }); tf::Task D = taskflow.emplace([](){ std::cout << "TaskD\n"; }); A.precede(B, C); // A runs before B and C D.succeed(B, C); // D runs after B and C executor.run(taskflow).wait();
Please refer to Cookbook to learn more about each task type and how to submit a taskflow to an executor.
Base classes
- class FlowBuilder
- building methods of a task dependency graph
Constructors, destructors, conversion operators
Public functions
- void dump(std::ostream& ostream) const
- dumps the taskflow to a DOT format through a std::ostream target
- auto dump() const -> std::string
- dumps the taskflow to a std::string of DOT format
- auto num_tasks() const -> size_t
- queries the number of tasks
- auto empty() const -> bool
- queries the emptiness of the taskflow
- void name(const std::string&)
- assigns a name to the taskflow
- auto name() const -> const std::string&
- queries the name of the taskflow
- void clear()
- clears the associated task dependency graph
-
template<typename V>void for_each_task(V&& visitor) const
- applies a visitor to each task in the taskflow
Function documentation
tf:: Taskflow:: ~Taskflow() defaulted
default destructor
When the destructor is called, all tasks and their associated data (e.g., captured data) will be destroyed. It is your responsibility to ensure all submitted execution of this taskflow have completed before destroying it.
void tf:: Taskflow:: clear()
clears the associated task dependency graph
When you clear a taskflow, all tasks and their associated data (e.g., captured data) will be destroyed. You should never clean a taskflow while it is being run by an executor.
template<typename V>
void tf:: Taskflow:: for_each_task(V&& visitor) const
applies a visitor to each task in the taskflow
A visitor is a callable that takes an argument of type tf::
taskflow.for_each_task([](tf::Task task){ std::cout << task.name() << '\n'; });