OpenMP
TBB
- http://threadingbuildingblocks.org/
- http://www.intel.com/cd/software/products/asmo-na/eng/294797.htm
- http://en.wikipedia.org/wiki/Intel_Threading_Building_Blocks
選擇OpenMP or TBB
First, you’ll want to look at the development environment. If the code is written in C++, it’s likely that TBB is the best fit. TBB matches especially well with the code that is highly object oriented, and makes heavy use of C++ templates and user defined types. . If the code is written in C or FORTRAN, OpenMP may be the better solution because it fits better than TBB into a structured coding style and for simple cases, it introduces less coding overhead. TBB and native threads don’t require specific compiler support; OpenMP does. The use of OpenMP requires that you compile with a compiler that recognizes OpenMP pragmas.
Next, look at what you want to make parallel. Use OpenMP if the parallelism is primarily for bounded loops over built-in types, or if it is flat do-loop centric parallelism. OpenMP works especially well with large and predictable data parallel problems. It can be very challenging to match OpenMP performance with TBB for such problems. It is seldom worth the effort to bother – just use OpenMP. TBB excels at the common problem of having less structured or consistent parallelism in a program.
TBB relies on generic programming; use its loop parallelization patterns if you need to work with custom iteration spaces or complex reduction operations. Also, consider using TBB if you need to go beyond loop-based parallelism, since it provides generic parallel patterns for parallel while-loops, data-flow pipeline models, parallel sorts and prefixes.
Finally, what happens if you come upon a case where either TBB or OpenMP could be a usable option? Then you would look at the features within the APIs. If you need features exclusive to OpenMP, then choose OpenMP. If you need features exclusive to TBB, then use TBB. If the features you need are available with both TBB and OpenMP, then we recommend you use TBB. If you already are using OpenMP for such features, and plan to add TBB moving forward, then it would be a good idea to replace the OpenMP code with TBB. The reason why is because TBB is designed to anticipate incremental parallelization - allowing additional parallelization without creating unnecessary threads that can lead to over-utilization.
And TBB and OpenMP can coexist. You can utilize TBB in part of your application while using OpenMP in another part. That way you can use the tool which best fit the problem.