Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <chrono>
- using namespace std;
- using namespace std::chrono;
- int MAX = 100;
- int n;
- void print_array(int **a) {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- milliseconds job( int n)
- {
- int **a, **b, **c;
- a = (int**)malloc(n*sizeof(int*));
- b = (int**)malloc(n*sizeof(int*));
- c = (int**)malloc(n*sizeof(int*));
- for (int i = 0; i < n; i++)
- {
- int *x = (int*)malloc(n*sizeof(int));
- for (int j = 0; j < n; j++)
- {
- x[j] = rand()%100;
- }
- a[i] = x;
- }
- for (int i = 0; i < n; i++)
- {
- int *x = (int*)malloc(n*sizeof(int));
- int *y = (int*)malloc(n*sizeof(int));
- for (int j = 0; j < n; j++)
- {
- x[j] = rand()%100;
- y[j] = rand()%100;
- }
- b[i] = x;
- c[i] = y;
- }
- // print_array(a);
- // print_array(b);
- clock_t tic = clock();
- auto strt = duration_cast< milliseconds >(system_clock::now().time_since_epoch());
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- c[i][j]=0;
- for (int k = 0; k < n; k++)
- {
- c[i][j] += a[i][k]*b[k][j];
- }
- }
- }
- auto stop = duration_cast< milliseconds >(system_clock::now().time_since_epoch());
- clock_t tac = clock();
- //printf("Elapsed: %f seconds\n", (double)(tac - tic) / CLOCKS_PER_SEC);
- //print_array(c);
- free(a);
- free(b);
- free(c);
- return stop-strt;
- }
- int main(int argc, char** argv)
- {
- int n = atoi(argv[1]);
- cout << "n : " << n << "time: " << endl;
- job(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement