Cpp-Taskflow
2.1.0
|
This page summarizes a list of frequently asked questions about Cpp-Taskflow. If you cannot find a solution here, please post an issue at here.
Cpp-Taskflow aims to help C++ developers quickly implement efficient parallel decomposition strategies using task-based approaches.
Cpp-Taskflow is a header-only library with zero dependencies. The only thing you need is a C++17 compiler. To use Cpp-Taskflow, simply drop the folder taskflow/
to your project and include taskflow.hpp.
Static tasking refers to those tasks created before execution, while dynamic tasking refers to those tasks created during the execution of static tasks or dynamic tasks (nested). Dynamic tasks created by the same task node are grouped together to a subflow.
Benchmarks showed Cpp-Taskflow can efficiently handle millions or billions of tasks (both large and small tasks) on a machine with up to 64 CPUs.
The hex value represents the memory address of the task. Each task has a method tf::Task::name(const std::string&) for user to assign a human readable string to ease the debugging process. If a task is not assigned a name or is an internal node, its address value in the memory is used instead.
Unfortunately, Cpp-Taskflow is heavily relying on modern C++17's features/idoms/STL and it is very difficult to provide a version that compiles under older C++ versions.
Cpp-Taskflow has implemented different scheduler modules (centralized queue, proactive shceduler, speculative strategy, and work stealing). The default scheduler implements the famous work stealing algorithm that has shown to behave efficiently in most multicore architectures. You can find the source code at taskflow/threadpool/workstealing_threadpool.hpp
The master thread owns the thread pool and can spawn workers to run tasks or shutdown the pool. Giving taskflow N
threads means using N
threads to do the works, and there is a total of N+1
threads (including the master threads) in the program.
If there is no worker threads in the pool, the master thread will do all the works by itself. Please refer to Master, Workers, and Executor for more details.
The lifetime of a task sticks with its parent graph. A task is not destroyed until its parent graph is destroyed. Please refer to Lifetime of a Graph for more details.
No, the taskflow object is not thread-safe. You can't create tasks from multiple threads at the same time.
When the program hangs forever it is very likely your taskflow graph has a cycle. Try the tf::Taskflow::dump method to debug the graph before dispatching your taskflow graph.
No. The subflow is spawned during the execution of B, and at this point A must finish because A precedes B. This gives rise to the fact B1 and B2 must run after A. This graph may looks strange because B seems to run twice! However, Cpp-Taskflow will schedule B only once to create its subflow. Whether this subflow joins or detaches from B only affects the future object returned from B.