How can I evaluate if I’d benefit from using Intel TBB with VTK?
That is, is there a list of VTK classes that use it? Or is there some TBB bottleneck function that I could put a breakpoint on to see if my app’s use of VTK involves anything that uses TBB?
If you have an application that is large enough so that you cannot manually tune number of threads in each filter then you must use a backend that supports thread pools (TBB or OpenMP). See for example why we had to switch to TBB in Slicer: https://github.com/Slicer/Slicer/pull/930
My question is more like: VTK is a big library. I only use parts of it. Maybe the parts I use don’t ever use TBB, how can I tell? For a silly example, if the only VTK class I use is vtkMatrix4x4, then (I assume) I’d be wasting my time adding TBB.
If you use any multi-threaded filter then you may benefit from using a non-sequential backend, because creation of hundreds of threads per second (this is what the sequential backend does) may have an enormous overhead on its own and it may also interfere with NVidia’s threaded optimization heuristics.
If you use VTK in a product where you control all the hardware, drivers, operating system settings, and other concurrently running applications then you can just test in that environment to see if benefits of using TBB are significant. If you develop a product that the user can install on his own computer then your best bet is to use TBB to prevent any surprises.
There are also a few filters that are specifically designed for parallel backends (flying edge filter, etc.) that are very slow if you use the sequential backend.
If you look at the source code of a filter then it is obvious if it is multi-threaded or not. For example, if vtkMultiThreader.h is included in the .cxx file then most likely it is a multi-threaded filter.
In addition to the classes that use vtkSMPTools directly, all classes derived from vtkThreadedImageFilter will also use TBB if VTK is built with it.
So if you build with TBB and use image filters, you have a choice:
SetGlobalDefaultEnableSMP(1) to use TBB for all threaded image filters
SetGlobalDefaultEnableSMP(0) to use vtkMultiThreader (which is what you’re using now)
It’s also possible to use SetEnableSMP(bool) to choose TBB vs vtkMultiThreader for individual image filters (or use SetNumberOfThreads(1) to turn off threading completely).