glo
glo

Reputation: 85

OpenMP parallel program of Fibonacci is slower than sequential

I have this sequential code:

int fib(int n) {
int x, y;

if (n < 2)
return n;
x = fib(n-1);
y = fib(n-2);
return x + y;
}

And this parallel code:

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;
}

The openmp parallel code is slower than serial. I use tdm-gcc 7.4. I have no other program open at Fibonacci runtime. What's wrong?

Upvotes: 0

Views: 329

Answers (0)

Related Questions