Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/time.h>
- const int N = 30;
- const int M = 30;
- int A[N][M] = { 1 }, B[N][M] = { 1 };
- void convo(int A[N][M], int B[N][M])
- {
- for (int i = 1; i < N-1; ++i)
- for (int j = 1; j < M-1; ++j)
- B[i][j] = (A[i][j]*4 + A[i-1][j] +
- A[i+1][j] + A[i][j-1] + A[i][j+1])/8;
- }
- int main(int argc, char** argv)
- {
- int L, i;
- struct timeval tv1, tv2;
- L = atoi(argv[1]);
- gettimeofday(&tv1, 0);
- for (int i = 0; i < L; ++i)
- {
- convo(A, B);
- convo(B, A);
- }
- gettimeofday(&tv2, 0);
- printf("T = %f seconds\n",
- (float)((tv2.tv_usec - tv1.tv_usec)*1e-6
- + (tv2.tv_sec - tv1.tv_sec)));
- return 0; }
Add Comment
Please, Sign In to add comment