我正在尝试从雅可比松弛公式中优化除法运算。 还使用perf进行分析。 这是我的代码
for (int l = 0; l < iter; l++) {
for (i = 1; i < height; i++) {
for (j = 1; j < width; j++) {
for (k = 1; k < length; k++) {
float val = 0.0f;
// Do the Jacobi additions here
// From profiling, fastest is to fetch k+/-1,j,i
// Slowest is to fetch k,j,i+/-1
// Scale with dimensions of the array
val -= dim * array[k][j][i];
// Want to optimise this
val /= 6.0; // profiling shows this as the slowest op
// Some code here to put the result into the output array
}
}
}
}
3D阵列的大小可以是100x100x100到1000x1000x1000。
我试图将它乘以1.0f/6.0f
,但这似乎没有什么区别。该数组是一个浮动的3D数组。