libMesh::Threads Namespace Reference

Classes

class  BoolAcquire
 
class  Thread
 
class  atomic
 
class  spin_mutex
 
class  recursive_mutex
 
class  RangeBody
 
class  task_scheduler_init
 
class  split
 
class  BlockedRange
 
class  scalable_allocator
 

Typedefs

typedef std::thread Thread
 
typedef tbb::task_scheduler_init task_scheduler_init
 
typedef tbb::split split
 
typedef tbb::spin_mutex spin_mutex
 
typedef tbb::recursive_mutex recursive_mutex
 

Functions

template<typename Range , typename Body >
void parallel_for (const Range &range, const Body &body)
 
template<typename Range , typename Body , typename Partitioner >
void parallel_for (const Range &range, const Body &body, const Partitioner &partitioner)
 
template<typename Range , typename Body >
void parallel_reduce (const Range &range, Body &body)
 
template<typename Range , typename Body , typename Partitioner >
void parallel_reduce (const Range &range, Body &body, const Partitioner &partitioner)
 
unsigned int pthread_unique_id ()
 
template<typename Range >
unsigned int num_pthreads (Range &range)
 
template<typename Range , typename Body >
void * run_body (void *args)
 

Variables

bool in_threads = false
 
std::map< pthread_t, unsigned int > _pthread_unique_ids
 
spin_mutex _pthread_unique_id_mutex
 
spin_mutex spin_mtx
 
recursive_mutex recursive_mtx
 

Detailed Description

The Threads namespace is for wrapper functions for common general multithreading algorithms and tasks.

Typedef Documentation

typedef tbb::recursive_mutex libMesh::Threads::recursive_mutex

Recursive mutex. Implements mutual exclusion by busy-waiting in user space for the lock to be acquired. The same thread can aquire the same lock multiple times

Definition at line 314 of file threads.h.

typedef tbb::spin_mutex libMesh::Threads::spin_mutex

Spin mutex. Implements mutual exclusion by busy-waiting in user space for the lock to be acquired.

Definition at line 306 of file threads.h.

typedef tbb::split libMesh::Threads::split

Dummy "splitting object" used to distinguish splitting constructors from copy constructors.

Definition at line 169 of file threads.h.

typedef tbb::task_scheduler_init libMesh::Threads::task_scheduler_init

Scheduler to manage threads.

Definition at line 160 of file threads.h.

typedef tbb::tbb_thread libMesh::Threads::Thread

Use std::thread when available.

Fall back to tbb::tbb_thread when available.

Definition at line 114 of file threads.h.

Function Documentation

template<typename Range >
unsigned int libMesh::Threads::num_pthreads ( Range &  range)

Definition at line 442 of file threads.h.

References std::min(), and libMesh::n_threads.

443  {
444  unsigned int min = std::min((std::size_t)libMesh::n_threads(), range.size());
445  return min > 0 ? min : 1;
446  }
template<typename Range , typename Body >
void libMesh::Threads::parallel_for ( const Range &  range,
const Body &  body 
)
inline

Exectue the provided function object in parallel on the specified range.

Definition at line 180 of file threads.h.

References libMesh::PerfLog::disable_logging(), libMesh::PerfLog::enable_logging(), in_threads, libMesh::PerfLog::logging_enabled(), libMesh::n_threads, and libMesh::perflog.

Referenced by libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), libMesh::MeshCommunication::assign_global_indices(), libMesh::System::boundary_project_vector(), libMesh::DofMap::create_dof_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), parallel_for(), libMesh::FEMSystem::postprocess(), and libMesh::System::project_vector().

181  {
182  BoolAcquire b(in_threads);
183 
184 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
185  const bool logging_was_enabled = libMesh::perflog.logging_enabled();
186 
187  if (libMesh::n_threads() > 1)
189 #endif
190 
191  if (libMesh::n_threads() > 1)
192  tbb::parallel_for (range, body, tbb::auto_partitioner());
193 
194  else
195  body(range);
196 
197 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
198  if (libMesh::n_threads() > 1 && logging_was_enabled)
200 #endif
201  }
template<typename Range , typename Body , typename Partitioner >
void libMesh::Threads::parallel_for ( const Range &  range,
const Body &  body,
const Partitioner &  partitioner 
)
inline

Exectue the provided function object in parallel on the specified range with the specified partitioner.

Definition at line 212 of file threads.h.

References libMesh::PerfLog::disable_logging(), libMesh::PerfLog::enable_logging(), in_threads, libMesh::PerfLog::logging_enabled(), libMesh::n_threads, parallel_for(), and libMesh::perflog.

