diff --git a/codes/correlation/correlation.c b/codes/correlation/correlation.c index 6e814357eb23b66eaf38e65edb02ec47cf56ef10..20f38d18275333cc7b88de7f7f2ba5b59bc32462 100644 --- a/codes/correlation/correlation.c +++ b/codes/correlation/correlation.c @@ -38,6 +38,22 @@ void init_array (int m, } +static +void calc_error(int m, + DATA_TYPE POLYBENCH_2D(corr,M,M,m,m)) + +{ + int i, j; + double error = 0; + + for (i = 0; i < m; i++) + for (j = 0; j < m; j++) { + error += (corr[i][j] - 1.0)*(corr[i][j] - 1.0); + } + error /= m*m; + error = sqrtf(error); + printf("error: %f\n", error); +} /* DCE code. Must scan the entire live-out data. Can be used also to check the correctness of the output. */ @@ -158,6 +174,9 @@ int main(int argc, char** argv) by the function call in argument. */ polybench_prevent_dce(print_array(m, POLYBENCH_ARRAY(corr))); + /* calculate error */ + calc_error(m, POLYBENCH_ARRAY(corr)); + /* Be clean. */ POLYBENCH_FREE_ARRAY(data); POLYBENCH_FREE_ARRAY(corr);