我正在使用Gauss-Seidel方法编写稀疏矩阵求解器.通过剖析,我已经确定我的程序的大约一半时间花在解算器中.性能关键部分如下:
size_t ic = d_ny + 1, iw = d_ny, ie = d_ny + 2, is = 1, in = 2 * d_ny + 1;
for (size_t y = 1; y < d_ny - 1; ++y) {
for (size_t x = 1; x < d_nx - 1; ++x) {
d_x[ic] = d_b[ic]
- d_w[ic] * d_x[iw] - d_e[ic] * d_x[ie]
- d_s[ic] * d_x[is] - d_n[ic] * d_x[in];
++ic; ++iw; ++ie; ++is; ++in;
}
ic += 2; iw += 2; …Run Code Online (Sandbox Code Playgroud) 是什么原因导致第一个数据集的执行时间增加了?装配说明是相同的.
如果DN_FLUSH标志未打开,则第一个数据集需要63毫秒,第二个数据集需要15毫秒.
在DN_FLUSH标志打开的情况下,第一个数据集需要15毫秒,第二个数据集需要约0毫秒.
因此,在这两种情况下,第一数据集的执行时间都要大得多.
有没有办法减少执行时间与第二个数据集更接近?
我正在使用C++ Visual Studio 2005,/ arch:SSE2/fp:在Intel Core 2 Duo T7700 @ 2.4Ghz Windows XP Pro上快速运行.
#define NUMLOOPS 1000000
// Denormal values flushed to zero by hardware on ALPHA and x86
// processors with SSE2 support. Ignored on other x86 platforms
// Setting this decreases execution time from 63 milliseconds to 16 millisecond
// _controlfp(_DN_FLUSH, _MCW_DN);
float denormal = 1.0e-38;
float denormalTwo = 1.0e-39;
float denormalThree = 1;
tickStart = GetTickCount();
// Run First Calculation Loop
for …Run Code Online (Sandbox Code Playgroud)