libMesh/libmesh — pull request #109 by friedmud (2013-06-30 16:10:49+00:00)
Title: Pthread

Initial implementation of a TBB-like interface using straight pthreads.

I'm doing this for a couple of reasons:

1. Reduce dependencies
2. Portability. Pthreads work better on a wider range of hardware (including Blue Gene, some Crays, Intel Phi and more).
3. More control over work partitioning.
4. Better threaded debugging. Helgrind works better with straight pthreads as do a lot of other thread inspection tools.
5. Profit!!!!!

This is just an initial implementation so there are some inefficiencies:

1. No thread pool. Right now threads are started and stopped as needed. I might end up using the thread pull from a threaded compile of PETSc... or I might write my own. But it's not necessary for now.
2. spin_mutex doesn't spin! This is because OSX doesn't actually implement the pthread_spin_mutex... so to keep things simple I'm just using a regular mutex. I'll specialize this for different architectures later (OSX does implement a spin mutex... just not through the normal pthread stuff.... argh!)
3. The partitioning algorithm is extremely simple. The range is simply divided with anything leftover just going to the last thread. I might change this later so that the remainder is spread across more than the last thread. Unnecessary for now.

A couple of extra notes on this set of patches:

1. In order to use this pthread interface you must implement one more constructor for your Range objects. It is a "copy" constructor (that doesn't need to copy the data) that allows for setting the begin and end iterators (essentially allowing a direct creation of a specific subrange). This is because I wanted a very simple partitioning algorithm (that's part of the reason I'm doing this). I've already done it for StoredRange... so most libMesh applications (and libMesh itself) just work without modification (MOOSE did!). Only someone that is creating their own Range objects from scratch would get hit with a compile error if they try to use this interface.

2. Both TBB and this new interface are enabled by default if they are found. For backwards compatibility I made TBB take precedence though. So to use the new interface you must use "--disable-tbb" if you have your environment setup for TBB (or you could remove TBB from your environment...).