Consider following Program calculating Fibonacci Numbers.
It uses OpenMP Tasks for parallelisation.
#include <iostream>
#include <omp.h>
using namespace std;
int fib(int n)
{
if(n == 0 || n == 1)
return n;
int res, a, b;
#pragma omp parallel
{
#pragma omp single
{
#pragma omp task shared(a)
a = fib(n-1);
#pragma omp task shared(b)
b = fib(n-2);
#pragma omp taskwait
res = a+b;
}
}
return res;
}
int main()
{
cout << fib(40);
}
I use gcc version 4.8.2 and Fedora 20.
When compiling the above program with g++ -fopenmp name_of_program.cpp -Wall
and running it, I see when looking into htop that only two (sometimes 3) threads are running.
The machine I'm running this program on has 8 logical CPUs.
My question is, what do I need to do to offload the work onto 8 Threads.
I tried export OMP_NESTED=TRUE, but this leads to following error while running the
Program:
libgomp: Thread creation failed: Resource temporarily unavailable
The point of my program is not to efficiently compute Fibonacci Numbers, but to
use tasks or something similar in OpenMP.