213  {
214  BoolAcquire b(in_threads);
215 
216 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
217  const bool logging_was_enabled = libMesh::perflog.logging_enabled();
218 
219  if (libMesh::n_threads() > 1)
221 #endif
222 
223  if (libMesh::n_threads() > 1)
224  tbb::parallel_for (range, body, partitioner);
225 
226  else
227  body(range);
228 
229 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
230  if (libMesh::n_threads() > 1 && logging_was_enabled)
232 #endif
233  }
template<typename Range , typename Body >
void libMesh::Threads::parallel_reduce ( const Range &  range,
Body &  body 
)
inline

Exectue the provided reduction operation in parallel on the specified range.

Definition at line 244 of file threads.h.

References libMesh::PerfLog::disable_logging(), libMesh::PerfLog::enable_logging(), in_threads, libMesh::PerfLog::logging_enabled(), libMesh::n_threads, and libMesh::perflog.

Referenced by libMesh::FEMSystem::assemble_qoi(), libMesh::MeshTools::bounding_box(), libMesh::DofMap::build_sparsity(), parallel_reduce(), libMesh::MeshTools::processor_bounding_box(), libMesh::System::project_vector(), libMesh::MeshTools::total_weight(), and libMesh::MeshTools::weight().

245  {
246  BoolAcquire b(in_threads);
247 
248 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
249  const bool logging_was_enabled = libMesh::perflog.logging_enabled();
250 
251  if (libMesh::n_threads() > 1)
253 #endif
254 
255  if (libMesh::n_threads() > 1)
256  tbb::parallel_reduce (range, body, tbb::auto_partitioner());
257 
258  else
259  body(range);
260 
261 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
262  if (libMesh::n_threads() > 1 && logging_was_enabled)
264 #endif
265  }
template<typename Range , typename Body , typename Partitioner >
void libMesh::Threads::parallel_reduce ( const Range &  range,
Body &  body,
const Partitioner &  partitioner 
)
inline

Exectue the provided reduction operation in parallel on the specified range with the specified partitioner.

Definition at line 276 of file threads.h.

References libMesh::PerfLog::disable_logging(), libMesh::PerfLog::enable_logging(), in_threads, libMesh::PerfLog::logging_enabled(), libMesh::n_threads, parallel_reduce(), and libMesh::perflog.

277  {
278  BoolAcquire b(in_threads);
279 
280 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
281  const bool logging_was_enabled = libMesh::perflog.logging_enabled();
282 
283  if (libMesh::n_threads() > 1)
285 #endif
286 
287  if (libMesh::n_threads() > 1)
288  tbb::parallel_reduce (range, body, partitioner);
289 
290  else
291  body(range);
292 
293 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
294  if (libMesh::n_threads() > 1 && logging_was_enabled)
296 #endif
297  }
unsigned int libMesh::Threads::pthread_unique_id ( )

When called by a thread this will return a unique number from 0 to num_pthreads-1 Very useful for creating long-lived thread local storage

Definition at line 35 of file threads.C.

References _pthread_unique_id_mutex, and _pthread_unique_ids.

36  {
37 #if LIBMESH_HAVE_OPENMP
38  return omp_get_thread_num();
39 #else
40  spin_mutex::scoped_lock lock(_pthread_unique_id_mutex);
41  return _pthread_unique_ids[pthread_self()];
42 #endif
43  }
template<typename Range , typename Body >
void* libMesh::Threads::run_body ( void *  args)

Definition at line 457 of file threads.h.

References libMesh::Threads::RangeBody< Range, Body >::body, and libMesh::Threads::RangeBody< Range, Body >::range.

458  {
459 
460  RangeBody<Range, Body> * range_body = (RangeBody<Range, Body>*)args;
461 
462  Body & body = *range_body->body;
463  Range & range = *range_body->range;
464 
465  body(range);
466 
467  return NULL;
468  }

Variable Documentation

Threads::spin_mutex libMesh::Threads::_pthread_unique_id_mutex

Definition at line 33 of file threads.C.

Referenced by pthread_unique_id().

std::map< pthread_t, unsigned int > libMesh::Threads::_pthread_unique_ids

Definition at line 32 of file threads.C.

Referenced by pthread_unique_id().

bool libMesh::Threads::in_threads = false

A boolean which is true iff we are in a Threads:: function It may be useful to assert(!Threadsin_threads) in any code which is known to not be thread-safe.

Definition at line 50 of file threads.C.

Referenced by parallel_for(), parallel_reduce(), libMesh::MeshBase::point_locator(), and libMesh::MeshBase::sub_point_locator().

Threads::recursive_mutex libMesh::Threads::recursive_mtx

A recursive mutex object which

Definition at line 49 of file threads.C.


Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:33 UTC

Hosted By:
SourceForge.net Logo