Parallel Programming HW2 @NYCU, 2022 Fall
Q1
In your write-up, produce a graph of speedup compared to the reference sequential implementation as a function of the number of threads used FOR VIEW 1.

Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Is speedup linear in the number of threads used?
view1 的 speedup 和 thread number 非線性
view2 的 speedup 和 thread number 線性
In your writeup hypothesize why this is (or is not) the case?
- view1 的圖有黑白區塊非常明顯,黑白區塊在做運算時所花的時間不同,因此不同thread會有不同的運算時間。
- view2 的圖無太大顏色改變,所以在運算上的時間差不多,thread 數量和speedup 呈線性。
Q2 How do your measurements explain the speedup graph you previously created?
View1 因為每個 thread 工作量分配不均的關係,圖片中白色區塊的部份會花比較多計算,所以在不同 thread 數量下的 speedup 之所以沒有成線性成長。
view1 實驗結果
圖片分配thread 狀況:

- 由實驗結果可以看到
- 3 個 thread時,thread 1 所花的時間比 thread 0, 2 還要多
- 4 個 thread時,thread 1,2 所花的時間比 thread 0, 3 還要多
- 由圖片切割可以看出
- 3 個 thread時,thread 1 要處理圖片中間那一塊,有比較多白色的區塊
- 4 個 thread時,thread 1,2 要處理圖片中間那二塊,有比較多白色的區塊
Q3
In your write-up, describe your approach to parallelization
我使用的方法是把圖切成很多區塊,並且讓每一個thread 都平均分配,讓每個thread 的工作量差不多。
如下圖與程式:

Report the final 4-thread speedup obtained.
view1
view2
Q4
在performance 上, 8 thread並沒有比 4 thread有顯著的進步。
|
view1 |
view2 |
4-thread |
3.79x speedup |
3.79x speedup |
8-thread |
3.76x speedup |
3.79x speedup |
Why or why not? (Notice that the workstation server provides 4 cores 4 threads.)
因為當 thread 數量多於核心數,會造成額外的 context switch overhead,導致速度沒有明顯的進步,甚至稍微退步。
我有另外找了一台6核心的電腦作8 thread來實驗
由實驗結果可以看出核心數增加確實可以加速,但若是比thread小很多,速度沒辦法顯著的進步。