cpp: void kernel_covariance(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))\n{\nint i, j, j1, j2;\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/* Center the column vectors. */\nfor (i = 0; i < _PB_N; i++)\nfor (j = 0; j < _PB_M; j++)\ndata[i][j] -= mean[j];\n\n/* Calculate the m * m covariance matrix. */\nfor (j1 = 0; j1 < _PB_M; j1++)\nfor (j2 = j1; 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#pragma endscop\n\n}
fortran: subroutine kernel_covariance(m, n, float_n, dat, symmat, mean)\nimplicit none\n\nDATA_TYPE, dimension(m, m) :: symmat\nDATA_TYPE, dimension(n, m) :: dat\nDATA_TYPE, dimension(m) :: mean\nDATA_TYPE :: float_n\ninteger :: m, n\ninteger :: i, j, j1, j2\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!       Center the column vectors.\ndo i = 1, _PB_N\ndo j = 1, _PB_M\ndat(j, i) = dat(j, i) - mean(j)\nend do\nend do\n\n!       Calculate the m * m covariance matrix.\ndo j1 = 1, _PB_M\ndo j2 = j1, _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\n!$pragma endscop\nend subroutine