Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

taskflow

> 数据库
Open source

A General-purpose Task-parallel Programming System in C++

12.1K stars0 likes1 views
WebsiteGitHub

About

A General-purpose Task-parallel Programming System in C++

Taskflow

Taskflow helps you quickly write high-performance task-parallel programs with high programming productivity. It is faster, more expressive, fewer lines of code, and easier for drop-in integration than many existing task programming libraries.

Start Your First Taskflow Program

The following program (simple.cpp) creates four tasks A, B, C, and D, where A runs before B and C, and D runs after B and C. When A finishes, B and C run in parallel. Try it live on Compiler Explorer!

…

Taskflow is header-only and there is no struggle with installation. To compile the program, clone the Taskflow project and tell the compiler to include the headers under taskflow/.

bash
~$ git clone https://github.com/taskflow/taskflow.git  # clone it only once
~$ g++ -std=c++20 simple.cpp -I taskflow/ -O2 -pthread -o simple
~$ ./simple
TaskA
TaskC 
TaskB 
TaskD

Taskflow comes with a built-in profiler, TFProf, for you to profile and visualize taskflow programs in an easy-to-use web-based interface.

bash
# run the program with the environment variable TF_ENABLE_PROFILER enabled
~$ TF_ENABLE_PROFILER=simple.tfp ./simple
# drag the simple.tfp file to https://taskflow.github.io/tfprof/

Create a Subflow Graph

Taskflow supports recursive tasking for you to create a subflow graph from the execution of a task to perform recursive parallelism. The following program spawns a task dependency graph parented at task B.

cpp
tf::Task A = taskflow.emplace([](){}).name("A");  
tf::Task C = taskflow.emplace([](){}).name("C");  
tf::Task D = taskflow.emplace([](){}).name("D");  

tf::Task B = taskflow.emplace([] (tf::Subflow& subflow) { // subflow task B
  tf::Task B1 = subflow.emplace([](){}).name("B1");  
  tf::Task B2 = subflow.emplace([](){}).name("B2");  
  tf::Task B3 = subflow.emplace([](){}).name("B3");  
  B3.succeed(B1, B2);  // B3 runs after B1 and B2
}).name("B");

A.precede(B, C);  // A runs before B and C
D.succeed(B, C);  // D runs after  B and C

Integrate Control Flow into a Task Graph

Taskflow supports conditional tasking for you to make rapid control-flow decisions across dependent tasks to implement cycles and conditions in an end-to-end task graph.

cpp
tf::Task init = taskflow.emplace([](){}).name("init");
tf::Task stop = taskflow.emplace([](){}).name("stop");

// creates a condition task that returns a random binary
tf::Task cond = taskflow.emplace([](){ return std::rand() % 2; }).name("cond");

// creates a feedback loop {0: cond, 1: stop}
init.precede(cond);
cond.precede(cond, stop);  // moves on to 'cond' on returning 0, or 'stop' on 1

Compose Task Graphs

Taskflow is composable. You can create large parallel graphs through composition of modular and reusable blocks that are easier to optimize at an individual scope.

…

Launch Asynchronous Tasks

Taskflow supports asynchronous tasking. You can launch tasks asynchronously to dynamically explore task graph parallelism.

…

Leverage Standard Parallel Algorithms

Taskflow defines algorithms for you to quickly express common parallel patterns using standard C++ syntaxes, such as parallel iterations, reductions, and sort.

cpp
tf::Task task1 = taskflow.for_each( // assign each element to 100 in parallel
  first, last, [] (auto& i) { i = 100; }    
);
tf::Task task2 = taskflow.reduce(   // reduce a range of items in parallel
  first, last, init, [] (auto a, auto b) { return a + b; }
);
tf::Task task3 = taskflow.sort(     // sort a range of items in parallel
  first, last, [] (auto a, auto b) { return a < b; }
);

Taskflow also provides composable graph building blocks for common parallel algorithms such as parallel pipeline.

cpp
// create a pipeline to propagate five tokens through three serial stages
tf::Pipeline pl(num_lines,
  tf::Pipe{tf::PipeType::SERIAL, [](tf::Pipeflow& pf) {
    if(pf.token() == 5) pf.stop();
  }},
  tf::Pipe{tf::PipeType::SERIAL, [](tf::Pipeflow& pf) {
    printf("stage 2: input buffer[%zu] = %d\n", pf.line(), buffer[pf.line()]);
  }},
  tf::Pipe{tf::PipeType::SERIAL, [](tf::Pipeflow& pf) {
    printf("stage 3: input buffer[%zu] = %d\n", pf.line(), buffer[pf.line()]);
  }}
);
taskflow.composed_of(pl);
executor.run(taskflow).wait();

Offload Tasks to a GPU

