Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pthread vs intel TBB and their relation to OpenMP?

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?

like image 330
60080 Avatar asked Dec 29 '12 14:12

60080


People also ask

Is OpenMP based on 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.

Is pthread still used?

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.

What are pthreads in operating system?

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.

Is pthread a standard library?

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.


2 Answers

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.

like image 105
Andrew Tomazos Avatar answered Sep 27 '22 18:09

Andrew Tomazos


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...

like image 26
Mats Petersson Avatar answered Sep 27 '22 16:09

Mats Petersson