3ds Max C++ API Reference
ThreadTools Class Reference

This class lets control the amount of threading in different parts of Max *‍/. More...

#include <PerformanceTools.h>

+ Inheritance diagram for ThreadTools:

Public Types

enum  ThreadType { kMeshThreading = 0 , kDeformationThreading , kHWMeshCreationThreading , kEndThreading }
 

Public Member Functions

UtilExport unsigned int GetNumberOfThreads (ThreadType threadType, unsigned int numberElements)
 This method returns the actual number of threads to be used for a particular task depending on the number of elements. More...
 

Static Public Member Functions

static UtilExport void SetNumberOfThreads (ThreadType threadType, unsigned int maxNumThreads, unsigned int minElementsPerThread)
 This method lets you set the number of threads on various parts of Max. More...
 
static UtilExport unsigned int GetNumberOfThreads (ThreadType threadType)
 This method returns the maximum number of threads on various parts used by Max. More...
 
static UtilExport unsigned int GetMinNumberElements (ThreadType threadType)
 This method returns the minimum number elements in each threads on various parts used by Max. More...
 
static UtilExport size_t TbbGrainsize (size_t iterationCount)
 This method returns the optimal grainsize to be used with Intel's TBB parallel_for and similar functions. More...
 
static UtilExport void SetTbbMaxThreads (int numThreads)
 This method sets the maximum number of threads for Tbb. More...
 
static UtilExport size_t GetTbbMaxThreads ()
 This method return the maximum number of threads for Tbb. More...
 
- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

This class lets control the amount of threading in different parts of Max *‍/.

Member Enumeration Documentation

◆ ThreadType

enum ThreadType
Enumerator
kMeshThreading 
kDeformationThreading 
kHWMeshCreationThreading 
kEndThreading 
28  { kMeshThreading = 0, //the internal threading to mesh this mainly building normals, some clip operations, and vec normalization
29  kDeformationThreading, //this controls the threading of the simple deformation class that is used by modifiers like bend, skin, skinwrap etc
30  kHWMeshCreationThreading, //this the numbers of threads used to create the DirectX hardware meshes
31  kEndThreading // do not use this just signifies the end of the enumeration. Insert any new enumeration above this one
32  } ;
@ kEndThreading
Definition: PerformanceTools.h:31
@ kMeshThreading
Definition: PerformanceTools.h:28
@ kDeformationThreading
Definition: PerformanceTools.h:29
@ kHWMeshCreationThreading
Definition: PerformanceTools.h:30

Member Function Documentation

◆ SetNumberOfThreads()

static UtilExport void SetNumberOfThreads ( ThreadType  threadType,
unsigned int  maxNumThreads,
unsigned int  minElementsPerThread 
)
static

This method lets you set the number of threads on various parts of Max.

This method lets you set the maximum number of threads on various parts of Max. It also lets you set the minimum number of elements for each thread to prevent excessiving threading. It does not prevent you from oversubscribing threads.

Parameters
[in]threadTypethis is which part of Max you want to set the multi-thread level
[in]maxNumThreadsthis is the maximum number of threads to use for this operation. This is not limited so you can over subscribe and have more threads than CPUs.
[in]minElementsPerThreadthis is used to restrict the number of threads. It controls the number of threads to use limited by maxNumThreads. The number of threads used equal to numberElements/minElementsPerThread. So for instance the KMeshThreads in the elements are the faces/vertices. This is here to prevent too few elements per thread. If set to 0 or less this value will be ignored and the numThreads will be used.

◆ GetNumberOfThreads() [1/2]

static UtilExport unsigned int GetNumberOfThreads ( ThreadType  threadType)
static

This method returns the maximum number of threads on various parts used by Max.

This method returns the maximum number of threads on various parts of used by Max.

Parameters
[in]threadTypethis is which part of Max you want to set the multi-thread level

◆ GetMinNumberElements()

static UtilExport unsigned int GetMinNumberElements ( ThreadType  threadType)
static

This method returns the minimum number elements in each threads on various parts used by Max.

This method returns the minimum number elements in each threads on various parts used by Max

Parameters
[in]threadTypethis is which part of Max you want to set the multi-thread level

◆ GetNumberOfThreads() [2/2]

UtilExport unsigned int GetNumberOfThreads ( ThreadType  threadType,
unsigned int  numberElements 
)

This method returns the actual number of threads to be used for a particular task depending on the number of elements.

This method returns the actual number of threads to be used for a particular task depending on the number of elements

Parameters
[in]threadTypethis is which part of Max you want to get the multi-thread level
[in]numberElementsis the number of elements in the loop to thread

◆ TbbGrainsize()

static UtilExport size_t TbbGrainsize ( size_t  iterationCount)
static

This method returns the optimal grainsize to be used with Intel's TBB parallel_for and similar functions.

It will cap the amount of work according to the number of threads available - 1, or the setting in your preference ini file. If the MaxThreads setting is higher than number of threads available -1, we cap the thread count.

Parameters
[in]iterationCountthis is the number of elements you will iterate over

◆ SetTbbMaxThreads()

static UtilExport void SetTbbMaxThreads ( int  numThreads)
static

This method sets the maximum number of threads for Tbb.

This value should be set in the currentdefaults.ini preference file.

Parameters
[in]numThreadsThe number of threads to use, -1 for max available threads.

◆ GetTbbMaxThreads()

static UtilExport size_t GetTbbMaxThreads ( )
static

This method return the maximum number of threads for Tbb.

It returns the appropriate value, not the value set in the preferences.

Returns
numThreads The number of threads tbb will use, between 1 and max threads - 1.