Logo ROOT   6.14/05
Reference Guide
mt302_TTaskGroupNested.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook
4 /// Calculate Fibonacci numbers exploiting nested parallelism through TTaskGroup.
5 ///
6 /// \macro_code
7 ///
8 /// \date August 2017
9 /// \author Danilo Piparo
10 
11 int Fibonacci(int n)
12 {
13  if (n < 2) {
14  return n;
15  } else {
16  int x, y;
18  tg.Run([&] { x = Fibonacci(n - 1); });
19  tg.Run([&] { y = Fibonacci(n - 2); });
20  tg.Wait();
21  return x + y;
22  }
23 }
24 
25 void mt302_TTaskGroupNested()
26 {
27 
29 
30  cout << "Fibonacci(33) = " << Fibonacci(33) << endl;
31 }
void Wait()
Wait until all submitted items of work are completed.
Definition: TTaskGroup.cxx:107
Double_t x[n]
Definition: legend1.C:17
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT&#39;s implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:576
A class to manage the asynchronous execution of work items.
Definition: TTaskGroup.hxx:21
void Run(const std::function< void(void)> &closure)
Add to the group an item of work which will be ran asynchronously.
Definition: TTaskGroup.cxx:92
Double_t y[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16