contributed by <finalallpass
>
TempoJiJi
>Louie Lu
>RayPan
>git rebase -i 812caaa2dafba0d
pick bcba26f OpenMP
s 09dc206 22:51
Author: finalallpass <thyen@hsnet.ee.ncku.edu.tw>
Date: Thu Sep 29 12:33:08 2016 +0800
Adding OpenMP support for improve performance
OpenMP can easily imporve performance by adding
one line on for loop, it still have some limit
but good enough for this case.
Performance compare with non-version:
100 202
105 495
## 參考資料
[TempoJiJI raytracing 共筆](https://hackmd.io/MYQwpgnARsBMUFoBmAWAjADgSsBmLGSuArAgAwDsFKAJmmAGxJgbFA==?view)
# Rendering scene
Done!
Execution time of raytracing() : 5.473432 sec
for (int i = 0; i < 3; i++)
out[i] = a[i] + b[i];
更改為
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
out[2] = a[2] + b[2];
得到結果
#Rendering scene
Done!
Execution time of raytracing() : 3.893162 sec
gprof分析
在時間上進步了!
# Rendering scene
Done!
Execution time of raytracing() : 2.180311 sec
沒有執行inline的話呼叫程式會去呼叫函式,有的話會在函式位置直接展開。但要展開這個函式不是也要去讀說這個函式的內容是甚麼嘛?
查了一下知道call function會有function prologue和function epilogue,這些都會衝擊效能。有關這方面的問題會再去找書來研究。
在深入了解inline的優缺點、性能及使用指南中有提到說:May increase function size so that it may not fit on the cache, causing lots of cahce miss.這個缺點,所以我嘗試用phonebook中的perf工具來驗證cache-misses的問題。
使用inline之前:
200,289 cache-misses # 20.294 % of all cache refs
797,136 cache-references
26,722,398,637 instructions # 2.22 insns per cycle
11,965,663,673 cycles
212,135 cache-misses # 28.161 % of all cache refs
637,978 cache-references
13,560,212,154 instructions # 2.06 insns per cycle
6,585,484,004 cycles
相差了大約8%。不知道如果展開的函式越長會不會差異愈大。
# Rendering scene
Done!
Execution time of raytracing() : 1.663272 sec
這邊不是很懂thread的數目跟core的數量間的關係。
用lscpu得到我的threaf per core是1,所以照裡來說我應該一次只能執行4個thread才對,但是num_threads輸入8的效能會明顯比4還要好。
參考網址看了這篇之後,覺得應該可以想成一張桌子只能一人使用,但前一人再結束階段時後面排隊的可以先使用桌子進行準備的感覺。不過這樣要如何知道我要同時開多少thread來讓效能最佳化呢?