[問題] OpenMP沒有效果
開發平台(Platform): (Ex: Win10, Linux, ...)
Win7
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
OpenMP
問題(Question):
各位版大大家好
小弟最近需要加速一個function,因為function裡面只是兩層for迴圈,所以選用
OpenMP來加速。在自己寫的測試程式當中是正常可以使用的,也能確認OpenMP有發揮強
大的效果,但當我將測試程式寫回需要使用的專案中之後OpenMP的加速效果就消失了,
已確認編譯器參數有調整(/openmp),也有include omp.h,編譯無報錯,程式正常執行,
小弟經過以下兩點判斷OpenMP沒有發揮加速效果:
1.時間測試
2.使用omp_get_thread_num(),得到的值全為0
目前個人推估可能是編譯器直接略過#pragma,或是執行緒都被佔用??(有測試指定thread
num給parallel for,但還是沒有效果)
但目前對於如何解決還沒有方向,希望版大們賜教!
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
void CMFC_TestSpeedUpDlg::TFunction1D(float srcMx[], float dstMx1[], float
dstMx2[], int Width, int Height, float **cLUT, float **sLUT)
{
#pragma omp parallel for
for (int u = 0; u < Width; u++)
{
float sigma = 0.0f;
float sigma2 = 0.0f;
for (int x = 0; x < Width; x++)
{
sigma += srcMx[x] * cLUT[u][x];
sigma2 += srcMx[x] * sLUT[u][x];
}
dstMx1[u] = sigma;
dstMx2[u] = sigma2;
sigma = sigma2 = 0;
}
}
補充說明(Supplement):
開發平台(Platform): (Ex: Win10, Linux, ...)
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.87.85.162
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1479431111.A.EB0.html
推
11/18 10:06, , 1F
11/18 10:06, 1F
→
11/18 10:06, , 2F
11/18 10:06, 2F
→
11/18 10:08, , 3F
11/18 10:08, 3F
→
11/18 10:24, , 4F
11/18 10:24, 4F
→
11/18 10:24, , 5F
11/18 10:24, 5F
→
11/18 10:24, , 6F
11/18 10:24, 6F
→
11/18 13:29, , 7F
11/18 13:29, 7F
推
11/18 19:02, , 8F
11/18 19:02, 8F
→
11/18 19:31, , 9F
11/18 19:31, 9F
推
11/18 19:34, , 10F
11/18 19:34, 10F
→
11/21 11:03, , 11F
11/21 11:03, 11F
→
11/21 14:13, , 12F
11/21 14:13, 12F
→
11/21 14:13, , 13F
11/21 14:13, 13F
→
11/21 14:13, , 14F
11/21 14:13, 14F