相关文章推荐
礼貌的绿茶  ·  Android animation停止 - ...·  1 年前    · 
星星上的铅笔  ·  std::jthread与std::thre ...·  2 年前    · 
热心肠的人字拖  ·  Dynamic M query ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have tried out the taskflow librabry https://github.com/taskflow/taskflow for c++ and got one most basic program running. Next, I wanted to adopt this example https://www.cs.cmu.edu/~15210/pasl.html#_parallel_fibonacci of calculating Fibonacci numbers while using the taskflow library.

Now, I get a error message which I don't understand. Maybe you people here can help me. The eror message says:

abort() has been called
(Press Retry to debug the application)
Ausnahme ausgelöst bei 0x760A4402 in TestTaskFlow.exe: Microsoft C++-Ausnahme: std::system_error bei Speicherort 0x220BE0F0.
TestTaskFlow.exe hat einen Haltepunkt ausgelöst.

Translation:

Exception thrown at 0x760A4402 in TestTaskFlow.exe: Microsoft C++-Exception: std::system_error at memory 0x220BE0F0.
TestTaskFlow.exe has triggered a breakpoint.

My code looks like this:

#include <iostream>
#include <stdio.h>
#include <taskflow.hpp>
F(n) = F(n-1) + F(n-2)
// parallel calculation of F(n)
long fib_par(long n) {
    long result;
    if (n < 2) {
        result = n;
    else {
        tf::Taskflow tf;
        long a, b;
        tf::Task taskA = tf.emplace([&]()
                a = fib_par(n - 1);
        tf::Task taskB = tf.emplace([&]()
                b = fib_par(n - 2);
        tf::Task taskResult = tf.emplace([&]()
                result = a + b;
        taskA.precede(taskResult);
        taskB.precede(taskResult);
        tf::Executor().run(tf);
    return result;
int main() {
    int n(40);
    long par = fib_par(n);
    return 0;

So the question is: What am I doing wrong? Thank you.

Start your program in a debugger and find out the line of the of the crash and the stacktrace. – Thomas Sablik Jun 24, 2020 at 9:05 I would say is a bad idea to put tf::Taskflow tf inside your function. As far as there is no debugging details I am there is no way to tell what is exactly the problem. Even more it is specific to taskflow. – armagedescu Jun 24, 2020 at 9:22

The problem is that you are recursively creating Taskflow and Executor instances. The executor manages the workers and the task queue, creating separate instances for each call means there is no overall management of the tasks. Each executor will create at least one worker and the number of workers created will be >= n!. And by creating separate taskflows the executors can't see the overall graph, all they can see are the three tasks.

There is a fibonacci example in taskflow handbook now. I rewrote the example to use your variable names and stripped out the graph printing.

int fib_par(int n, tf::Subflow &sbf) {
    if (n < 2) return n;
    int a, b;
    sbf.emplace([&a, n](tf::Subflow &sbf) {
        a = fib_par(n - 1, sbf);
    sbf.emplace([&b, n](tf::Subflow &sbf) {
        b = fib_par(n - 2, sbf);
    sbf.join();
    return a + b;
int main(int argc, char *argv[]) {
    int n = 10;
    int par;
    tf::Executor executor;
    tf::Taskflow taskflow;
    taskflow.emplace([&par, n](tf::Subflow &sbf) {
        par = fib_par(n, sbf);
    executor.run(taskflow).wait();
    std::cout << "Fib[" << n << "]: " << par << std::endl;
    return 0;

The key here is the use of dynamic tasking. emplaceing a callable that takes a tf::Subflow parameter creates a dynamic task which can extend the task graph by creating sub-graphs. This is all managed by the single executor declared in main, which becomes aware of the new preceding tasks with the call to sbf.join() in fib_par.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.