C ++ Concurrency Libraries: OpenMP vs. Thread building blocks

I am going to modify my own graphics engine to use multi-core processors. More precisely, I am looking for a library for loop parallelization.

It seems to me that both OpenMP and Intel Thread Building Blocks are very well suited for work. In addition, both of them are supported by the Visual Studio C ++ compiler and most other popular compilers. And both libraries seem pretty easy to use.

So which one should I choose? Has anyone tried both libraries and can give me some minuses and advantages of using any library? Also, what did you decide to work with at the end?

Thank,

Adrian

+41
c ++ multithreading openmp multicore tbb
Mar 05 '09 at 15:28
source share
8 answers

I have not used TBB extensively, but I feel that they complement each other more than they compete. TBB provides thread-safe containers and some parallel algorithms, while OpenMP is more a way to parallelize existing code.

Personally, I found that OpenMP is very easy to insert into existing code, where you have a parallelizable loop or a bunch of sections that you can run in parallel. However, this does not particularly help you when you need to change some common data - where the simultaneous TBB containers may be exactly what you want.

If all you need is loop parallelization where the iterations are independent (or they can be pretty easy to do), I would go for OpenMP. If you need more interaction between threads, I think that TBB can offer a little more in this regard.

+43
Mar 05 '09 at 20:46
source share

From the Intel Software Blog: Compare Windows *, OpenMP *, Intelยฎ Threading Building Blocks for Parallel Programming Streams

This is also a style issue - for me, TBB is very similar to C ++, while I do not like OpenMP pragmas, which is a lot (it smells of C bits, it will use it if I had to write in C).

I would also consider the existing knowledge and experience of the team. Learning a new library (especially when it comes to streaming / concurrency) takes some time. I think that at the moment OpenMP is more widely known and deployed than TBB (but this is only my opinion).

Another factor - but given most common platforms, may not be a problem - portability. But a license can be a problem.

  • TBB includes some interesting studies derived from academic studies, such as a recursive parallel data approach .
  • There is some work to ensure the convenience of caching, for example .
  • The Intel blog lecture seems really interesting.
+25
Mar 05 '09 at 15:41
source share

In general, I found that using TBB requires much more time-consuming changes to the high-performance code base, while OpenMP provides a quick but moderate gain. If you are looking at a new module from scratch and think for a long time, get involved in TBB. If you want to get a small but immediate gain, use OpenMP.

In addition, TBB and OpenMP are not mutually exclusive.

+15
Mar 06 '09 at 10:51
source share

I really used both, and my general impression is that if your algorithm is pretty easy to make parallel (for example, even-sized loops, not too much data interdependence), OpenMP is easier and fun to work with. In fact, if you find that you can use OpenMP, this is probably the best way to go if you know that your platform will support it. I did not use the new OpenMP task structures, which are much more general than the original loop and section parameters.

TBB gives you more data structures in front, but it definitely requires a bigger edge. As a plus, it might be better if you find out about problems with the conditions of the race. I mean, in OpenMP, it's pretty easy to incorporate race conditions without creating something in common (or something else) that should be. You only see this when you get bad results. I think this is a little less likely with TBB.

In general, my personal preference was for OpenMP, especially considering its increased expressiveness with tasks.

+5
Apr 28 '09 at 11:54
source share

Viva64 Links: Parallel Programming .

+2
Mar 06 '09 at 8:11
source share

Yes, TBB is much more C ++ friendly, while OpenMP is more suitable for FORTRAN style code, given its design. The new task function in OpenMP looks very interesting, and at the same time, the Lambda object and functions in C ++ 0x can facilitate the use of TBB.

+2
Jan 24 '13 at 6:51
source share

In Visual Studio 2008, you can add the following line to parallelize any for loop. It works even with multiple nested loops. Here is an example:

#pragma omp parallel for private(i,j) for (i=0; i<num_particles; i++) { p[i].fitness = fitnessFunction(p[i].present); if (p[i].fitness > p[i].pbestFitness) { p[i].pbestFitness = p[i].fitness; for (j=0; j<p[i].numVars; j++) p[i].pbest[j] = p[i].present[j]; } } gbest = pso_get_best(num_particles, p); 

After adding the #pragma omp parallel, both cores on my Core 2 Duo were used for maximum capacity, so overall CPU usage ranged from 50% to 100%.

+1
Jun 28 2018-10-18T00:
source share

As far as I know, TBB (there is an OpenSource version under GPLv2 avaiable) addresses C ++ more and then C Area. At these times, it is difficult to find C ++ and general OOP-parallelization of specific Information. Most addresses of functional things, such as c (same on CUDA or OpenCL). If you need C ++ support for parallelization, go to TBB!

+1
Jan 10 '12 at 7:14
source share



All Articles