The Software Purist |

CAT | Intel Threading-Building Blocks

This is a post I decided to migrate from my old blog and ultimately removed from my old blog.  Hopefully you will find the information useful:

I spent a little time reviewing threading technologies. OpenMP is the option that gets the most attention, because it’s an open standard and is the most likely to stick around. However, in my review, I stumbled upon Intel Threading-Building Blocks, and I have to say it’s a better option, despite being a commercial library. Here’s a head-to-head comparison from my PoV:

1) Compiler support: OpenMP uses pragmas, so it needs explicit compiler support, although most of the newer compilers support it. TBB is a portable library, so it can be built and added for older compilers. As Stroustrop says, it’s better to have something added as a library rather than keywords and compiler directives, because it opens up possibilities. Advantage: TBB.

2) Code clarity: In cases where OpenMP can be used, OpenMP involves very little work in modifying code if you have a parallelizable loop, for example. TBB involves functors, and while STL algorithms are nice, it’s also nice to have the ability to do things inline. I give OpenMP the edge, because in the best case, OpenMP is a little cleaner. In the worst case, TBB may be cleaner, but I’ll give this one to OpenMP. Advantage: OpenMP

3) C++ Support. OpenMP is clearly not targetted towards C++ programmers. It doesn’t support many important C++ constructs. TBB seems to support these better. The iterator support is quite important. I understand that OpenMP intends to be support C++ with the 3.0 spec, but it’s still quite lacking. Advantage: TBB

4) Concurrent containers. OpenMP has nothing for extra C++ support. TBB has a few concurrent containers and I believe there’s more in the next version. I can’t express how many times I would’ve parallelized a piece of code if I had something like concurrent_queue available. Major props, Intel. Huge Advantage: TBB

5) Exceptions. OpenMP has an issue where you throw an exception into an OpenMP thread and the behavior is undefined. This is not surprising, but they have no plans to correct this issue. This issue alone makes OpenMP unusable for production code, because there’s too much work to do to make OpenMP handle exceptions correctly. TBB states an intent to acknowledge exception handling and propagate the first exception. I believe it does this correctly. Advantage: TBB

Overall, as a C++ programmer, I think TBB wins on almost all aspects. Since it’s using threading underneath, it’s clear to me that you can achieve similar speed-ups with both. I believe TBB gives more opportunity for taking existing C++ code and making smaller modifications, while OpenMP would require you to “dumb down” your code to C level in order to take advantage of things. If you’re a C programmer, I don’t have any doubt, however, that you’d want to consider OpenMP. TBB is the C++-friendly version of OpenMP, as far as I’m concerned.

· · · · ·

Theme Design by devolux.nh2.me