我需要執行只能由主進程執行的操作。奴隸們什麼都不能做,只能等着主人完成。所以我做了以下(僞代碼,我將多數程序,所以我想有一個很難拿出實際MPI代碼。我希望評論是在解釋我在做什麼很清楚)我可以使用MPI_Bcast進行同步嗎?
def routine():
if not isMaster():
# I am a slave. I just sit here, waiting for the master to finish.
# wait for a string from the master explaining the state
string = MPI_Bcast("whatever", 0)
return (string == "SUCCESS")
<master does its long running business>
string = MPI_Bcast("SUCCESS", 0) # tell the slaves it worked fine.
return True
不這項工作,還是我濫用廣播?
只要確保'MPI_Bcast'中的根級別匹配'isMaster()'謂詞中使用的級別。 – 2013-03-12 18:52:59