1

マスタープロセスでしか実行できない操作を実行する必要があります。スレーブは実際には何もできませんが、マスターが終了するのを待ちます。したがって、私は次のことを行いました(擬似コード、ほとんどのルーチンをラップするため、実際の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

これは機能しますか、それとも私は放送を誤用していますか?

4

1 に答える 1

2

その疑似コードを作成すると:

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")

    else:
        <master does its long running business>
        string = MPI_Bcast("SUCCESS", 0) # tell the slaves it worked fine.

    return True

その後、あなたは元気になるはずです。(もちろん、言語に適した特定の MPI API を取得する必要があります。) 一般に、ブロードキャストまたは集合操作の場合、コミュニケーターの各ランクは同じ数の呼び出しを実行する必要があります。理解するために、同じソースコード行で各ランクの Bcast を無条件に実行する方法でプログラムを再構築することが有益な場合があります。

def routine():
    status_code = UNKNOWN
    if isMaster(): 
        #do stuff
        status_code = OK

    MPI_Bcast(&status_code, 0)
    #check status_code on each rank
于 2013-03-11T11:15:30.063 に答える