I recently encountered a deadlock that I have been able to resolve by using MPI_Bsend
instead of MPI_Send
. If I understand correctly MPI_Bsend is a non-blocking send and it is safe to modify the thing I send without worrying about when the send operation it complete, so
double x = 1;
MPI_Bsend(&x,1,MPI_DOUBLE,master,1,MPI_COMM_WORLD);
x = 0;
will always result in x being sent at 1.
When reading the documentation on MPI send modes I encountered this warning about MPI_Bsend
A late add-on to the MPI specification. Should be used only when absolutely necessary.
My questions are:
MPI_BSend
problematic?Buffered operations in MPI require the user to provide a large-enough buffer. MPI describes an operational model how much buffer may be used for each operation - so you can theoretically compute how much buffer will be needed in total. However, in in sufficiently complex applications it is not feasible to correctly compute the amount of buffer that is needed. Not having enough buffer space is an unrecoverable error. This error may be a very nasty heisenbug randomly occurring under specific circumstances.
Note that buffered mode and non-blocking mode is different (even orthogonal) in MPI. It is easier to write a correct MPI program using non-blocking primitives, i.e. using MPI_Isend
. This is generally recommended.
MPI_BSend
support?The "late addition" quote is misleading. It was already in the very first MPI standard 24 years ago. I wouldn't worry about support by libraries, but rather the other issues I mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With