Skip to content

Commit

Permalink
BUG: Call SetGlobalDefaultNumberOfThreads when processing "-threads"
Browse files Browse the repository at this point in the history
It appears that `SetGlobalMaximumNumberOfThreads` may not affect the size of ITK's ThreadPool. The ThreadPool only uses "GlobalDefaultNumberOfThreads".

- Related to ITK issue InsightSoftwareConsortium/ITK#4773 "GlobalDefaultNumberOfThreads should not be greater than GlobalMaximumNumberOfThreads"
  • Loading branch information
N-Dekker committed Jul 11, 2024
1 parent d44e65e commit e3cafc5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Core/Kernel/elxMainBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ MainBase::SetMaximumNumberOfThreads() const
{
const int maximumNumberOfThreads = atoi(maximumNumberOfThreadsString.c_str());
itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads(maximumNumberOfThreads);

// The following statement (getting and setting GlobalDefaultNumberOfThreads) may look redundant, but it's not
// (using ITK 5.4.0)! The Set function ensures that GlobalDefaultNumberOfThreads <= GlobalMaximumNumberOfThreads.
// (GlobalDefaultNumberOfThreads is important, as ITK uses this number when constructing the ThreadPool.)
itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
}
} // end SetMaximumNumberOfThreads()

Expand Down

0 comments on commit e3cafc5

Please sign in to comment.