Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<omp.h>
- using namespace std;
- int getNumarValoriFibonacci(int n)
- {
- return (int)(log(sqrt(5)*n) / log((1 + sqrt(5)) / 2));
- }
- void fibonnaci(int n)
- {
- long long t1 = 0, t2 = 1, nextTerm;
- nextTerm = t1 + t2;
- cout << endl << nextTerm;
- int numarValoriFibonacci = getNumarValoriFibonacci(n);
- #pragma omp parallel for num_threads(4) firstprivate(t1,t2, nextTerm)
- for (int i=1; i<=numarValoriFibonacci;i++)
- {
- t1 = t2;
- t2 = nextTerm;
- nextTerm = t1 + t2;
- #pragma omp critical
- cout << endl << nextTerm;
- }
- }
- void main()
- {
- fibonnaci(100);
- //getNumarValoriFibonacci(5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement