Implementation
A.
Load balancing
設定兩個變數 batch_x, batch_y,代表 x, y 軸的 batch size,並依照 iters 參數分成兩種情況:
iters > 10000:每個像素點會進行多次迭代,但因為有些點會在還沒有迭代到指定步數就跳出(x^2 + y^2 >= 4),會造成多個點計算量的不平均。在這個情況下,將 batch_x 設定為 max(1, (int)(width / num_threads / 4)),並將 batch _y 設定為 1,利用更小的 batch size 來提升 load balancing 的效果
iters <= 10000:將 batch_x 設定為 width / num_threads, batch_y 設定為 width / num_threads / 12,也就是平均每個 thread 會分到 num_threads * 12 塊區域。
分配工作
首先宣告以下物件: