サーチ…
備考
Collectives操作は、一回の操作でコミュニケータによって指摘されたプロセスを通信するか、またはそれらの間で同期を実行するように設計されたMPI呼び出しです。これらは、他のプロセスによって提供されたデータに基づいて1つ以上の値を計算したり、他のすべてのプロセスからデータを配布または収集したりするためによく使用されます。
コミュニケータ内のすべてのプロセスは、同じ集合操作を順番に呼び出す必要があります。そうでない場合、アプリケーションはブロックされます。
放送
次のコードは、 MPI_Bcast
操作を使用して、 MPI_Bcast
MPI_COMM_WORLD
タに属するすべてのプロセス(つまり、並列に実行されているすべてのプロセス)の中で、 buffer
内のコンテンツをMPI_Bcast
します。
int rank;
int res;
res = MPI_Comm_rank (MPI_COMM_WORLD, &rank);
if (res != MPI_SUCCESS)
{
fprintf (stderr, "MPI_Comm_rank failed\n");
exit (0);
}
int buffer[100];
if (rank == 0)
{
// Process with rank id 0 should fill the buffer structure
// with the data it wants to share.
}
res = MPI_Bcast (buffer, 100, MPI_INT, 0, MPI_COMM_WORLD);
if (res != MPI_SUCCESS)
{
fprintf (stderr, "MPI_Bcast failed\n");
exit (0);
}
バリア
MPI_Barrier
オペレーションは、所与のコミュニケータに属するプロセス間の同期を実行する。つまり、特定のコミュニケータからのすべてのプロセスは、すべてが内部にMPI_Barrier
までMPI_Barrier
内で待機し、その時点で操作を終了します。
int res;
res = MPI_Barrier (MPI_COMM_WORLD); /* all processes will wait */
if (res != MPI_SUCCESS)
{
fprintf (stderr, "MPI_Barrier failed\n");
exit (0);
}
散布
ルートプロセスは、 MPI_Scatter
操作を使用してsendbuf
の内容をすべてのプロセス(それ自体を含む)にMPI_Scatter
ます。
int rank;
int size;
int sendcount = 1;
int recvcount = sendcount;
int sendbuf[3];
int recvbuf;
int root = 0;
MPI_Comm_size (MPI_COMM_WORLD, &size);
if (size != 3)
{
fprintf (stderr, "Number of processes must be 3\n");
exit (0);
}
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
if (rank == 0)
{
sendbuf[0] = 3;
sendbuf[1] = 5;
sendbuf[2] = 7;
}
MPI_Scatter (sendbuf, sendcount, MPI_INT, &recvbuf, recvcount, MPI_INT, root, MPI_COMM_WORLD);
printf ("rank: %i, value: %i\n", rank, recvbuf);
/* Output:
* rank: 0, value: 3
* rank: 1, value: 5
* rank: 2, value: 7
*/
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow