Logo ROOT   6.12/07
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  if( n<2 ) {
13  return n;
14  } else {
15  int x, y;
17  tg.Run([&]{x=Fibonacci(n-1);});
18  tg.Run([&]{y=Fibonacci(n-2);});
19  tg.Wait();
20  return x+y;
21  }
22 }
23 
24 void mt302_TTaskGroupNested()
25 {
26 
28 
29  cout << "Fibonacci(33) = " << Fibonacci(33) << endl;
30 
31 }
32 
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:555
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