#include #include #include #include "mf_pragma.h" int main (int argc, char *argv[]) { int T = 4, N = 1026, x = 11, B = 128; if (argc > 1 && argc != 4) { printf("usage: ./jacobi iterations input_size block_size\n"); exit(0); } if (argc == 4) { T = atoi(argv[1]); N = atoi(argv[2]); B = atoi(argv[3]); } int a[N], b[N], c[N], d[N]; srand (time(NULL)); for (int i = 0; i < N; ++i) { a[i] = rand() % x; c[i] = a[i]; } int ub_v = (N - 2) / B; meta_schedule { for (int t = 0; t < T; ++t) { meta_for (int v = 0; v < ub_v; v++) { meta_for (int u = 0; u < B; u++) { int p = v * B + u; b[p+1] = (a[p] + a[p+1] + a[p+2]) / 3; } } meta_for (int v = 0; v < ub_v; v++) { meta_for (int u = 0; u < B; u++) { int w = v * B + u; a[w+1] = b[w+1]; } } } } // serial jacabi code for (int t = 0; t < T; ++t) { for (int i = 0; i < N-2; ++i) d[i+1] = (c[i] + c[i+1] + c[i+2]) / 3; for (int i = 0; i < N-2; ++i) c[i+1] = d[i+1]; } // compare the result of serial code and parallel code and verify the validation int isCorrect = 1; for (int i = 0; i < N; i++){ if (c[i] != a[i]) { printf("== [%d] ==\n", i); printf("%d :: %d\n", c[i], a[i]); isCorrect = 0; } } if (isCorrect) { printf("pass.\n"); } return 0; }