cpp: void kernel_correlation(int m, int n,\nDATA_TYPE float_n,\nDATA_TYPE POLYBENCH_2D(data,M,N,m,n),\nDATA_TYPE POLYBENCH_2D(symmat,M,M,m,m),\nDATA_TYPE POLYBENCH_1D(mean,M,m),\nDATA_TYPE POLYBENCH_1D(stddev,M,m))\n{\nint i, j, j1, j2;\n\nDATA_TYPE eps = 0.1f;\n\n#define sqrt_of_array_cell(x,j) sqrt(x[j])\n\n#pragma scop\n/* Determine mean of column vectors of input data matrix */\nfor (j = 0; j < _PB_M; j++)\n{\nmean[j] = 0.0;\nfor (i = 0; i < _PB_N; i++)\nmean[j] += data[i][j];\nmean[j] /= float_n;\n}\n\n/* Determine standard deviations of column vectors of data matrix. */\nfor (j = 0; j < _PB_M; j++)\n{\nstddev[j] = 0.0;\nfor (i = 0; i < _PB_N; i++)\nstddev[j] += (data[i][j] - mean[j]) * (data[i][j] - mean[j]);\nstddev[j] /= float_n;\nstddev[j] = sqrt_of_array_cell(stddev, j);\n/* The following in an inelegant but usual way to handle\nnear-zero std. dev. values, which below would cause a zero-\ndivide. */\nstddev[j] = stddev[j] <= eps ? 1.0 : stddev[j];\n}\n\n/* Center and reduce the column vectors. */\nfor (i = 0; i < _PB_N; i++)\nfor (j = 0; j < _PB_M; j++)\n{\ndata[i][j] -= mean[j];\ndata[i][j] /= sqrt(float_n) * stddev[j];\n}\n\n/* Calculate the m * m correlation matrix. */\nfor (j1 = 0; j1 < _PB_M-1; j1++)\n{\nsymmat[j1][j1] = 1.0;\nfor (j2 = j1+1; j2 < _PB_M; j2++)\n{\nsymmat[j1][j2] = 0.0;\nfor (i = 0; i < _PB_N; i++)\nsymmat[j1][j2] += (data[i][j1] * data[i][j2]);\nsymmat[j2][j1] = symmat[j1][j2];\n}\n}\nsymmat[_PB_M-1][_PB_M-1] = 1.0;\n#pragma endscop\n\n}
fortran: subroutine kernel_correlation(m, n, float_n, dat, symmat, &\nmean, stddev)\nimplicit none\n\nDATA_TYPE, dimension(n,m) :: dat\nDATA_TYPE, dimension(m,m) :: symmat\nDATA_TYPE, dimension(m) :: stddev\nDATA_TYPE, dimension(m) :: mean\nDATA_TYPE :: float_n, EPS\ninteger :: m, n\ninteger :: i, j, j1, j2\n\nEPS = 0.1D0\n!$pragma scop\n!       Determine mean of column vectors of input data matrix\ndo j = 1, _PB_M\nmean(j) = 0.0D0\ndo i = 1, _PB_N\nmean(j) = mean(j) + dat(j, i)\nend do\nmean(j) = mean(j) / float_n\nend do\n\n!       Determine standard deviations of column vectors of data matrix.\ndo j = 1, _PB_M\nstddev(j) = 0.0D0\ndo i = 1, _PB_N\nstddev(j) = stddev(j) + (dat(j, i) - mean(j)) * (dat(j, i) - &\nmean(j))\nend do\nstddev(j) = stddev(j) / float_n\nstddev(j) = sqrt(stddev(j))\nif (stddev(j) <= EPS) then\nstddev(j) = 1.0D0\nendif\nend do\n\n!       Center and reduce the column vectors.\ndo i = 1, _PB_N\ndo j = 1, _PB_M\ndat(j, i) = dat(j, i) - mean(j)\ndat(j, i) = dat(j, i) / (sqrt(float_n) * stddev(j))\nend do\nend do\n\n!       Calculate the m * m correlation matrix.\ndo j1 = 1, _PB_M - 1\nsymmat(j1, j1) = 1.0D0\ndo j2 = j1 + 1, _PB_M\nsymmat(j2, j1) = 0.0D0\ndo i = 1, _PB_N\nsymmat(j2, j1) = symmat(j2, j1) + (dat(j1, i) * dat(j2, i))\nend do\nsymmat(j1, j2) = symmat(j2, j1)\nend do\nend do\nsymmat(_PB_M, _PB_M) = 1.0D0\n!$pragma endscop\nend subroutine