Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlobalDefaultNumberOfThreads should not be greater than GlobalMaximumNumberOfThreads #4773

Open
N-Dekker opened this issue Jul 10, 2024 · 0 comments
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Milestone

Comments

@N-Dekker
Copy link
Contributor

N-Dekker commented Jul 10, 2024

Description

Users typically call MultiThreaderBase::SetGlobalMaximumNumberOfThreads when they want to reduce (limit) the number of threads used by a process. However, when a user sets the GlobalMaximumNumberOfThreads while leaving the GlobalDefaultNumberOfThreads unspecified, this "default number" may end up becoming larger than the "maximum number"!

Steps to Reproduce

#include <itkMultiThreaderBase.h>
#include <iostream>

int main()
{
  itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads(3);

  std::cout
    << "Maximum: " << itk::MultiThreaderBase::GetGlobalMaximumNumberOfThreads() << '\n'
    << "Default: " << itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads() << '\n';
}

Expected behavior

With this example, both Maximum and Default should end up being 3 (at least, if the machine supports having 3 simultaneous threads).

Actual behavior

Output on my (LKEB/LUMC) multi-core machine:

Maximum: 3
Default: 12

Versions

ITK 5.4.0

Environment

Windows

Additional Information

GlobalDefaultNumberOfThreads is being used when constructing the ThreadPool:

ThreadIdType threadCount = MultiThreaderBase::GetGlobalDefaultNumberOfThreads();

So the number of threads held by the thread pool appears to also occasionally exceed GlobalMaximumNumberOfThreads!


@N-Dekker N-Dekker added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Jul 10, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this issue Jul 11, 2024
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"
N-Dekker added a commit to SuperElastix/elastix that referenced this issue Jul 11, 2024
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"
@thewtex thewtex added this to the ITK 5.4.1 milestone Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

No branches or pull requests

2 participants