Advertisement
Guest User

fiboparallel.c

a guest
Oct 23rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <omp.h>
  3. int fibonacci(int n){
  4.     int i,j;
  5.     if(n<2) return n;
  6.     else{
  7.         #pragma omp task shared(i)
  8.         i = fibonacci(n-1);
  9.         #pragma omp task shared(j)
  10.         j = fibonacci(n-2);
  11.         #pragma omp taskwait
  12.         return i+j;
  13.     }
  14. }
  15.  
  16.  
  17. int main(){
  18.     int fibN;
  19.     omp_set_num_threads(4);
  20.     #pragma omp parallel
  21.     {
  22.         #pragma omp single nowait
  23.         fibN = fibonacci(27);
  24.     }
  25.     printf("%d",fibN);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement