0
的爲什麼這行代碼:行爲MPI_SEND和MPI_RECV
if(my_rank != 0) {
sprintf(msg, "Hello from %d of %d...", my_rank, comm_sz);
if(my_rank == 2) {
sleep(2);
sprintf(msg, "Hello from %d of %d, I have slept 2 seconds...", my_rank, comm_sz);
}
MPI_Send(msg, strlen(msg), MPI_CHAR, 0, 0, MPI_COMM_WORLD);
}
else {
printf("Hello from the chosen Master %d\n", my_rank);
for(i = 1; i < comm_sz; i++) {
MPI_Recv(msg, MAX_STRING, MPI_CHAR, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("%s\n", msg);
}
}
給這個結果呢?
Hello from the chosen Master 0
Hello from 1 of 5...
Hello from 2 of 5, I have slept 2 seconds...
Hello from 3 of 5... have slept 2 seconds...
Hello from 4 of 5... have slept 2 seconds...
是不是每個進程都有它的'msg'副本?
你期望什麼?請注意,MPI不適用於線程,而是進程。 – Zulan
@Zulan我希望只有第二個過程會寫_I睡了2秒... _ – Caramelleamare