我正在嘗試使用nehalem cpu來檢測我的應用程序的性能異常,但我似乎無法達到它的單線程FP峯值性能。時鐘速度爲3.2 GHz,我希望在不使用SSE指令和多線程的情況下實現CPU的峯值FP性能。Intel Nehalem單線程峯值性能
據我所知,單精度FP加法和乘法可以在每個時鐘週期並行完成,產生2 * 3.20 = 6.4 GFLOPS/sec的最大性能。
但是我不能夠有一段簡單的代碼來達到這樣的性能:
int iterations = 1000000;
int flops_per_iteration = 2;
int num_flops = iterations * flops_per_iterations;
for(int i=0; i<iterations; i++)
{
a[i] = i;
b[i] = i*2;
c[i] = i*3;
}
tick(&start_time);
for(int i = 0; i < iterations; i++){
a[i] *= b[i];
c[i] += b[i];
}
time = tock(&start_time);
printf("Performance: %0.4f GFLOPS \n", flops/(time*pow(10,-3)*pow(10,9)));
這段代碼給我的表現:〜而不是1.5 GFLOPS 6.4 GFLOPS。
有沒有其他的例子可以在不使用MT和SSE的情況下達到峯值性能,或者我的代碼沒有任何想法?
在此先感謝
*更新:熱循環的增加彙編代碼:*
Address Assembly
Block 17:
0x4013a5 movssl (%rdi,%rax,4), %xmm2
0x4013aa movssl (%r8,%rax,4), %xmm0
0x4013b0 movssl (%rsi,%rax,4), %xmm1
0x4013b5 mulss %xmm2, %xmm0
0x4013b9 addss %xmm1, %xmm2
0x4013bd movssl %xmm0, (%r8,%rax,4)
0x4013c3 movssl %xmm2, (%rsi,%rax,4)
0x4013c8 inc %rax
0x4013cb cmp %rcx, %rax
0x4013ce jb 0x4013a5 <Block 17>
你是否嘗試過沒有數組的同樣的事情? – 2012-03-05 12:10:14
什麼是您的編譯器及其選項? – osgx 2012-03-05 12:16:23
我沒有嘗試沒有陣列實際上,我可以放棄它。我現在只用-O2進行編譯 – Ricky 2012-03-05 12:17:07