Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <omp.h>
- using namespace std;
- class M {
- public:
- vector<vector<int> >v;
- int n;
- M()
- {
- n = 0;
- }
- M(int n) :n(n)
- {
- v.resize(n, vector<int>(n, 1));
- }
- M operator*(M& b)
- {
- M c(n);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- c.v[i][j] = 0;
- // c.display();
- cout << '\n';
- double t1 = omp_get_wtime();
- omp_set_num_threads(4);
- #pragma omp parallel for
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- for (int k = 0; k < n; k++)
- c.v[i][j] += v[i][k] * b.v[k][j];
- double t2 = omp_get_wtime();
- cout << t2 - t1;
- cout << '\n';
- return c;
- }
- void display()
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout << v[i][j] << ' ';
- cout << '\n';
- }
- }
- void in()
- {
- for (auto& i : v)
- for (auto& j : i)
- cin >> j;
- }
- };
- int main()
- {
- int n;
- cin >> n;
- M a(n);
- M b(n);
- a.in();
- b.in();
- M c = (a * b);
- //a.display();
- cout << '\n';
- //b.display();
- cout << '\n';
- c.display();
- cout << '\n';
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement