// Use of OpenMP tasks to compute fibonacci(45) #include using namespace std; int fib(int n) { int x, y; if (n < 2) return n; #pragma omp task shared(x) x = fib(n-1); #pragma omp task shared(y) y = fib(n-2); #pragma omp taskwait return x + y; } int main() { int res, n = 45; // parallel section but one thread will // lauch the function fib() #pragma omp parallel { #pragma omp single { res = fib(n); } } cout << "res=" << res << endl; return 0; }