Intel Threading Building Blocks (TBB)
 
 
 

Overview of TBB

TBB is a relatively new higher level API for threading, supplied by Intel. It replaces the concept of threads with the concept of tasks, which are defined by the user and queued up. TBB then maps those tasks to threads efficiently.

TBB is available on all platforms Maya supports. It provides wrappers for common functionality such as for, while, reduce and sort operations. It also provides atomic primitives, a scalable memory allocator (allocators such as malloc access the global heap and so are locking operations, leading to contention when many threads are working with memory.) Finally there are threadsafe containers based on STL, such as lists, queues and hash maps. Note that these threadsafe containers have poorer single threaded performance than regular containers, since they usually require internal locking, so they should be used only when required for threadsafety.

Pros and cons of TBB

TBB is a higher level library than OpenMP and provides increased flexibility at the cost of greater complexity. Parallel code must be extracted into separate classes, which is more invasive than OpenMP.

The task-based approach avoids the problem of oversubscription encountered with OpenMP. Maya makes use of TBB in several places, partly to avoid the oversubscription issues of OpenMP, and partly to make use of the higher level algorithms and containers. Writing threadsafe cross-platform primitives and containers is remarkably difficult, and using a third party library designed for the purpose allows developers to focus on optimizing their specific application rather than building the required threading infrastructure.

Although TBB is used by Maya, it is not exposed in a way that plug-in writers can access directly, so a license must be acquired for a developer wishing to use TBB in their own plug-ins. There is no requirement to use TBB when threading Maya plug-ins, however the Maya API does provide an indirect way for plug-ins to use TBB without needing their own license. See Threading and Maya for more information.

Note that version compatibility is important for TBB. For Maya it is necessary to use TBB version 2.1.012.