Reference documentation for deal.II version GIT c415589cf0 2022-08-14 18:50:02+00:00
\(\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 (const MPI_Comm &comm)
 
void unlock (const 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]
}
void lock(const MPI_Comm &comm)
Definition: mpi.cc:1102
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 363 of file mpi.h.

Constructor & Destructor Documentation

◆ CollectiveMutex()

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

Constructor of this class.

Definition at line 1080 of file mpi.cc.

◆ ~CollectiveMutex()

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

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

Definition at line 1089 of file mpi.cc.

Member Function Documentation

◆ lock()

void Utilities::MPI::CollectiveMutex::lock ( const 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 1102 of file mpi.cc.

◆ unlock()

void Utilities::MPI::CollectiveMutex::unlock ( const 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 1136 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 435 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 440 of file mpi.h.


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