Skip to content

ENH: Add SetDefaultNumberOfThreads#149

Merged
thewtex merged 1 commit intoInsightSoftwareConsortium:masterfrom
thewtex:AddSetDefaultNumberOfThreads
Dec 2, 2019
Merged

ENH: Add SetDefaultNumberOfThreads#149
thewtex merged 1 commit intoInsightSoftwareConsortium:masterfrom
thewtex:AddSetDefaultNumberOfThreads

Conversation

@thewtex
Copy link
Member

@thewtex thewtex commented Dec 2, 2019

@thewtex
Copy link
Member Author

thewtex commented Dec 2, 2019

@mrocklin please take a look

@mrocklin
Copy link

mrocklin commented Dec 2, 2019

From a Python user's perspective I would prefer an API like ...

import itk
itk.set_nthreads(4)

There are a few other libraries (blosc comes to mind) that do something similar.

However, with proper documentation what's here also works. I imagine that the sorts of people who are going to want to change the default number of threads are also going to have a decently high tolerance for writing lots of code.

Thank you all for working on this.

Copy link
Member

@jhlegarreta jhlegarreta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although @mrocklin 's comment seems fair, I guess it is not trivial to implement that under ITK's framework. If you think it is feasible, an issue could be opened in the ITK repository and cross-reference this example.

In the meantime, I think merging the example would help users have a better grasp of the current multi-threading mechanism use.

@mrocklin
Copy link

mrocklin commented Dec 2, 2019

Yeah, that was my guess as to what was happening. Thought I'd mention it anyway. Thanks all!

@dzenanz
Copy link
Member

dzenanz commented Dec 2, 2019

It should not be hard to implement. A stand-alone function itk::set_nthreads:

void 
set_nthreads(ThreadIdType numberOfThreads)
{
  itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads(numberOfThreads);
}

should be about enough.

@dzenanz
Copy link
Member

dzenanz commented Dec 2, 2019

While such a function wouldn't make much sense in C++, we could make it available only in Python. Thoughts?

@thewtex
Copy link
Member Author

thewtex commented Dec 2, 2019

Thanks for the reviews!

The CI failures are unrelated, so merging.

If there is demand for it, we could add itk.set_nthreads by defining it in itkExtras.py.

It would look like:

def set_nthreads(number_of_threads):
    threader = itk.MultiThreaderBase.New()
    threader.SetGlobalDefaultNumberOfThreads(number_of_threads)

@thewtex thewtex merged commit 41927a5 into InsightSoftwareConsortium:master Dec 2, 2019
@thewtex thewtex deleted the AddSetDefaultNumberOfThreads branch December 2, 2019 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants