Advertisement
Guest User

Untitled

a guest
May 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <pthread.h>
  3. #include <ctime>
  4. #include <stdio.h>
  5.  
  6. #define n 20000
  7. #define m 20000
  8.  
  9. void sequial(int **matr);
  10. void fill_matr(int **matr);
  11.  
  12. int main()
  13. {
  14.     srand(time(0));
  15.  
  16.     try
  17.     {
  18.         int **matr = new int*[n];
  19.         for(int i = 0; i < n; ++i)
  20.             matr[i] = new int[m];
  21.  
  22.         fill_matr(matr);
  23.         sequial(matr);
  24.  
  25.         for(int i = 0; i < n; ++i)
  26.             delete[] matr[i];
  27.         delete matr;
  28.  
  29.     }
  30.     catch(...)
  31.     {
  32.        printf("Error!\n");
  33.        return 0;
  34.     }
  35.  
  36.     system("pause");
  37.     return 0;
  38. }
  39.  
  40. void sequial(int **matr)
  41. {
  42.     int my_max = 0;
  43.     clock_t my_time = clock();
  44.  
  45.     for(int i = 0; i < n; ++i)
  46.     {
  47.         for(int j = i; j < m; ++j)
  48.         {
  49.            if(my_max < matr[i][j]) my_max = matr[i][j];
  50.         }
  51.     }
  52.  
  53.     my_time = clock() - my_time;
  54.     printf("sequial:\tmax_el = %i\ttime: %.6lf\n", my_max, (double)my_time/CLOCKS_PER_SEC);
  55. }
  56.  
  57. void fill_matr(int **matr)
  58. {
  59.     for(int i = 0; i < n; ++i)
  60.     {
  61.         for(int j = i; j < m; ++j)
  62.         {
  63.             matr[i][j] = rand() % 3000;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement