Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22300

OpenMP parallel program of Fibonacci is slower than sequential

$
0
0

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?


Viewing all articles
Browse latest Browse all 22300

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>