Fortran 板


LINE

模式想要利用openMP平行化 以下剪一小段副程式的呼叫,可以正常執行 加入!$OMP DO以後 (以下綠色字體部分) 編譯沒有bug 但程式卻也沒辦法跑 想問一下是哪邊設定或邏輯上發生錯誤? 有想過是不是common或是哪邊變數平行化後會產生衝突 但也不知該從何下手 懇請板友們指教了,謝謝!! 以下是程式碼 -------------------------- program adi implicit real*8(a-h,o-z) parameter (max1=200000,max2=20000) dimension a9(max1),nbx9(max2) common /duv19/ dx9,dy9,m9,mm9(10),n19,n29 common /duv191/ hr9(10),lo9,nb9,iaa9,idisch9(10) common /duv29/ nx9,ny9,dt9,se9(10),idtimed9(10) common /duv49/ ic19(10),ic29(10),jc19(10),icover9(10),lmm9(10) common /duv59/xxk9(10),znn9(50000,10),xnn9(500,500,10) common /duv591/ tmin9(10),indey9(10),tmax9(10),timed9(10) common /duv79/ ihr9(10),iarea9,iwater9(10),nww9(10) common /duv89/ ri9(10),sec9(10),rq9(10),rt9(10),crit9(10) common /duv109/ ind9(10),ndx19,ndy19,mts9 common /duv119/ nv9,nu9,nv19(10),nv29(10),nu19(10) common /duv129/ kpum9(10),np9(10),ibc9(10),wpump9(10),nu29(10) common /stage9/ std9(100,100,10) common /grp/ ign,ifd character ch29*30,put9*30,stf9*30,wrf9*30,trf9*30,da01*30,da02*30 !$OMP PARALLEL !$OMP DO do 399 i=1,2 call inp19(i,max1,max2,nn19,nn29,n39,n49,n59,n69,n79,n89,n99,n109, + n119,nm19,nm29,nm39,nm49,nm59,nm69,nm79,nm89,nm99,nm109,nm119) close(138) close(120) close(135) 399 continue !$OMP END DO !$OMP END PARALLEL stop end c------------------------------------------------ subroutine inp19(i,max1,max2,nn19,nn29,n39,n49,n59,n69,n79,n89,n99 +,n109,n119,nm19,nm29,nm39,nm49,nm59,nm69,nm79,nm89,nm99,nm109 +,nm119) implicit real*8(a-h,o-z) common /duv19/ dx9,dy9,m9,mm9(10),n19,n29 common /duv191/ hr9(10),lo9,nb9,iaa9,idisch9(10) common /duv29/ nx9,ny9,dt9,se9(10),idtimed9(10) common /duv49/ ic19(10),ic29(10),jc19(10),icover9(10),lmm9(10) common /duv59/xxk9(10),znn9(50000,10),xnn9(500,500,10) common /duv591/ tmin9(10),indey9(10),tmax9(10),timed9(10) common /duv79/ ihr9(10),iarea9,iwater9(10),nww9(10) common /duv89/ ri9(10),sec9(10),rq9(10),rt9(10),crit9(10) common /duv109/ ind9(10),ndx19,ndy19,mts9 common /duv119/ nv9,nu9,nv19(10),nv29(10),nu19(10) common /duv129/ kpum9(10),np9(10),ibc9(10),wpump9(10),nu29(10) common /stage9/ std9(100,100,10) common /grp/ ign,ifd character ch29*30,put9*30,stf9*30,wrf9*30,trf9*30,da01*30,da02*30 da01='g'//char(i/10+48)//char(mod(i,10)+48)//'/'//'run1.dat' da02='g'//char(i/10+48)//char(mod(i,10)+48)//'/'//'check1.out' open(138,file=da01,status='old') read(138,'(a30)') put9 open(120,file=put9,status='old') read(138,'(a30)') ch29 read(138,'(a30)') stf9 read(138,'(a30)') wrf9 read(138,'(a30)') trf9 open(135,file=da02,status='unknown') write(*,'(''input the dike overflow or break number :''\)') read(138,'(i7)') nb9 write(*,*) nb9 read(120,'(/3f6.1,7i8)') dx9,dy9,hr9(i),m9,mm9(i),n19,n29 + ,lo9,iaa9,idisch9(i) read(120,'(/2i7,2f15.3,i7)') nx9,ny9,dt9,se9(i),idtimed9(i) read(120,'(/5i7)') ic19(i),ic29(i),jc19(i),icover9(i),lmm9(i) read(120,'(/6i7)') nv9,nu9,nv19(i),nv29(i),nu19(i),nu29(i) read(120,'(/5f10.4)') ri9(i),sec9(i),rq9(i),crit9(i) read(120,'(/3i7)')ind9(i),ndx19,ndy19 read(120,'(/f10.4,i7)') xxk9(i),indey9(i) read(120,'(/4i7)') iwater9(i),nww9(i),ihr9(i),iarea9 read(120,'(/3i7,f10.2)') kpum9(i),np9(i),ibc9(i),wpump9(i) c******************** if(nn19 .eq. 0) then nn19=1 nn29=nn19+(nx9)*(ny9+2)*ign n39=nn29+(nx9+3)*(ny9+3)*ign n49=n39+(2*(nx9+1)+1)*(2*(ny9+1)+1)*ign n59=n49+(2*(nx9+1)+1)*(2*(ny9+1)+1)*ign n69=n59+(nx9)*(ny9)*ign n79=n69+(m9+1)*nb9*ign n89=n79+(m9+1)*nb9*ign n99=n89+(nx9*ny9)*ign n109=n99+(nx9+2)*(ny9+2)*ign n119=n109+(m9+1)*(iarea9)*ign n129=n119+nx9*ny9*ign nm19=1 nm29=nm19+2*iarea9*ign nm39=nm29+nb9*2*ign nm49=nm39+ndx19*2*ign nm59=nm49+ndy19*2*ign nm69=nm59+nv9*2*ign nm79=nm69+nu9*2*ign nm89=nm79+ndx19*ign nm99=nm89+ndy19*ign nm109=nm99+nb9*7*ign nm119=nm109+nv9*ign nm129=nm119+nu9*ign if((n129.ge.max1).or.(nm129.ge.max2))then write(*,444) n129,nm129 print*,'please check the dynamic storage adress, + it must exceed 1500000 adresses !' stop else write(*,444) n129,nm129 444 format(1x,'n129= ',i10,' nm129 = ',i6) endif endif return end --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.63.161 ※ 編輯: ja000123 來自: 140.112.63.161 (02/07 15:30)
1F:推 gilocustom:(1)什麼叫做"沒辦法跑"? 02/07 16:47
debug編譯OK,但程式執行時跑到平行的部分即停在那邊不動 (沒出現錯誤訊息) 抱歉自己Fortran算是自學,有些術語比較不熟悉 描述上可能比較沒這麼準確
2F:→ gilocustom:(2)建議把平行區塊內的各個變數的屬性都標明。 02/07 16:48
好,未平行時程式可以跑倒沒注意這些變數沒標示清楚,我再補上去 謝謝 ※ 編輯: ja000123 來自: 36.227.25.90 (02/07 23:04)
3F:→ gilocustom:你的懷疑是合理的,請參考以下連結: 02/08 00:30
5F:→ gilocustom:PRIVATE 02/08 00:30
6F:→ gilocustom:再者,你這樣寫會導致不同的執行緒同時讀/寫/開/關同個 02/08 00:37
7F:→ gilocustom:檔案,遲早觸發race condition。 02/08 00:38
8F:→ gilocustom:喔看錯,可能會造成困擾的是(只)同時開/關同個檔案。 02/08 00:49
9F:→ gilocustom:又錯...同時讀也會造成問題。 02/08 01:59
嗯嗯,其實程式中有其他副程式有用到寫入 XD 想請教這種問題該從哪裡下手? 我曾對character的變數PRIVATE 但還是有問題 !$OMP PARALLEL PRIVATE (da01,da02,put9,ch29,stf9,wrf9,trf9,nb9) 想問是我這樣寫有用錯,還是有其他的變數需要納入? 謝謝了! ※ 編輯: ja000123 來自: 36.227.30.243 (02/08 21:33)
10F:→ gilocustom:如果只是同時操作同一編號的不同名稱檔案,只需要改成 02/09 01:05
11F:→ gilocustom:各執行緒用不同的編號即可。如果是操作同一名稱的檔案, 02/09 01:07
12F:→ gilocustom:可以考慮為各執行緒創建不同名稱的副本(複製或連結), 02/09 01:13
13F:→ gilocustom:視需要最後再刪除或合併。 02/09 01:13
程式是讀取路徑不同子資料夾內同樣名稱的檔案,所以是屬於後者嗎?
14F:→ gilocustom:也可以考慮每到操作檔案時限制只有一個執行緒可用。 02/09 01:15
15F:→ gilocustom:話說回來,除非你用的儲存裝置夠快,快到可以輕鬆負荷 02/09 01:25
16F:→ gilocustom:多個執行緒同時讀寫檔案,否則讀寫就效能來說沒有必要 02/09 01:27
17F:→ gilocustom:平行化,甚至可能會有反效果。 02/09 01:30
18F:→ gilocustom:你需要先了解變數的屬性有哪些以及各自的用途,然後再 02/09 01:45
19F:→ gilocustom:仔細審視程式碼、依照各個變數的需求賦予不同的屬性, 02/09 01:49
20F:→ gilocustom:譬如我上面給的連結就是在說明其中一種你的程式碼可能 02/09 01:51
21F:→ gilocustom:會需要用到的變數屬性。 02/09 01:51
22F:→ gilocustom:da01等變數並不是全域的,而且也不是從主程式傳遞至 02/09 02:07
23F:→ gilocustom:副程式,所以在主程式令其為PRIVATE是沒有意義的,只會 02/09 02:08
24F:→ gilocustom:多占用一點點記憶體。 02/09 02:09
變數的屬性我有看過相關資料教學,但可能學的不精,仍無法靈活應用 就像PRIVATE自己也是亂用,做了很多無意義的錯誤方法 因此想冒昧請教一下,如果就上面例子來說, 您會針對那些細部做修改,有哪些變數或部分一定有問題的? 希望讓我有個正確的方向去修改,而不是一直往錯的地方去鑽研 最後謝謝你肯花時間回答我問題 之後幾天過年,我也很不好意思再麻煩你 這次問完後,年假期間我就針對您的指教回覆自己研究摸索吧 非常感謝您!也祝你新年快樂囉!! ※ 編輯: ja000123 來自: 36.227.28.81 (02/09 12:50)
25F:→ gilocustom:不同路徑就是不同檔案,除非你是同檔案連結到不同路徑. 02/09 18:35
26F:→ gilocustom:主程式的那些字串變數(ch29等)和副程式內同名的變數 02/09 18:37
27F:→ gilocustom:根本沒有關係所以不必給屬性,而其實在主程式中根本 02/09 18:38
28F:→ gilocustom:用不到所以甚至不需要宣告。副程式的那些字串就是另外 02/09 18:40
29F:→ gilocustom:一個世界了所以也不用動。 02/09 18:41
30F:→ gilocustom:common的變數如要私有化需要使用THREADPRIVATE屬性。 02/09 18:43
31F:→ gilocustom:max1與max2都是常數所以不需要也不可以給屬性。 02/09 18:44
32F:→ gilocustom:迴圈用的引數i當然要私有化所以是PRIVATE。 02/09 18:47
33F:→ gilocustom:inp19的其他變數(nn19~nm119)如果有需要私有化那就私有 02/09 18:49
34F:→ gilocustom:化,不過主程式乍看根本用不到這些變數所以乾脆連傳都 02/09 18:50
35F:→ gilocustom:不要傳了,直接省去就不用考慮要用哪種私有化的屬性, 02/09 18:51
36F:→ gilocustom:不然你就還是要視需求慎擇屬性。 02/09 18:52
37F:→ gilocustom:最後就是檔案編號,再加上i就可以簡單避免重複,或者 02/09 18:55
38F:→ gilocustom:加上執行緒的編號也可以。 02/09 18:55
實在是非常感謝您!!!解決了我不少問題 修正了我不少錯誤 雖然可能還是會碰壁碰到問題,但我會往你所講的這些方向去研究看看 謝謝囉!!! ※ 編輯: ja000123 來自: 36.227.29.241 (02/10 00:08)
39F:→ Cypresslin:樓上平行魔人 02/10 00:43







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:iOS站內搜尋

TOP