elastix
elastix copied to clipboard
Thread pools
Investigate the use of the ITK thread pooling mechanisms
Part of this investigation should be the following questions, in my opinion:
- Which components would particularly benefit from using thread pools?
- Is the performance gain from using thread pools significant and reproducible?
Currently looking at how AdvancedMeanSquaresImageToImageMetric could make use of ITK's Thread Pool mechanism, as suggested by @mstaring . AdvancedMeanSquaresImageToImageMetric overrides ThreadedGetValue and ThreadedGetValueAndDerivative from AdvancedImageToImageMetric, introduced with commit 2fc2c495837f64416263fa7c5d1e2bc4e3e061fa (2013). ITK's ImageToImageMetric has similarly named member functions, GetValueAndDerivativeThread and GetValueThread, introduced with commit https://github.com/InsightSoftwareConsortium/ITK/commit/6abbc7969a90786c4c73f5d191f634db536c2d1d (2010). ITK's ThreadPool mechanism started with the introduction of PoolMultiThreader, commit https://github.com/InsightSoftwareConsortium/ITK/commit/ee699138fab5f590e3203e30fb656834f5b0a025 (2018)
To be continued.
@mstaring Your commit 065f17c3bbe595c08cbfb17f38f314fa6a97ef9d "PERF: switch from local to global threader" (2014) seems related. Doesn't it already enable thread pools?
Elastix metric classes use ITK's ImageToImageMetric::m_Threader, which is a pointer to an ITK MultiThreaderBase. By default, MultiThreaderBase::New() creates a PoolMultiThreader.
On the other hand, it appears that elastix ComputeDisplacementDistribution and AdvancedImageMomentsCalculator have their own m_Threader data member, which is a pointer to PlatformMultiThreader, instead of PoolMultiThreader. I guess these two m_Threader data members should be of type MultiThreaderBase instead, in order to enable thread pools.
Will the effect of using thread pools noticeable for ComputeDisplacementDistribution and AdvancedImageMomentsCalculator?
For the record:
ITK v5 Migration Guide - Multithreading refactored is at https://github.com/InsightSoftwareConsortium/ITK/blob/aaa43159aa5510fd514c71823b6b9c86b1f01212/Documentation/ITK5MigrationGuide.md#multithreading-refactored