0

私はいくつかのデータの配列を持っています。私がやろうとしていたことは次のようなものです:

ランク 0 を使用して、データを 50 ノードにブロードキャストします。各ノードには 1 つの mpi プロセスがあり、そのプロセスで 16 コアを使用できます。次に、各 mpi プロセスが python multiprocessing を呼び出します。いくつかの計算が行われた後、mpi プロセスは multiprocessing で計算されたデータを保存します。次に、mpi プロセスはいくつかの変数を変更し、マルチプロセッシングを再度実行します。等。

そのため、ノードはすべてのデータを受信する最初の起動を除いて、相互に通信する必要はありません。

マルチプロセッシングはうまく機能していません。だから今、私はすべてのMPIを使いたいです。

bcast または scatter の MPI ランクを参照する整数の配列をどのように使用できますか (または使用できませんか)。たとえば、ランク 1 ~ 1000 の場合、ノードには 12 個のコアがあります。したがって、12 ランクごとにデータをブロードキャストしたいと考えています。次に、12番目のランクごとに、データを12 + 1から12 + 12ランクに分散させます。

これには、最初の bcast が totalrank/12 と通信する必要があり、次に各ランクが同じノードのランクにデータを送信し、結果を収集して保存し、同じノードのランクにさらにデータを送信する必要があります。

4

1 に答える 1

4

mpi4py については、コード サンプルを提供できるほど詳しくありませんが、C++ で解決できる可能性のあるものを次に示します。Pythonコードを簡単に推測できると確信しています。

#include <mpi.h>
#include <iostream>
#include <cstdlib> /// for abs
#include <zlib.h>  /// for crc32

using namespace std;

int main( int argc, char *argv[] ) {

    MPI_Init( &argc, &argv );
    // get size and rank
    int rank, size;
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    // get the compute node name
    char name[MPI_MAX_PROCESSOR_NAME];
    int len;
    MPI_Get_processor_name( name, &len );

    // get an unique positive int from each node names
    // using crc32 from zlib (just a possible solution)
    uLong crc = crc32( 0L, Z_NULL, 0 );
    int color = crc32( crc, ( const unsigned char* )name, len );
    color = abs( color );

    // split the communicator into processes of the same node
    MPI_Comm nodeComm;
    MPI_Comm_split( MPI_COMM_WORLD, color, rank, &nodeComm );

    // get the rank on the node
    int nodeRank;
    MPI_Comm_rank( nodeComm, &nodeRank );

    // create comms of processes of the same local ranks
    MPI_Comm peersComm;
    MPI_Comm_split( MPI_COMM_WORLD, nodeRank, rank, &peersComm );

    // now, masters are all the processes of nodeRank 0
    // they can communicate among them with the peersComm
    // and with their local slaves with the nodeComm
    int worktoDo = 0;
    if ( rank == 0 ) worktoDo = 1000;
    cout << "Initially [" << rank << "] on node "
         << name << " has " << worktoDo << endl;
    MPI_Bcast( &worktoDo, 1, MPI_INT, 0, peersComm );
    cout << "After first Bcast [" << rank << "] on node "
         << name << " has " << worktoDo << endl;
    if ( nodeRank == 0 ) worktoDo += rank;
    MPI_Bcast( &worktoDo, 1, MPI_INT, 0, nodeComm );
    cout << "After second Bcast [" << rank << "] on node "
         << name << " has " << worktoDo << endl;

    // cleaning up
    MPI_Comm_free( &peersComm );
    MPI_Comm_free( &nodeComm );

    MPI_Finalize();
    return 0;
}

ご覧のとおり、最初に同じノード上のプロセスを持つコミュニケーターを作成します。次に、各ノードで同じローカル ランクのすべてのプロセスを持つピア コミュニケーターを作成します。それ以降、グローバル ランク 0 のマスター プロセスがローカル マスターにデータを送信します。そして、担当するノードで作業を分散します。

于 2015-09-03T14:37:49.877 に答える