| 6 | 1/1 | 返回列表 |
| 查看: 1311 | 回復: 5 | |||
von_weiqiang木蟲 (正式寫手)
|
[求助]
用MPICH2運行并行程序,代碼中的printf語句只有在所有進程都結束后才會打印出來么? 已有2人參與
|
|
能不能各進程一邊運行,一邊打? 例如代碼: MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&myrank); for(i=0;i<1e1;i++) { a=integration(0,1,1e-6,f); printf("current %d %d %e\n",myrank,i,a); } MPI_Finalize(); 其中,integration函數每調用一次需要約2s時間,每個進程運行時間大約20s,我的理解是,每個進程每2s就應該打印一次“進程號,循環(huán)次數”,所以進程號應該是雜亂無章的,可是用MPICH開啟3個進程實際運行結果是這樣: current 0 0 3.141593e+000 current 0 1 3.141593e+000 current 0 2 3.141593e+000 current 0 3 3.141593e+000 current 0 4 3.141593e+000 current 0 5 3.141593e+000 current 0 6 3.141593e+000 current 0 7 3.141593e+000 current 0 8 3.141593e+000 current 0 9 3.141593e+000 current 2 0 3.141593e+000 current 2 1 3.141593e+000 current 2 2 3.141593e+000 current 2 3 3.141593e+000 current 2 4 3.141593e+000 current 2 5 3.141593e+000 current 2 6 3.141593e+000 current 2 7 3.141593e+000 current 2 8 3.141593e+000 current 2 9 3.141593e+000 current 1 0 3.141593e+000 current 1 1 3.141593e+000 current 1 2 3.141593e+000 current 1 3 3.141593e+000 current 1 4 3.141593e+000 current 1 5 3.141593e+000 current 1 6 3.141593e+000 current 1 7 3.141593e+000 current 1 8 3.141593e+000 current 1 9 3.141593e+000 請按任意鍵繼續(xù). . . 為什么呢? |

|
這個問題設計計算機的緩沖區(qū)。print的東西是先輸出到緩沖區(qū),再從緩沖區(qū)輸出到終端的(文件,或者顯示器)。所以最終的輸出和系統(tǒng)有關系,并不能直接反應運行順序。你可以使用flush命令來刷新緩沖區(qū),并用mpi_barrier()來同步各個進程,就可以得到想要的順序。 [ 發(fā)自手機版 http://www.gaoyang168.com/3g ] |

木蟲 (正式寫手)

銀蟲 (初入文壇)
木蟲 (文壇精英)

| 6 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿西南交通 專碩 材料355 本科雙非 求調劑 +4 | 西南交通專材355 2026-03-19 | 4/200 |
|
|---|---|---|---|---|
|
[論文投稿]
申請回稿延期一個月,編輯同意了。但系統(tǒng)上的時間沒變,給編輯又寫郵件了,沒回復
10+3
|
wangf9518 2026-03-17 | 4/200 |
|
|
[考研] 梁成偉老師課題組歡迎你的加入 +9 | 一鴨鴨喲 2026-03-14 | 11/550 |
|
|
[考研] 266求調劑 +5 | 陽陽哇塞 2026-03-14 | 10/500 |
|
|
[考研] 085600材料與化工調劑 324分 +10 | llllkkkhh 2026-03-18 | 12/600 |
|
|
[考研] 求調劑,一志愿:南京航空航天大學大學 ,080500材料科學與工程學碩,總分289分 +3 | @taotao 2026-03-19 | 3/150 |
|
|
[考研] 一志愿福大288有機化學,求調劑 +3 | 小木蟲200408204 2026-03-18 | 3/150 |
|
|
[考研] 085600材料與化工求調劑 +6 | 緒幸與子 2026-03-17 | 6/300 |
|
|
[考研] 材料考研調劑 +3 | xwt。 2026-03-19 | 3/150 |
|
|
[考研] 354求調劑 +4 | Tyoumou 2026-03-18 | 7/350 |
|
|
[考研] 【同濟軟件】軟件(085405)考研求調劑 +3 | 2026eternal 2026-03-18 | 3/150 |
|
|
[考研] 08工科 320總分 求調劑 +5 | 梨花珞晚風 2026-03-17 | 5/250 |
|
|
[考研] 311求調劑 +11 | 冬十三 2026-03-15 | 12/600 |
|
|
[考研] 材料專碩306英一數二 +10 | z1z2z3879 2026-03-16 | 13/650 |
|
|
[考研] 生物學071000 329分求調劑 +3 | 我愛生物生物愛?/a> 2026-03-17 | 3/150 |
|
|
[考研] 301求調劑 +9 | yy要上岸呀 2026-03-17 | 9/450 |
|
|
[考研] 一志愿南京大學,080500材料科學與工程,調劑 +4 | Jy? 2026-03-16 | 4/200 |
|
|
[考研] 東南大學364求調劑 +5 | JasonYuiui 2026-03-15 | 5/250 |
|
|
[考研] 中科院材料273求調劑 +4 | yzydy 2026-03-15 | 4/200 |
|
|
[考研] 一志愿哈工大材料324分求調劑 +5 | 閆旭東 2026-03-14 | 5/250 |
|