Logo ROOT   6.12/07
Reference Guide
mt304_AsyncNested.C File Reference

Detailed Description

View in nbviewer Open in SWAN Calculate Fibonacci numbers exploiting nested parallelism through Async.

/// \date August 2017
#include "TROOT.h"
#include "ROOT/TFuture.hxx"
#include <future>
#include <iostream>
int Fibonacci(int n)
{
if (n < 2) {
return n;
} else {
auto fut1 = ROOT::Experimental::Async(Fibonacci, n - 1);
auto fut2 = ROOT::Experimental::Async(Fibonacci, n - 2);
auto res = fut1.get() + fut2.get();
return res;
}
}
void mt304_AsyncNested()
{
std::cout << "Fibonacci(33) = " << Fibonacci(33) << std::endl;
}
int main()
{
mt304_AsyncNested();
return 0;
}
Author
Danilo Piparo

Definition in file mt304_AsyncNested.C.