fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. long int A[8000][8000];
  6. long int B[8000][8000];
  7. long int total=0;
  8. long int total1=0;
  9. long int x=(8000*8000);
  10. double Average, Average1;
  11.  
  12.  
  13. int main()
  14.  
  15. {
  16. long int i, j;
  17. clock_t start, stop;
  18. float cpuSecs;
  19. start = clock();
  20.  
  21. for (i = 0; i < 8000; i++)
  22. for (j = 0; j < 8000; j++)
  23. A[i][j]=(rand()%100); // random matrix generation ( square)
  24.  
  25.  
  26. for (i = 0; i < 8000; i++)
  27. for (j = 0; j < 8000; j++)
  28.  
  29.  
  30. total=total+A[i][j];
  31. Average=(double)total/x;
  32. printf("Average of elements of matrix calculated in row major order is %lf\n", Average);
  33.  
  34. stop = clock();
  35. cpuSecs=((float)(stop-start))/CLOCKS_PER_SEC;
  36. printf("CPU time for row major order is :%f\n",cpuSecs);
  37.  
  38.  
  39. start = clock();
  40.  
  41. for (i = 0; i < 8000; i++)
  42. for (j = 0; j < 8000; j++)
  43. B[i][j]=(rand()%100); // random matrix generation ( square)
  44.  
  45.  
  46.  
  47. for (j = 0; j < 8000; j++)
  48. for (i = 0; i < 8000; i++)
  49.  
  50. total1=total1+B[i][j];
  51. Average1=(double)total/x;
  52. printf("Average of elements of matrix calculated in column major order is %lf\n", Average1);
  53.  
  54. stop = clock();
  55. cpuSecs=((float)(stop-start))/CLOCKS_PER_SEC;
  56. printf("CPU time for column major order is :%f\n",cpuSecs);
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66.  
Success #stdin #stdout 1.82s 1001616KB
stdin
Standard input is empty
stdout
Average of elements of matrix calculated in row major order is 49.506548
CPU time for row major order is :0.813992
Average of elements of matrix calculated in column major order is 49.506548
CPU time for column major order is :0.996980