Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using of tasks in openmp for recursive calls
- #include "stdio.h"
- int com_fib(int n)
- {
- int f,fn2,fn1;
- // f(n) = f(n-1) + f(n-2)
- if(n == 0||n == 1) return n;
- if ( n < 20 ) return(com_fib(n-1) + com_fib(n-2));
- #pragma omp task shared(fn1)
- { fn1 = com_fib(n-1); }
- #pragma omp task shared(fn2)
- { fn2 = com_fib(n-2); }
- #pragma omp taskwait
- f = fn1 + fn1;
- return f;
- }
- void main(int argc, char *argv[])
- {
- int result;
- // printf("arg is %dn", atoi(argv[1]) );
- #pragma omp parallel
- {
- #pragma omp single nowait
- {
- result = com_fib(atoi(argv[1]));
- } // End of single
- } // End of parallel region
- printf("Fib is %dn", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment