Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<omp.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int getNumarValoriFibonacci(int n)
  9. {
  10.     return (int)(log(sqrt(5)*n) / log((1 + sqrt(5)) / 2));
  11. }
  12.  
  13.  
  14. void fibonnaci(int n)
  15. {
  16.  
  17.     long long t1 = 0, t2 = 1, nextTerm;
  18.     nextTerm = t1 + t2;
  19.     cout << endl << nextTerm;
  20.  
  21.     int numarValoriFibonacci = getNumarValoriFibonacci(n);
  22.  
  23.  
  24. #pragma omp parallel for num_threads(4) firstprivate(t1,t2, nextTerm)
  25.     for (int i=1; i<=numarValoriFibonacci;i++)
  26.     {
  27.         t1 = t2;
  28.         t2 = nextTerm;
  29.         nextTerm = t1 + t2;
  30.  
  31. #pragma omp critical
  32.         cout << endl << nextTerm;
  33.     }
  34.  
  35. }
  36.  
  37. void main()
  38. {
  39.     fibonnaci(100);
  40.     //getNumarValoriFibonacci(5);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement