www.mooseframework.org
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! More...
 

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 29 of file ParallelUniqueId.h.

Constructor & Destructor Documentation

◆ ParallelUniqueId()

ParallelUniqueId::ParallelUniqueId ( )
inline

Definition at line 32 of file ParallelUniqueId.h.

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

◆ ~ParallelUniqueId()

ParallelUniqueId::~ParallelUniqueId ( )
inline

Definition at line 53 of file ParallelUniqueId.h.

54  {
55 #ifdef LIBMESH_HAVE_TBB_API
56  _ids.push(id);
57 #elif !defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD)
58  Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
59 
60  _ids.push(id);
61 #endif
62  }
static tbb::concurrent_bounded_queue< unsigned int > _ids
static Threads::spin_mutex _pthread_id_mutex

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 68 of file ParallelUniqueId.h.

Referenced by MooseInit::MooseInit().

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

Member Data Documentation

◆ _ids [1/2]

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

Definition at line 86 of file ParallelUniqueId.h.

◆ _ids [2/2]

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

Definition at line 88 of file ParallelUniqueId.h.

◆ _initialized

bool ParallelUniqueId::_initialized = false
staticprivate

Definition at line 92 of file ParallelUniqueId.h.

◆ _pthread_id_mutex

Threads::spin_mutex ParallelUniqueId::_pthread_id_mutex
staticprivate

Definition at line 89 of file ParallelUniqueId.h.

◆ id

THREAD_ID ParallelUniqueId::id

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