수색…
비고
Collectives 작업은 단일 작업에서 커뮤니케이터가 지적한 프로세스를 통신하거나 해당 작업간에 동기화를 수행하도록 설계된 MPI 호출입니다. 이들은 종종 다른 프로세스가 제공 한 데이터를 기반으로 하나 이상의 값을 계산하거나 다른 모든 프로세스의 데이터를 배포하거나 수집하는 데 사용됩니다.
커뮤니케이터의 모든 프로세스는 동일한 일괄 작업을 순서대로 호출해야합니다. 그렇지 않으면 응용 프로그램이 차단됩니다.
방송
다음의 코드는 MPI_COMM_WORLD
커뮤니케이터에 속한 모든 프로세스들 (즉, 병렬로 실행되는 모든 프로세스들)에 MPI_Bcast
오퍼레이션을 사용하여 buffer
내의 내용을 방송한다.
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);
}
소수
루트 과정에서 내용을 산란 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