Did anyone try to run the fibonacci sequence computation with OpenMP tasks like stated in the IWOMP 2010 tutorial.

I've tried to run the code below but no speedup achieved and the program hangs for n = 40; The Iwomp 2010 material ( slide 124 of OpenMP overview) states that there's a approximatively x2 speedup.

Can someone help me explain this ??

Thanks

- Code: Select all
`/* File : fibonacci.c`

* Computes fibonacci numbers

* Last modified : 2011-04-25

*/

#include <stdio.h>

//#define NUM_THREADS 2

/* function that uses recursivity

* to compute fibonacci numbers

*/

long comp_fib_numbers(int n)

{

// Basic algorithm: f(n) = f(n-1) + f(n-2)

long fnm1, fnm2, fn;

if ( n == 0 || n == 1 ) return(n);

#pragma omp task shared(fnm1)

fnm1 = comp_fib_numbers(n-1);

#pragma omp task shared(fnm2)

fnm2 = comp_fib_numbers(n-2);

#pragma omp taskwait

fn = fnm1 + fnm2;

return(fn);

}

int main(int argc, char **argv)

{

int n;

long result;

if(argc<2){

printf("usage ./fibonacci <number>\n");

exit(1);

}

n = atoi(argv[1]);

//#pragma omp parallel num_threads(NUM_THREADS)

#pragma omp parallel

{

#pragma omp single nowait

{

result = comp_fib_numbers(n);

} // end of single region

} // end of parallel region

printf("finonacci(%d) = %ld\n", n, result);

return 0;

}