---
# System prepended metadata

title: 平行程式設計 作業二

---

# 平行程式設計 作業二

## 學號: 511506009
## 學生: 吳宗霖

### 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. Is speedup linear in the number of threads used? In your writeup hypothesize why this is (or is not) the case? 

![](https://i.imgur.com/bdyC3Tx.jpg)

![](https://i.imgur.com/niUduBj.jpg)

![](https://i.imgur.com/7jrWL41.jpg)

![](https://i.imgur.com/VWL5Qcj.jpg)

![](https://i.imgur.com/JvRL96F.jpg)

#### VIEW1和VIEW2的speed up和thread number 是線性
#### view1圖形的黑白區塊明顯且運算時所花的時間各不相同，所以thread不同時，運算時間也並不相同。
#### view2圖形，顏色改變不明顯且運算的時間，相差不大，thread數量和speed up也是線性。

### Q2: How do your measurements explain the speedup graph you previously created?

#### VIEW1在thread number 不一樣的關係，圖形中各個區塊部份會花費多時計算，因此不同thread number的speed up沒有線性。

#### 依執行結果，觀察出以下四點結果
1. 當3個thread number，thread 1 所花的時間比 thread 0, 2 還要多
2. 當4個thread number，thread 1,2 所花的時間比 thread 0, 3 還要多
3. 當3個thread number，thread 1 處理圖形中間那一塊，有比較多白色的區塊
4. 當4個thread number，thread 1,2 處理圖形中間那二塊，有比較多白色的區塊

### Q3: In your write-up, describe your approach to parallelization and report the final 4-thread speedup obtained.

#### 依執行結果，觀察圖形變化，在某些部分比其他區塊花費時間較多，當每個行段交錯的方式分佈，因此負載不平衡的問題可以解決。請看下面的例子（假設線程數 = 4）
VIEW1
![](https://i.imgur.com/3yFAWwt.jpg)
![](https://i.imgur.com/EFMKu0M.jpg)

VIEW2
![](https://i.imgur.com/9BoSU1d.jpg)
![](https://i.imgur.com/xBofAfa.jpg)

### Q4: Now run your improved code with eight threads. Is performance noticeably greater than when running with four threads? Why or why not? (Notice that the workstation server provides 4 cores 4 threads.)

![](https://i.imgur.com/S5hZoyy.jpg)

![](https://i.imgur.com/cehtvEu.jpg)

#### 依執行結果，觀察8個thread number的性能，明顯提高。實際上，當thread number越高時，有明顯的改善。