https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Private Attributes | List of all members
ParallelUniqueId Class Reference

#include <ParallelUniqueId.h>

Public Member Functions

 ParallelUniqueId ()
 
 ~ParallelUniqueId ()
 

Static Public Member Functions

static void initialize ()
 Must be called by main thread before any threaded computation! Do NOT call in a worker thread!
 

Public Attributes

THREAD_ID id
 

Static Private Attributes

static tbb::concurrent_bounded_queue< unsigned int_ids
 
static std::queue< unsigned int_ids
 
static Threads::spin_mutex _pthread_id_mutex
 
static bool _initialized = false
 

Detailed Description

Definition at line 27 of file ParallelUniqueId.h.

Constructor & Destructor Documentation

◆ ParallelUniqueId()

ParallelUniqueId::ParallelUniqueId ( )
inline

Definition at line 30 of file ParallelUniqueId.h.

31 {
32#ifdef LIBMESH_HAVE_TBB_API
33 _ids.pop(id);
34#elif LIBMESH_HAVE_OPENMP
35 id = omp_get_thread_num();
36#elif LIBMESH_HAVE_PTHREAD
37 Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
38
39 if (_ids.empty())
40 throw MooseException(
41 "No Thread IDs available in ParallelUniqueID. Did you forget to initialize()?");
42
43 id = _ids.front();
44 _ids.pop();
45#else
46 // There is no thread model active, so we're always on thread 0.
47 id = 0;
48#endif
49 }
Provides a way for users to bail out of the current solve.
static tbb::concurrent_bounded_queue< unsigned int > _ids
static Threads::spin_mutex _pthread_id_mutex

◆ ~ParallelUniqueId()

ParallelUniqueId::~ParallelUniqueId ( )
inline

Definition at line 51 of file ParallelUniqueId.h.

52 {
53#ifdef LIBMESH_HAVE_TBB_API
54 _ids.push(id);
55#elif !defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD)
56 Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
57
58 _ids.push(id);
59#endif
60 }

Member Function Documentation

◆ initialize()

static void ParallelUniqueId::initialize ( )
inlinestatic

Must be called by main thread before any threaded computation! Do NOT call in a worker thread!

Definition at line 66 of file ParallelUniqueId.h.

67 {
68 if (!_initialized)
69 {
70 _initialized = true;
71
72#if defined(LIBMESH_HAVE_TBB_API) || \
73 (!defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD))
74 for (unsigned int i = 0; i < libMesh::n_threads(); ++i)
75 _ids.push(i);
76#endif
77 }
78 }
static bool _initialized
unsigned int n_threads()

Referenced by MooseInit::MooseInit().

Member Data Documentation

◆ _ids [1/2]

std::queue< unsigned int > ParallelUniqueId::_ids
staticprivate

Definition at line 84 of file ParallelUniqueId.h.

Referenced by initialize(), ParallelUniqueId(), and ~ParallelUniqueId().

◆ _ids [2/2]

std::queue<unsigned int> ParallelUniqueId::_ids
staticprivate

Definition at line 86 of file ParallelUniqueId.h.

◆ _initialized

bool ParallelUniqueId::_initialized = false
staticprivate

Definition at line 90 of file ParallelUniqueId.h.

Referenced by initialize().

◆ _pthread_id_mutex

Threads::spin_mutex ParallelUniqueId::_pthread_id_mutex
staticprivate

Definition at line 87 of file ParallelUniqueId.h.

Referenced by ParallelUniqueId(), and ~ParallelUniqueId().

◆ id

THREAD_ID ParallelUniqueId::id

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