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

Constructor & Destructor Documentation

ParallelUniqueId::ParallelUniqueId ( )
inline

Definition at line 38 of file ParallelUniqueId.h.

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

Definition at line 59 of file ParallelUniqueId.h.

60  {
61 #ifdef LIBMESH_HAVE_TBB_API
62  _ids.push(id);
63 #elif !defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD)
64  Threads::spin_mutex::scoped_lock lock(_pthread_id_mutex);
65 
66  _ids.push(id);
67 #endif
68  }
static tbb::concurrent_bounded_queue< unsigned int > _ids
static Threads::spin_mutex _pthread_id_mutex

Member Function Documentation

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

Referenced by MooseInit::MooseInit().

75  {
76  if (!_initialized)
77  {
78  _initialized = true;
79 
80 #if defined(LIBMESH_HAVE_TBB_API) || \
81  (!defined(LIBMESH_HAVE_OPENMP) && defined(LIBMESH_HAVE_PTHREAD))
82  for (unsigned int i = 0; i < libMesh::n_threads(); ++i)
83  _ids.push(i);
84 #endif
85  }
86  }
static tbb::concurrent_bounded_queue< unsigned int > _ids
static bool _initialized

Member Data Documentation

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

Definition at line 92 of file ParallelUniqueId.h.

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

Definition at line 94 of file ParallelUniqueId.h.

bool ParallelUniqueId::_initialized = false
staticprivate

Definition at line 98 of file ParallelUniqueId.h.

Threads::spin_mutex ParallelUniqueId::_pthread_id_mutex
staticprivate

Definition at line 95 of file ParallelUniqueId.h.

THREAD_ID ParallelUniqueId::id

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