int main(int argc, char * argv[]) { const int BASE = 1024; int t; struct timeval start, end; int N_SIZE = 0, T_SIZE = 0; if (argc < 3) { printf("argc < 3, quit! \n"); exit(1); } N_SIZE = StrToInt(argv[1]); T_SIZE = StrToInt(argv[2]); printf("N_SIZE = %d, T_SIZE = %d\n", N_SIZE, T_SIZE); /* Known */ Pochoir_Shape <1> heat_shape_1D [4] = {{0, 0}, {-1, 1}, {-1, 0}, {-1, -1}}; /* toggle: 2; slopes: [1] */ /* Known*/ Pochoir_Array <double, 1> a ( N_SIZE ) , b ( N_SIZE ) ; /* Known */a.Register_Shape(heat_shape_1D); a.Register_Boundary(aperiodic_1D); /* Register_Boundary */ /* Known */b.Register_Shape(heat_shape_1D); b.Register_Boundary(aperiodic_1D); /* Register_Boundary */ for (int i = 0; i < N_SIZE; ++i) { a(0, i) = 1.0 * (rand() % BASE); a(1, i) = 0; b(0, i) = a(0, i); b(1, i) = 0; } cout << "a(T+1, J) = 0.125 * (a(T, I+1) - 2.0 * a(T, I) + a(T, I-1)) + a(T, I)" << endl; gettimeofday(&start, 0); for (int times = 0; times < 1; ++times) { for (int t = 0; t < T_SIZE; ++t) { for (int i = 0; i <= N_SIZE-1; ++i) { a(t+1, i) = 0.125 * (a(t, i+1) - 2.0 * a(t, i) + a(t, i-1)) + a(t, i); } } } gettimeofday(&end, 0); std::cout << "Pochoir ET: consumed time :" << 1.0e3 * tdiff(&end, &start)/1 << "ms" << std::endl; gettimeofday(&start, 0); for (int times = 0; times < 1; ++times) { for (int t = 0; t < T_SIZE; ++t) { _Cilk_for (int i = 0; i <= N_SIZE-1; ++i) { b(t+1, i) = 0.125 * (b(t, i+1) - 2.0 * b(t, i) + b(t, i-1)) + b(t, i); } } } gettimeofday(&end, 0); std::cout << "Naive Loop: consumed time :" << 1.0e3 * tdiff(&end, &start)/1 << "ms" << std::endl; t = T_SIZE; for (int i = 0; i <= N_SIZE-1; ++i) { check_result(t, i, a.interior(t, i), b.interior(t, i)); } return 0; }
int main(int argc, char * argv[]) { const int BASE = 1024; int t; struct timeval start, end; int N_SIZE = 0, T_SIZE = 0; if (argc < 3) { printf("argc < 3, quit! \n"); exit(1); } N_SIZE = StrToInt(argv[1]); T_SIZE = StrToInt(argv[2]); printf("N_SIZE = %d, T_SIZE = %d\n", N_SIZE, T_SIZE); /* Known */ Pochoir_Shape <2> heat_shape_2D [6] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}, {0, -1, 0}, {0, 0, -1}, {0, 0, 1}}; Pochoir<2> heat_2D(heat_shape_2D); /* Known*/ Pochoir_Array <double, 2> a ( N_SIZE, N_SIZE ) , b ( N_SIZE, N_SIZE ) ; /* Known */a.Register_Shape(heat_shape_2D); a.Register_Boundary(periodic_2D); /* Register_Boundary */ heat_2D.Register_Array(a); /* Known */b.Register_Shape(heat_shape_2D); b.Register_Boundary(periodic_2D); /* Register_Boundary */ for (int i = 0; i < N_SIZE; ++i) { for (int j = 0; j < N_SIZE; ++j) { a(0, i, j) = 1.0 * (rand() % BASE); a(1, i, j) = 0; b(0, i, j) = a(0, i, j); b(1, i, j) = 0; } } cout << "a(T+1, J, I) = 0.125 * (a(T, J+1, I) - 2.0 * a(T, J, I) + a(T, J-1, I)) + 0.125 * (a(T, J, I+1) - 2.0 * a(T, J, I) + a(T, J, I-1)) + a(T, J, I)" << endl; gettimeofday(&start, 0); for (int times = 0; times < 1; ++times) { for (int t = 0; t < T_SIZE; ++t) { for (int i = 0; i < N_SIZE; ++i) { for (int j = 0; j < N_SIZE; ++j) { a(t+1, i, j) = 0.125 * (a(t, i+1, j) - 2.0 * a(t, i, j) + a(t, i-1, j)) + 0.125 * (a(t, i, j+1) - 2.0 * a(t, i, j) + a(t, i, j-1)) + a(t, i, j); } } } } gettimeofday(&end, 0); std::cout << "Pochoir : consumed time :" << 1.0e3 * tdiff(&end, &start)/1 << "ms" << std::endl; gettimeofday(&start, 0); for (int times = 0; times < 1; ++times) { for (int t = 0; t < T_SIZE; ++t) { cilk_for (int i = 0; i < N_SIZE; ++i) { for (int j = 0; j < N_SIZE; ++j) { b(t+1, i, j) = 0.125 * (b(t, i+1, j) - 2.0 * b(t, i, j) + b(t, i-1, j)) + 0.125 * (b(t, i, j+1) - 2.0 * b(t, i, j) + b(t, i, j-1)) + b(t, i, j); } } } } gettimeofday(&end, 0); std::cout << "Naive Loop: consumed time :" << 1.0e3 * tdiff(&end, &start)/1 << "ms" << std::endl; t = T_SIZE; for (int i = 0; i <= N_SIZE-1; ++i) { for (int j = 0; j <= N_SIZE-1; ++j) { check_result(t, i, j, a.interior(t, i, j), b.interior(t, i, j)); } } return 0; }