| 5 | 1/1 | 返回列表 |
| 查看: 1312 | 回復(fù): 5 | ||
| 當(dāng)前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | ||
von_weiqiang木蟲 (正式寫手)
|
[求助]
用MPICH2運行并行程序,代碼中的printf語句只有在所有進程都結(jié)束后才會打印出來么? 已有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函數(shù)每調(diào)用一次需要約2s時間,每個進程運行時間大約20s,我的理解是,每個進程每2s就應(yīng)該打印一次“進程號,循環(huán)次數(shù)”,所以進程號應(yīng)該是雜亂無章的,可是用MPICH開啟3個進程實際運行結(jié)果是這樣: 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ù). . . 為什么呢? |

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

木蟲 (正式寫手)

銀蟲 (初入文壇)
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 298-一志愿中國農(nóng)業(yè)大學(xué)-求調(diào)劑 +9 | 手機用戶 2026-03-17 | 9/450 |
|
|---|---|---|---|---|
|
[考研] 265求調(diào)劑 +9 | 梁梁校校 2026-03-19 | 9/450 |
|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 12/600 |
|
|
[考研] 085700資源與環(huán)境308求調(diào)劑 +10 | 墨墨漠 2026-03-18 | 11/550 |
|
|
[考研] 081700化工學(xué)碩調(diào)劑 +3 | 【1】 2026-03-16 | 3/150 |
|
|
[考研] 0703化學(xué)調(diào)劑 +10 | 妮妮ninicgb 2026-03-15 | 14/700 |
|
|
[考研]
|
不想起名字112 2026-03-19 | 3/150 |
|
|
[考研] 294求調(diào)劑材料與化工專碩 +14 | 陌の森林 2026-03-18 | 14/700 |
|
|
[考研] 一志愿南京理工大學(xué)085701資源與環(huán)境302分求調(diào)劑 +3 | 葵梓衛(wèi)隊 2026-03-18 | 5/250 |
|
|
[考研] 材料考研調(diào)劑 +3 | xwt。 2026-03-19 | 3/150 |
|
|
[考研] 0703化學(xué) 305求調(diào)劑 +4 | FY_yy 2026-03-14 | 4/200 |
|
|
[考研] 344求調(diào)劑 +6 | knight344 2026-03-16 | 7/350 |
|
|
[考研] 【同濟軟件】軟件(085405)考研求調(diào)劑 +3 | 2026eternal 2026-03-18 | 3/150 |
|
|
[考研] 070300化學(xué)319求調(diào)劑 +6 | 錦鯉0909 2026-03-17 | 6/300 |
|
|
[考研] 268求調(diào)劑 +8 | 一定有學(xué)上- 2026-03-14 | 9/450 |
|
|
[考研] 301求調(diào)劑 +4 | A_JiXing 2026-03-16 | 4/200 |
|
|
[考研] 材料與化工專碩調(diào)劑 +5 | heming3743 2026-03-16 | 5/250 |
|
|
[考研] 070300化學(xué)學(xué)碩求調(diào)劑 +6 | 太想進步了0608 2026-03-16 | 6/300 |
|
|
[考研] 327求調(diào)劑 +6 | 拾光任染 2026-03-15 | 11/550 |
|
|
[考研] 本科南京大學(xué)一志愿川大藥學(xué)327 +3 | 麥田耕者 2026-03-14 | 3/150 |
|