Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <time.h>
  2. #include <omp.h>
  3. #include <iostream>
  4.  
  5. #define _CRT_SECURE_NO_WARNINGS
  6.  
  7. using namespace std;
  8. #define SIZE_DARR 100000000
  9. double arr[SIZE_DARR];
  10.  
  11. void my_func(__int64 count) { // заполняет массив синусами
  12. for (__int64 i = 0; i < count; i++)
  13. arr[i] = asin((double)((i / count) % 100007));
  14. }
  15.  
  16. int main() {
  17. setlocale(LC_CTYPE, "rus"); // кириллизация
  18. double a, b, result = 0, h;
  19. clock_t t_start, time;
  20. __int64 n = 1000;
  21. cout << "Введите a: "; cin >> a;
  22. cout << "\nВведите b: "; cin >> b;
  23. my_func(1000000);
  24.  
  25. h = (b - a) / n;
  26. omp_set_dynamic(0);
  27. cout << "proc = " << omp_get_num_procs() << "\n";
  28. cout << "threads = " << omp_get_num_threads() << "\n";
  29.  
  30. for (int flow = 1; flow <= 8; flow++) {// количество потоков
  31. cout << "\n\nflow = " << flow << "\n_______________" << "\n_______________";
  32.  
  33. for (int count = 100; count < 1000000; count *= 10) { // гранулярность задачи 100-1000000
  34. t_start = clock();
  35.  
  36. # pragma omp parallel for reduction(+:result) num_threads(flow)
  37. for (int iCount = 0; iCount < count; iCount++) { // повтор count раз
  38. result = 0;
  39.  
  40. for (int i = 1; i < n; i++) { // нахождение интеграла
  41. result += asin((a + i * h) - h / 2);
  42. }
  43. result *= h;
  44. }
  45. time = clock() - t_start;
  46. cout << "\ncount = " << count;
  47. cout << "\ntime = " << time << " мс.\n____________\n";
  48. }
  49. }
  50.  
  51. system("pause");
  52. return 0;
  53. }
  54.  
  55. /*int main() {
  56. setlocale(LC_CTYPE, "rus"); // кириллизация
  57. double a, b, result = 0, h;
  58. clock_t t_start, time;
  59. __int64 n = 100000;
  60. cout << "Введите a: "; cin >> a;
  61. cout << "\nВведите b: "; cin >> b;
  62. my_func(100000);
  63.  
  64. h = (b - a) / n;
  65. omp_set_dynamic(0);
  66. //omp_set_num_threads(1);
  67. int count = 100;
  68.  
  69. for (int flow = 1; flow < 8; flow++) {
  70. t_start = clock();
  71. cout << "\nflow = " << flow << "\n_______________\n________________";
  72.  
  73. for (int j = 0; j <= count; j++) {
  74. #pragma omp parallel for reduction(+:result) num_threads(flow)// firstprivate(a)
  75. for (int i = 1; i < n; i++) {
  76. result += asin((a + i * h) - h / 2);
  77. }
  78. result *= h;
  79. }
  80. time = clock() - t_start;
  81.  
  82. cout << "\nres = " << result;
  83. cout << "\ntime = " << time << " мс.\n______________________\n";
  84.  
  85. count *= 10;
  86. }
  87. system("pause");
  88. return 0;
  89. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement