Reputation: 443
I am trying to detect deadlocks in MPI
is there any method in which we can jump from function like MPI_Recv after particular time.
Upvotes: 1
Views: 1225
Reputation: 3417
MPI_Recv is a blocking function and will just sit there untill it receives the data it is waiting for, so if you are looking to have it timeout and error if things lock up then I don't think that's the one for you.
You could look into using MPI_Irecv
, which is the non-blocking version. You could then emulate the blocking behaviour of MPI_Recv
using MPI_Wait
or MPI_Test
.
If you use a combination of MPI_Irecv
and MPI_Test
you could make a snippet that waits to recieve for a specified length of time, then errors if it hasn't. Rough example:
MPI_Irecv(..., &request); //start a receive request, non-blocking
time_t start_time = time(); //get start time
MPI_Test(&request, &gotData, ...); //test, have we got it yet
//loop until we have received, or taken too long
while (!gotData && difftime(time(),start_time) < TIMEOUT_TIME) {
//wait a bit.
MPI_Test(&request, &gotData, ...); //test again
}
//By now we either have received the data, or taken too long, so...
if (!gotData) {
//we must have timed out
MPI_Cancel(&request);
MPI_Request_free(&request);
//throw an error
}
Upvotes: 3