PP-HW2 ================================== > 0716078 鄒義杰 ## Q1 - View 1  - View 2  速度與 Thread 數 **不成線性關係**。 我認為在 View 1 使用三個 Threads 的情況下,應該有一個 Thread 他的計算量相較於其他兩個較高,導致速度較慢,拖累整加速的效果。 ## Q2 - View 1  - View 2  我分別算了每個 Thread 的耗時,發現在 View 1 使用三個 Thread 的情況下,有一個 Thread 的耗時明顯高於另外兩個,沒有有效的分配工作量導致的。 在其他情況下,每個 Thread 的耗時就沒有差這麼多,所以整體的加速效果就有呈線性關係。 ## Q3 我的作法是第 i 個 row 就交給第 (i % numThreads) Thread 做,這樣可以有效的平均分配工作量。不管是工作量大或小的空間都可以平均的分配,就不會出像上述 Q1 Q2 的問題。 ```cpp= for (int i = args->threadId; i < (int)(args->height); i += args->numThreads) { mandelbrotSerial(args->x0, args->y0, args->x1, args->y1, args->width, args->height, i, 1, args->maxIterations, args->output); } ```  修正分配方法後再 View 1 & 2 上都可以跑到 3.80x 的加速。 ## Q4 表現比用 4 threads 時還要差一點點。 我認為應該是因為工作站上面只有 4 個 hardware thread,就算多開 thread 去跑,每次能平行執行的也只有 4 個 thread,所以 8 threads 跑出來的時間跟 4 threads 的差不多,但是因為 context switch 的次數會比較多次,所以效能略比 4 threads 的差一點點。 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up