Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iomanip>
- #include <iostream>
- #include <omp.h>
- #include <fstream>
- using namespace std;
- double f(double x)
- {
- return(x * x + 2 * x);
- }
- int main()
- {
- double xp, xk, s, dx;
- int i;
- xp = 1;
- xk = 14;
- const int N = 4000000;//liczba punktów/prostokątów podziałowych
- cout << endl;
- s = 0;
- dx = (xk - xp) / N;
- for (int j = 1; j<= 4; j++)
- {
- omp_set_num_threads(j);
- double t1 = omp_get_wtime(); //znacznik czasu
- #pragma omp parallel for reduction(+:s)
- for (i = 1; i <= N; i++) s += f(xp + i * dx);
- double t2 = omp_get_wtime(); //znacznik czasu
- s *= dx;
- cout << "Czas calkowania : " << t2 - t1 << " Liczba watkow : " << j <<"\n\n";
- }
- cout << "Wartosc calki wynosi : " << s << "\n\n";
- system("PAUSE"); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement