[問題] pthread無法提升效率

看板C_and_CPP (C/C++)作者 (heymei)時間14年前 (2012/03/24 14:33), 編輯推噓1(106)
留言7則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) linux 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) <pthread.h> 問題(Question): 小弟目前在做矩陣相乘,利用pthread的數目改善最後執行的時間 餵入的資料(Input): 資料1:pthread數目 資料2:矩陣的維度 預期的正確結果(Expected Output): 應該要隨著pthread的增加 執行時間減少 錯誤結果(Wrong Output): 但沒減少 反而增加1秒 錯誤資料為: pthread = 1 , matrix維度 = 1024 , 36.5032秒 pthread = 2 , matrix維度 = 1024 , 37.4032秒 pthread = 3 , matrix維度 = 1024 , 37.14245032秒 pthread = 8 , matrix維度 = 1024 , 38.5032秒 程式碼(Code):(請善用置底文網頁, 記得排版) http://codepad.org/PmsjjEzm 請鄉民大大提點我一下Q.Q 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.131.107

03/24 16:42, , 1F
goole matrix multiplication multithreading
03/24 16:42, 1F

03/24 23:02, , 2F
廣義上來說的確有變快,你這程式做八次矩陣相乘卻只增加一秒
03/24 23:02, 2F

03/24 23:03, , 3F
如果是想要用八個 thread 去跑一次矩陣相乘來加速
03/24 23:03, 3F

03/24 23:03, , 4F
重點要改的是 mm 這個 function......
03/24 23:03, 4F

03/25 10:47, , 5F
也要把create thread的時間考慮進去
03/25 10:47, 5F

03/25 10:49, , 6F
而且你切兩個並不代表就會變一半,thread要考慮的東
03/25 10:49, 6F

03/25 10:49, , 7F
西太多,lock問題之類的
03/25 10:49, 7F
文章代碼(AID): #1FRMgfhY (C_and_CPP)
文章代碼(AID): #1FRMgfhY (C_and_CPP)