看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Gcc and Linux Fedora 20 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) Openmp 問題(Question): 請問各位高手,小弟我最近在學openmp,有個關於parallel for的問題。 #pragma omp parallel for private(s) for(s=0;s<120;s++) myfun(*output,*input,s); *output和*input都是128*128的float point array 餵入的資料(Input): 每個s迴圈都會在myfun使用*input來計算出一個新的float point array,叫*new 然後輸出成 *output+=*new; 預期的正確結果(Expected Output): 我預期有使用openmp和沒有使用openmp結果一樣 錯誤結果(Wrong Output): 但我發現二者還是有差異大部分的差都在10^-5左右,但是有少部分值的差到0.2, 例如正確值=25.3,使用openmp後的值=25.1 *input在myfun中,不會被改變,但是*output則是不斷累加。 我試了很久,找不出原因。 各位不知道有沒有建議,感謝 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.150.52 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1421669517.A.E78.html
PkmX: 有完整的code嗎? 01/19 22:57
damody: 樓下隔空抓藥 01/20 00:46
mike0227: race condition 01/20 13:51