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

Constructor & Destructor Documentation

◆ ParallelUniqueId()

ParallelUniqueId::ParallelUniqueId ( )
inline

Definition at line 33 of file ParallelUniqueId.h.

34  {
35 #ifdef LIBMESH_HAVE_TBB_API
36  _ids.pop(id);
37 #elif LIBMESH_HAVE_OPENMP
38  id = omp_get_thread_num();
39 #elif LIBMESH_HAVE_PTHREAD
40  Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
41 
42  if (_ids.empty())
43  throw MooseException(
44  "No Thread IDs available in ParallelUniqueID. Did you forget to initialize()?");
45 
46  id = _ids.front();
47  _ids.pop();
48 #else
49  // There is no thread model active, so we're always on thread 0.
50  id = 0;
51 #endif
52  }
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 54 of file ParallelUniqueId.h.

55  {
56 #ifdef LIBMESH_HAVE_TBB_API
57  _ids.push(id);
58 #elif !defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD)
59  Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
60 
61  _ids.push(id);
62 #endif
63  }
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 69 of file ParallelUniqueId.h.

Referenced by MooseInit::MooseInit().

70  {
71  if (!_initialized)
72  {
73  _initialized = true;
74 
75 #if defined(LIBMESH_HAVE_TBB_API) || \
76  (!defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD))
77  for (unsigned int i = 0; i < libMesh::n_threads(); ++i)
78  _ids.push(i);
79 #endif
80  }
81  }
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 87 of file ParallelUniqueId.h.

◆ _ids [2/2]

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

Definition at line 89 of file ParallelUniqueId.h.

◆ _initialized

bool ParallelUniqueId::_initialized = false
staticprivate

Definition at line 93 of file ParallelUniqueId.h.

◆ _pthread_id_mutex

Threads::spin_mutex ParallelUniqueId::_pthread_id_mutex
staticprivate

Definition at line 90 of file ParallelUniqueId.h.

◆ id

THREAD_ID ParallelUniqueId::id

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