API Classes
MThreadPool, MThreadAsync, MSpinLock, MMutexLock - main threading classes, described in detail in this chapter. Added in Maya 2008.
MAtomic.h - cross-platform atomic operations. Added in Maya 2009.
MThreadUtils.h - functions to synchronize plug-in OpenMP thread counts with Maya. These functions must be used by any plug-in using OpenMP
with a compiler other than the Intel compiler. Added in Maya 2009.
Example plug-ins shipped with Maya
- threadTestCmd - usage example of MThreadPool. Shows how to initialize and manage the pool, create tasks that will be mapped to threads,
and combine data from the threads to evaluate the final result.
- threadTestWithLocksCmd - usage example of MThreadPool, MThreadAsync, MSpinLock, MMutexLock. This plug-in evaluates pi using multiple threads. It builds on the previous threadTestCmd example by adding examples showing the use of the various lock types provided by the Maya API to update a global variable,
and also has an example of parallel evaluation using asynchronous threads combined with a barrier construct that causes the
threads to synchronize when they are finished. A thread pool automatically synchronizes. Note that the examples in this plug-in
are for illustration purposes, and are not intended to demonstrate maximum efficiency in all cases. For example, the locking
methods are clearly inefficient, but do demonstrate usage of locks in real code.
- splatDeformer - example of threadsafe deformer plug-in. This is described in more detail in the body of this document. To use the plug-in,
create two dense poly meshes nested one inside the other, select the inner then the outer, and invoke the deformer using the
associated mel script. Adjusting the envelope attribute causes recomputes, which can be used to judge performance. Adjust
the number of active threads to check scaling performance using the mel command threadCount -n <numThreads>. Requires OpenMP.
- sseDeformer - example of autovectorization using Intel compiler
- threadedBoundingBox - example of false sharing. Create a large (for example, 1 million poly) primitive and invoke the command. Requires OpenMP.
- threadingLockTests - performance test for MSpinLock, MMutexLock, and atomic operations. Requires OpenMP.