Reference documentation for deal.II version Git 7a0e96d111 2021-06-21 21:20:26 -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>


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]

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

Constructor & Destructor Documentation

◆ CollectiveMutex()

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

Constructor of this class.

Definition at line 1037 of file

◆ ~CollectiveMutex()

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

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

Definition at line 1046 of file

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 1059 of file

◆ 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 1093 of file

Member Data Documentation

◆ locked

bool Utilities::MPI::CollectiveMutex::locked

Keep track if we have this lock right now.

Definition at line 408 of file mpi.h.

◆ request

MPI_Request Utilities::MPI::CollectiveMutex::request

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

Definition at line 413 of file mpi.h.

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