Logo ROOT   6.12/07
Reference Guide
mt304_AsyncNested.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -js
4 /// Calculate Fibonacci numbers exploiting nested parallelism through Async.
5 ///
6 /// \macro_code
7 ///
8 /// \author Danilo Piparo
9 /// \date August 2017
10 
11 #include "TROOT.h"
12 #include "ROOT/TFuture.hxx"
13 
14 #include <future>
15 #include <iostream>
16 
17 int Fibonacci(int n)
18 {
19  if (n < 2) {
20  return n;
21  } else {
22  auto fut1 = ROOT::Experimental::Async(Fibonacci, n - 1);
23  auto fut2 = ROOT::Experimental::Async(Fibonacci, n - 2);
24  auto res = fut1.get() + fut2.get();
25  return res;
26  }
27 }
28 
29 void mt304_AsyncNested()
30 {
31 
33 
34  std::cout << "Fibonacci(33) = " << Fibonacci(33) << std::endl;
35 }
36 
37 int main()
38 {
39  mt304_AsyncNested();
40  return 0;
41 }
TFuture< typename std::result_of< typename std::decay< Function >::type(typename std::decay< Args >::type...)>::type > Async(Function &&f, Args &&... args)
Runs a function asynchronously potentially in a new thread and returns a ROOT TFuture that will hold ...
Definition: TFuture.hxx:152
int main(int argc, char **argv)
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
const Int_t n
Definition: legend1.C:16