elastix icon indicating copy to clipboard operation
elastix copied to clipboard

Thread pools

Open mstaring opened this issue 4 years ago • 5 comments

Investigate the use of the ITK thread pooling mechanisms

mstaring avatar May 11 '21 14:05 mstaring

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?

N-Dekker avatar May 14 '21 12:05 N-Dekker

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.

N-Dekker avatar Aug 15 '23 14:08 N-Dekker

@mstaring Your commit 065f17c3bbe595c08cbfb17f38f314fa6a97ef9d "PERF: switch from local to global threader" (2014) seems related. Doesn't it already enable thread pools?

N-Dekker avatar Aug 28 '23 08:08 N-Dekker

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?

N-Dekker avatar Aug 28 '23 09:08 N-Dekker

For the record:

ITK v5 Migration Guide - Multithreading refactored is at https://github.com/InsightSoftwareConsortium/ITK/blob/aaa43159aa5510fd514c71823b6b9c86b1f01212/Documentation/ITK5MigrationGuide.md#multithreading-refactored

N-Dekker avatar Sep 15 '23 12:09 N-Dekker