This class represents a mutex to guard a critical section for a set of processors in a parallel computation using MPI.
The lock() commands waits until all MPI ranks in the communicator have released a previous lock using unlock().
A typical usage involves guarding a critical section using a lock guard:
{
}
void lock(const MPI_Comm &comm)
Here, the critical code will finish on all processors before the mutex can be acquired again (for example by a second execution of the block above. The critical code block typically involves MPI communication that would yield incorrect results without the lock. For example, if the code contains nonblocking receives with MPI_ANY_SOURCE, packets can be confused between iterations.
Note that the mutex needs to be the same instance between calls to the same critical region. While not required, this can be achieved by making the instance static (like in the example above). The variable can also be a global variable, or a member variable of the object to which the executing function belongs.
Definition at line 360 of file mpi.h.