Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "stdafx.h"
- #include <iostream>
- #include <omp.h>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(0));
- setlocale(0, "");
- int n = 3;
- int **a = new int*[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = new int[n];
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- if (n <= 3)
- {
- cout << "a[" << i + 1 << "][" << j + 1 << "] = ";
- cin >> a[i][j];
- }
- else
- {
- a[i][j] = rand() % 99;
- }
- }
- if (n <= 3)
- {
- cout << endl << "Матрица:" << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- int min = a[0][0], sum = 0;
- double t = omp_get_wtime();
- #pragma omp parallel num_threads(12)
- {
- #pragma omp parallel for reduction(+:sum, min) schedule(auto)
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (a[i][j] < min)
- min = a[i][j];
- }
- }
- }
- cout << endl << "минимальное значение: " << min << endl << endl;
- cout << "Time: " << omp_get_wtime() - t << endl << endl;
- for (int i = 0; i < n; i++)
- delete[]a[i];
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement