VS 2017 MPI 환경 설정
4671 단어 MPI
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
using namespace std;
const int MAX_STRLEN = 100;
int main(int argc, char **argv)
{
char greeting[MAX_STRLEN];
int comm_sz;
int my_rank;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if (my_rank != 0) {
sprintf(greeting, "Greetings from %d of %d", my_rank, comm_sz);
MPI_Send(greeting, strlen(greeting) + 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
}
else {
printf("Greeting from %d of %d!
", my_rank, comm_sz);
for (int q = 1; q < comm_sz; q++) {
MPI_Recv(greeting, MAX_STRLEN, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
printf("%s
", greeting);
}
}
MPI_Finalize();
return 0;
}
Greeting from 0 of 10!
Greetings from 4 of 10
Greetings from 1 of 10
Greetings from 3 of 10
Greetings from 2 of 10
Greetings from 6 of 10
Greetings from 9 of 10
Greetings from 8 of 10
Greetings from 7 of 10
Greetings from 5 of 10
스 레 드 명령 에 따라 무 작위 로 실행 되 기 때문에 출력 내용 순서 가 다 를 수 있 습 니 다.