0
我有類似:MPI_Waitsome分段錯誤?
int numprocs, id, arr[10], winner = -1;
bool stop = false;
MPI_Request reqs[10], winnerNotification;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
srand(time(NULL) + id);
if (id == 10) {
int completed = 0;
int* completedIndexes;
for (int i = 0; i < 10; i++) {
MPI_Irecv(&arr[i], 1, MPI_INT, i, 0, MPI_COMM_WORLD, &reqs[i]);
}
MPI_Waitsome(10, reqs, &completed, completedIndexes, MPI_STATUSES_IGNORE);
cout << completed << " seems to have completed" << endl;
for (int i = 0; i < completed; i++) {
cout << completedIndexes[i] << " have completed!";
}
}
while (id < 10 && winner == -1) {
if (((rand() % 100) + 1) < 5) { // players have 5% chance of completing
MPI_Send(&id, 1, MPI_INT, 10, 0, MPI_COMM_WORLD);
cout << id << " completed" << endl;
MPI_Wait(&winnerNotification, MPI_STATUS_IGNORE);
}
}
MPI_Finalize();
這是給分段錯誤,我認爲它是與Waitsome?但是什麼?錯誤的樣子:
1 completed
[JM:01317] *** Process received signal ***
[JM:01317] Signal: Segmentation fault (11)
[JM:01317] Signal code: Address not mapped (1)
[JM:01317] Failing at address: 0x646574
4 completed
5 completed
[JM:01320] *** Process received signal ***
[JM:01320] Signal: Segmentation fault (11)
[JM:01320] Signal code: Address not mapped (1)
[JM:01320] Failing at address: 0x646574
3 completed
[JM:01319] *** Process received signal ***
[JM:01319] Signal: Segmentation fault (11)
[JM:01319] Signal code: Address not mapped (1)
[JM:01319] Failing at address: 0x646574
...
看來最大完成值爲1?我猜測它是因爲一旦第一個進程發送,它會導致等待返回? –
不,這是由於在Open MPI中實現了進程(帶來一個未完成的非阻塞請求)的方式。如果您啓用了進程線程編譯Open MPI,則可以在後臺獲取請求。但這樣做會影響某些操作的延遲。如果您想等待所有接收完成,請使用'MPI_WAITALL'。 –
嗯問題是,並非所有的進程可能完成。我只想捕獲同時完成的過程(大致至少) –