Guest User

Untitled

a guest
Jan 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/time.h>
  4. const int N = 30;
  5. const int M = 30;
  6. int A[N][M] = { 1 }, B[N][M] = { 1 };
  7. void convo(int A[N][M], int B[N][M])
  8. {
  9. for (int i = 1; i < N-1; ++i)
  10. for (int j = 1; j < M-1; ++j)
  11. B[i][j] = (A[i][j]*4 + A[i-1][j] +
  12. A[i+1][j] + A[i][j-1] + A[i][j+1])/8;
  13. }
  14.  
  15.  
  16. int main(int argc, char** argv)
  17. {
  18. int L, i;
  19. struct timeval tv1, tv2;
  20. L = atoi(argv[1]);
  21. gettimeofday(&tv1, 0);
  22. for (int i = 0; i < L; ++i)
  23. {
  24. convo(A, B);
  25. convo(B, A);
  26. }
  27. gettimeofday(&tv2, 0);
  28. printf("T = %f seconds\n",
  29. (float)((tv2.tv_usec - tv1.tv_usec)*1e-6
  30. + (tv2.tv_sec - tv1.tv_sec)));
  31. return 0; }
Add Comment
Please, Sign In to add comment