Reference documentation for deal.II version GIT relicensing-837-gaf73e64026 2024-06-15 22:40: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\}}\)
No Matches
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;
// [ critical code to be guarded]
void lock(const MPI_Comm comm)
*braid_SplitCommworld & 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 328 of file mpi.h.

Constructor & Destructor Documentation

◆ CollectiveMutex()

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

Constructor of this class.

Definition at line 790 of file

◆ ~CollectiveMutex()

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

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

Definition at line 799 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 816 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 853 of file

Member Data Documentation

◆ locked

bool Utilities::MPI::CollectiveMutex::locked

Keep track if we have this lock right now.

Definition at line 400 of file mpi.h.

◆ request

MPI_Request Utilities::MPI::CollectiveMutex::request

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

Definition at line 405 of file mpi.h.

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