For multi-thread programming, with the considerations of combinations with HPC application (MPI), which one is better, can we say, in terms of functionality, Intel TBB (thread building block) is comparable to pthread or not? I only get experience in open mp, but I heard both TBB and Pthread offers finer thread control comparing to open mp, but can TBB or TBB+OpenMP offer similiar functionality compared to pthread?
On a linux system, it is very highly likely that the OpenMP API itself uses pthreads to implement its features such as parallelism, barriers and locks/mutex. Having said that, there are good reasons to work directly with the pthreads API.
Yes, the pthreads library is still used for threading. There are some higher level libraries (boost, or if you have a c++ 11 compliant compiler, the standard library) that will also give you threading capabilities, although for somethings you will still need to fall back to the plain pthread call.
POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time.
POSIX thread (pthread) libraries. The POSIX thread libraries are a standards based thread API for C/C++. It allows one to spawn a new concurrent process flow.
pthread is a thin wrapper above the OS infrastructure. It allows you to create a thread with a given thread main function, and some synchronization primitives (mutexes semaphores etc). Under Linux pthread is implemented on top of the clone(2)
system call. The equivilant under Windows is called CreateThread
. All the other threading stuff is built on top of this base.
Intel TBB is higher level, it gives parallel_for
and parallel_reduce
and similiar higher level constructs similar to OpenMP but implemented as a library not a language extension.
OpenMPI is even higher level still with multi-machine distributed infrastructure, but it is very old fashioned and a little clunky.
My advice would be to learn the pthread library first until you completely understand it, and then look at higher level libraries afterward.
TBB allows you to write portable code on top of the native threading functionality, so it makes the code more portable over different OS architectures. I don't think it's "more efficient" than pthread.
I haven't used open MP personally, but in the past I've worked with developers using open MP (as a technical specialist on the processors they were using), and it seems to work reasonably well for certain things, but others are harder to use in open mp than writing your own code. It all depends on what exactly you are doing. One of the benefits with openmp of course is that you can always recompile the code without the openmp option, and the code just works directly as you expect it to [but not spread out, of course].
With a programmes threading approach, you can have much more control over exactly what happens on what thread, yes. But it also means a lot more work...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With