11 Type fn_2 = 0, fn_1 = 1, fn;
13 for(Type i = 2; i <= n; ++i)
17 fn_2 = fn_1; fn_1 = fn;
24template<
typename Type>
33template<
typename Type,
auto go_serial =
Type{16} >
40 using base = tbb::task;
43 fibonacci(Type n, Type*
const fn_ptr): m_n{n}, m_fn_ptr{fn_ptr} { }
55 auto& task_n_2 = *
new(base::allocate_child())
fibonacci{m_n-2, &fn_2};
56 auto& task_n_1 = *
new(base::allocate_child())
fibonacci{m_n-1, &fn_1};
58 base::set_ref_count(3);
60 base::spawn(task_n_1);
61 base::spawn_and_wait_for_all(task_n_2);
63 *m_fn_ptr = fn_2 + fn_1;
70template<
typename Type>
75 auto& task = *
new(tbb::task::allocate_root())
fibonacci{n, &fn};
77 tbb::task::spawn_root_and_wait(task);
84 for(
int i=0; i <= 10; ++i)
Type fibonacci_recursion(Type n)
Type fibonacci_loop(Type n)
Type parallel_fibonacci(Type n)
fibonacci(Type n, Type *const fn_ptr)
base * execute() override