Introduction
Taskflow is a header-only C++ library that lets developers express parallel workloads as directed task graphs. It handles scheduling, work stealing, and GPU offloading so you can focus on the structure of your computation rather than low-level threading details.
What Taskflow Does
- Expresses complex parallel workflows as directed acyclic task graphs
- Schedules tasks across CPU cores using an efficient work-stealing executor
- Supports heterogeneous computing with CUDA and SYCL GPU task graphs
- Provides composable subflow graphs for modular task decomposition
- Handles dynamic control flow with conditional and looping constructs inside graphs
Architecture Overview
Taskflow uses a lightweight work-stealing scheduler that maps task graphs onto a thread pool. Tasks are nodes in a DAG with explicit dependencies. The executor traverses the graph, dispatching ready tasks to worker threads. For GPU work, CUDA tasks are embedded in the same graph and offloaded transparently.
Self-Hosting & Configuration
- Header-only: add the include path and compile with C++17 or later
- Available via vcpkg, Conan, Homebrew, and Conda
- Enable CUDA support with -DCMAKE_CUDA_COMPILER and linking cudart
- Control thread count via tf::Executor(N) constructor
- Profile task graphs using the built-in TFProf timeline visualizer
Key Features
- Header-only design with zero external dependencies
- Work-stealing scheduler that scales linearly with core count
- Built-in profiler that exports Chrome-tracing-compatible timelines
- Composable subflows allow reusing graph fragments across projects
- Benchmarks faster than OpenMP and TBB on many workloads
Comparison with Similar Tools
- OpenMP — OpenMP uses pragma-based parallelism; Taskflow uses explicit task graphs for more flexible dependency modeling
- Intel TBB (oneTBB) — TBB provides building blocks like parallel_for; Taskflow focuses on graph-based workflows with GPU support
- HPX — HPX targets distributed computing; Taskflow is single-node with lower overhead
- std::async — std::async lacks dependency control; Taskflow manages complex DAGs efficiently
FAQ
Q: Does Taskflow require C++17? A: Yes. Taskflow uses C++17 features such as std::optional, structured bindings, and if-constexpr.
Q: Can Taskflow run GPU tasks? A: Yes. Taskflow supports CUDA task graphs natively, allowing GPU kernels to participate in the same DAG as CPU tasks.
Q: How does Taskflow handle dynamic parallelism? A: Subflows can spawn new tasks at runtime, and conditional tasking allows branches and loops inside the graph.
Q: Is Taskflow thread-safe? A: The executor is thread-safe for concurrent graph submissions. Individual task graph construction is single-threaded by design.