Taskflow supports GPU tasking for you to accelerate scientific computing applications by harnessing the power of CPU-GPU collaborative computing using Nvidia CUDA Graph.

cpp
tf::Task cudaflow = taskflow.emplace([&]() {
  tf::cudaGraph cg;
  tf::cudaTask h2d_x = cg.copy(dx, hx.data(), N);
  tf::cudaTask h2d_y = cg.copy(dy, hy.data(), N);
  tf::cudaTask d2h_x = cg.copy(hx.data(), dx, N);
  tf::cudaTask d2h_y = cg.copy(hy.data(), dy, N);
  tf::cudaTask saxpy = cg.kernel((N+255)/256, 256, 0, saxpy, N, 2.0f, dx, dy);
  saxpy.succeed(h2d_x, h2d_y)
       .precede(d2h_x, d2h_y);
  tf::cudaGraphExec exec(cg);
  tf::cudaStream stream;
  stream.run(exec).synchronize();
}).name("CUDA Graph Task");

Run a Taskflow through an Executor

The executor provides several thread-safe methods to run a taskflow. You can run a taskflow once, multiple times, or until a stopping criteria is met. These methods are non-blocking with a tf::Future<void> return to let you query the execution status.

cpp
// runs the taskflow once
tf::Future<void> run_once = executor.run(taskflow); 

// wait on this run to finish
run_once.get();

// run the taskflow four times
executor.run_n(taskflow, 4);

// runs the taskflow five times
executor.run_until(taskflow, [counter=5](){ return --counter == 0; });

// blocks the executor until all submitted taskflows complete
executor.wait_for_all();

Visualize a Taskflow Graph

You can dump a taskflow graph to a DOT format and visualize it using free GraphViz tools.

cpp
// dump the taskflow graph to a DOT format through std::cout
taskflow.dump(std::cout); 

Supported Compilers

To use Taskflow v4.0.0, you need a compiler that supports C++20:

  • GNU C++ Compiler at least v11.0 with -std=c++20
  • Clang C++ Compiler at least v12.0 with -std=c++20
  • Microsoft Visual Studio at least v19.29 (VS 2019) with /std:c++20
  • Apple Clang (Xcode) at least v13.0 with -std=c++20
  • NVIDIA CUDA Toolkit and Compiler (nvcc) at least v12.0 with host compiler supporting C++20
  • Intel oneAPI DPC++/C++ Compiler at least v2022.0 with -std=c++20

Taskflow works on Linux, Windows, and Mac OS X.

Get Involved

Visit our project website and documentation to learn more about Taskflow. To get involved:

  • See release notes to stay up-to-date with newest versions
  • Read the step-by-step tutorial at cookbook
  • Submit an issue at GitHub issues
  • Learn more about our technical details at references
  • Watch our technical talks on YouTube

We are committed to support trustworthy developments for both academic and industrial research projects in parallel and heterogeneous computing. If you are using Taskflow, please cite the following paper we published at 2022 IEEE TPDS:

  • Tsung-Wei Huang, Dian-Lun Lin, Chun-Xun Lin, and Yibo Lin, "Taskflow: A Lightweight Parallel and Heterogeneous Task Graph Computing System," IEEE Transactions on Parallel and Distributed Systems (TPDS), vol. 33, no. 6, pp. 1303-1320, June 2022

More importantly, we appreciate all Taskflow contributors and the following organizations for sponsoring the Taskflow project!

License

Taskflow is open-source under the permissive MIT License. You are completely free to use, modify, and redistribute any work derived from Taskflow.


Issues· 37 open

View all issuesOpen on GitHub
  • #813

    v4.1.0 fails with NVCC 12.6 in IndexRanges::size()

    bugUpdated Sep 28, 2026
  • #810

    Why does Executor restore the join counter with fetch_add instead of store?

    questionUpdated Sep 28, 2026
  • #763

    Is there a plan to support coroutine scheduling again?

    questionUpdated Sep 6, 2026
  • #811

    Using fibers in taskflow

    Updated Sep 5, 2026
  • #780

    Latest via module using MSVC compilation issues.

    help wantedUpdated Aug 11, 2026
  • #807

    [request] Release 4.1.1

    Updated Aug 11, 2026
  • #797

    Question: is project interested in reviving no-worker mode ?

    Updated Jul 13, 2026
  • #792

    Work-stealing imbalance causing idle workers in short-duration parallel for_each tasks on Android

    Updated Jun 3, 2026
  • #709

    How to implement multiple CONDITION tasks triggering a common successor as a logical OR?

    questionUpdated Feb 11, 2026
  • #740

    Suggestion: make a hip-like-graph base that can be specialised for cuda, rocm and hip?

    Updated Dec 17, 2025

> Tags

C++concurrent-programmingcuda-programminggpu-programmingheterogeneous-parallel-programming

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库