我需要执行一个只能由主进程执行的操作。奴隶们真的什么都做不了,只能等主人说完。因此,我做了以下事情(伪代码,我包装了大多数例程,所以我很难想出实际的 MPI 代码。我希望评论足够清楚地解释我在做什么)
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
这行得通,还是我滥用广播?