C++ API Reference
|
Helper methods for threaded plugins. More...
#include <MThreadUtils.h>
Static Public Member Functions | |
static int | getNumThreads () |
Return number of threads currently being used by Maya. More... | |
static void | syncNumOpenMPThreads () |
Maya uses the Intel compiler for OpenMP internally. More... | |
static int | getCacheLineSize () |
Return cache line size for current processor. More... | |
Helper methods for threaded plugins.
Thread count controls
The user can control the number of threads currently running in Maya. This is useful for example to run rendering in a single thread when multiple frames are being rendered in parallel by different instances of Maya. All code should respect this thread count, so if a plugin is threaded, it needs to query the current thread count being used by Maya and set that threadcount for itself.
For a plugin-local thread pool using Win32 or pthreads, use the getNumThreads() method to check the required number of threads and set the number of threads in the plugin thread pool appropriately.
If using the Maya API MThreadPool class there is no need to do anything as this is an internal Maya thread pool that respects the user-defined thread count setting.
If using the Intel compiler, there is no need to do anything as the threadcount is set globally for the Intel compiler.
If using OpenMP with gcc on OSX and Linux, or Visual C++ on Windows, it is necessary to call the syncNumOpenMPThreads to ensure the correct threadcount is set in the plugin.
Cache line size control
The cache line size is important information when code may have false sharing problems. Use the query method to ensure data that will be modified by multiple threads is on separate cache lines.
|
static |
Return number of threads currently being used by Maya.
Users can modify the number of threads being used in Maya thread pools via the threadCount mel command. It is important for plugins to respect this settings, so a plugin should call this method to query the current threadcount when creating it's own threaded region using OpenMP. If the threads are created using the MThreadPool class, no action needs to be taken since the number of threads in this class always respects the threadCount command number.
|
inlinestatic |
Maya uses the Intel compiler for OpenMP internally.
A plugin may be built using VC++ or gcc, both of which have OpenMP thread pools that are incompatible with Intel's. For these thread pools to respect the Maya thread count, it is important to initialize the number of threads explicitly for these implementations of OpenMP. This is done by calling this function in the plugin, which queries the current the threadcount from Maya and applies it to the plugin OpenMP implementation.
This function does not need to be called if the plugin is compiled with the Intel compiler.
|
static |
Return cache line size for current processor.
This value can be used for padding to avoid false sharing.
Note that the value is queried explicitly only for processors supporting SSE3. For other processors the cache line size is assumed to be 64 bytes.