我正在努力調整程序以使用OpenMP。我有一組嵌套for循環。最外面的for循環是沿着圖像的y軸循環。我想在循環中運行多個並行線程,但我很難快速完成。OpenMP For - 用於高速緩存優化的組循環
目前,當我運行8個線程運行,如:
thread 0 -> row 0,8,16...
thread 1 -> row 1,9,17...
thread 2 -> row 2,10,18...
thread 3 -> row 3,11,19...
我想它在塊運行,使線程0確實行的第一1/8。做這個的最好方式是什麼?
當前代碼:
...
int y_percent = data_size_Y/8;
int thread = 0;
#pragma omp parallel for num_threads(8) firstprivate(vecs, bufferedOut,data_size_X, data_size_Y, kern_cent_X, kern_cent_Y, sum)
for(int y = y_percent*omp_get_thread_num(); y < (omp_get_thread_num()+1)*y_percent; y++){ // the y coordinate of theoutput location we're focusing on
如果一個人不關心塊分佈的排序,而是關心性能,那麼'schedule(動態)'應該只能作爲修復負載不平衡的最後手段。與靜態調度相比,動態調度的開銷是巨大的。 –