I have something like:
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();
Which is giving segmentation fault, I think its something to do with Waitsome? But what? The error looks like:
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
...
MPI_Waitsomeexpects an array of integers where it stores the indices of the completed requests, but what you give to it is an uninitialisedintpointer. Given the fact that you have hardcoded10as the number of requests, the following code should work: