Reference documentation for deal.II version Git 409ee4b167 2020-08-14 09:46:12 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Classes | Public Member Functions | Private Attributes | List of all members
Utilities::MPI::CollectiveMutex Class Reference

#include <deal.II/base/mpi.h>

Classes

class  ScopedLock
 

Public Member Functions

 CollectiveMutex ()
 
 ~CollectiveMutex ()
 
void lock (MPI_Comm comm)
 
void unlock (MPI_Comm comm)
 

Private Attributes

bool locked
 
MPI_Request request
 

Detailed Description

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:

{
static CollectiveMutex mutex;
CollectiveMutex::ScopedLock lock(mutex, comm);
// [ critical code to be guarded]
}

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 322 of file mpi.h.

Constructor & Destructor Documentation

◆ CollectiveMutex()

Utilities::MPI::CollectiveMutex::CollectiveMutex ( )
explicit

Constructor of this class.

Definition at line 1082 of file mpi.cc.

◆ ~CollectiveMutex()

Utilities::MPI::CollectiveMutex::~CollectiveMutex ( )

Destroy the mutex. Assumes the lock is not currently held.

Definition at line 1091 of file mpi.cc.

Member Function Documentation

◆ lock()

void Utilities::MPI::CollectiveMutex::lock ( MPI_Comm  comm)

Acquire the mutex and, if necessary, wait until we can do so.

This is a collective call that needs to be executed by all processors in the communicator.

Definition at line 1104 of file mpi.cc.

◆ unlock()

void Utilities::MPI::CollectiveMutex::unlock ( MPI_Comm  comm)

Release the lock.

This is a collective call that needs to be executed by all processors in the communicator.

Definition at line 1138 of file mpi.cc.

Member Data Documentation

◆ locked

bool Utilities::MPI::CollectiveMutex::locked
private

Keep track if we have this lock right now.

Definition at line 394 of file mpi.h.

◆ request

MPI_Request Utilities::MPI::CollectiveMutex::request
private

The request to keep track of the non-blocking barrier.

Definition at line 399 of file mpi.h.


The documentation for this class was generated from the following files: