Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <omp.h>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8.  
  9. double f(double x)
  10. {
  11.     return(x * x + 2 * x);
  12. }
  13. int main()
  14. {
  15.     double xp, xk, s, dx;
  16.     int i;
  17.  
  18.     xp = 1;
  19.     xk = 14;
  20.  
  21.     const int N = 4000000;//liczba punktów/prostokątów podziałowych
  22.     cout << endl;
  23.     s = 0;
  24.     dx = (xk - xp) / N;
  25.     for (int j = 1; j<= 4; j++)
  26.     {
  27.         omp_set_num_threads(j);
  28.         double t1 = omp_get_wtime(); //znacznik czasu
  29.         #pragma omp parallel for reduction(+:s)
  30.         for (i = 1; i <= N; i++) s += f(xp + i * dx);
  31.         double t2 = omp_get_wtime(); //znacznik czasu
  32.         s *= dx;
  33.         cout << "Czas calkowania : " << t2 - t1 << " Liczba watkow : " << j <<"\n\n";
  34.     }
  35.  
  36.     cout << "Wartosc calki wynosi : " << s << "\n\n";
  37.     system("PAUSE"); return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement