Advertisement
Tvor0zhok

ParProg2 (3)

Sep 27th, 2023
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. // https://drive.google.com/drive/folders/1GK3t7PBsRFQp01ApEmk1wb6Scrw_CFA4?usp=sharing
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <ctime>
  6. #include <cmath>
  7. #include <ppl.h>
  8. using namespace std;
  9.  
  10. #define N 50'000'000
  11. #define EPS 1e-9
  12.  
  13. double fun(double x)
  14. {
  15.     double x_2 = x * x;
  16.  
  17.     return x_2 / (1 + x_2) * sin(x);
  18. }
  19.  
  20. vector<double> res1(N + 7), res2(N + 7), res3(N + 7);
  21.  
  22. int main()
  23. {
  24.     setlocale(LC_ALL, "Russian");
  25.  
  26.     for (int i = 0; i < N; ++i)
  27.         res1[i] = res2[i] = res3[i] = fun(i);
  28.  
  29.     auto t_start = clock();
  30.  
  31.     sort(res1.begin(), res1.end());
  32.  
  33.     auto t_end = clock();
  34.  
  35.     double time1 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
  36.  
  37.     cout << "Последовательная реализация: " << time1 << "\n";
  38.  
  39.     t_start = clock();
  40.  
  41.     concurrency::parallel_sort(res2.begin(), res2.end());
  42.  
  43.     t_end = clock();
  44.  
  45.     double time2 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
  46.  
  47.     cout << "Параллельная реализация (parallel_sort): " << time2 << "\n";
  48.  
  49.     cout << "Разница во времени: " << time1 / time2 << "\n";
  50.  
  51.     t_start = clock();
  52.  
  53.     concurrency::parallel_buffered_sort(res3.begin(), res3.end());
  54.  
  55.     t_end = clock();
  56.  
  57.     double time3 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
  58.  
  59.     cout << "Параллельная реализация (parallel_buffered_sort): " << time3 << "\n";
  60.  
  61.     cout << "Разница во времени: " << time1 / time3 << "\n";
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement