Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <omp.h>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. srand(time(0));
  12. setlocale(0, "");
  13. int n = 3;
  14. int **a = new int*[n];
  15. for (int i = 0; i < n; i++)
  16. {
  17. a[i] = new int[n];
  18. }
  19.  
  20. for (int i = 0; i < n; i++)
  21. for (int j = 0; j < n; j++)
  22. {
  23. if (n <= 3)
  24. {
  25. cout << "a[" << i + 1 << "][" << j + 1 << "] = ";
  26. cin >> a[i][j];
  27. }
  28. else
  29. {
  30. a[i][j] = rand() % 99;
  31. }
  32. }
  33.  
  34. if (n <= 3)
  35. {
  36. cout << endl << "Матрица:" << endl;
  37. for (int i = 0; i < n; i++)
  38. {
  39. for (int j = 0; j < n; j++)
  40. {
  41. cout << a[i][j] << " ";
  42. }
  43. cout << endl;
  44. }
  45. }
  46.  
  47. int min = a[0][0], sum = 0;
  48. double t = omp_get_wtime();
  49. #pragma omp parallel num_threads(12)
  50. {
  51. #pragma omp parallel for reduction(+:sum, min) schedule(auto)
  52. for (int i = 0; i < n; i++)
  53. {
  54. for (int j = 0; j < n; j++)
  55. {
  56. if (a[i][j] < min)
  57. min = a[i][j];
  58. }
  59.  
  60. }
  61. }
  62. cout << endl << "минимальное значение: " << min << endl << endl;
  63. cout << "Time: " << omp_get_wtime() - t << endl << endl;
  64.  
  65. for (int i = 0; i < n; i++)
  66. delete[]a[i];
  67.  
  68. system("pause");
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement