Question

I want to learn multi-core programming in c++, could you recommend me some notes, please? And What are the differences among pthread, Intel TBB and openmp? which library could use the Intel CPU more efficiently? Thanks.

Was it helpful?

Solution

These three are completely separate things. Pthreads is the native threading API of many modern Unix OSes that conform to the POSIX specification, including but not limited to Linux, OS X, FreeBSD and Solaris. There is also a badly supported and not very well working Pthreads implementation for Windows (Windows has its own native Win32 threading API). Pthreads is designed to support general threading scenarios and building parallel processing applications with it comes at a very high price (in number of code lines).

Intel TBB is a portable and open-source C++ template library for parallel data processing on shared memory architectures and implements tasks and task flows. This works especially well in conjunction with the new C++ lambdas (anonymous code blocks). The library could be built with many different compilers and for different architectures. On POSIX systems TBB builds upon Pthreads as the underlying threading API.

OpenMP is a directive-based extension to C/C++ and Fortran that supports data and task parallelism on shared memory architectures. It is not a library but rather a language extension and requires an OpenMP-enabled compiler. Virtually all modern C++ compilers - with the notable exception of Clang - support OpenMP, including the PGI, Oracle and MSVC++ compilers and GCC. On POSIX systems the OpenMP runtimes are built on top of Pthreads. Version 4.0 supports accelerator devices, e.g. GPUs and co-processors like Intel Xeon Phi.

Of all the three, Intel TBB is the most flexible while OpenMP is the easiest to learn. Pthreads is neither portable (e.g. badly supported on Windows), nor easy to learn. As already mentioned by Claudio, C++11 includes its own threading primitives, implemented on POSIX systems using Pthreads. But these are more like language abstractions around the threading API than parallel processing libraries/extensions like ITBB and OpenMP.

OTHER TIPS

With the C++11 standard, C++ now has native support for multithreading, without the need of any external library. It is already available on Visual Studio 2012, Gcc 4.7+ and Clang.

For what concerns your additional questions:

  • pthread (which stands for "POSIX threads") is a multithread library for POSIX (i.e., Unix/Linux) systems. It does only multithreading since POSIX already supports multitasking (i.e., through the fork primitive). It works on all hardware platforms running a POSIX OS (e.g., Desktops, embedded Linux, and so on).

  • OpenMP is a portable library for multi-core programming in C/C++ and Fortran. The latest version is 4.0 which has support also for asynchronous calls.

  • Intel TBB supports Windows and Linux on Intel architectures. Running TBB on platforms different than Intel (e.g., ARM) is quite complicated (see here)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top