[Insight-developers] suggestion: use environment variable to limit number of parallel threads

Luis Ibanez luis.ibanez at kitware.com
Thu Sep 20 13:03:44 EDT 2007


Hi Torsten,

Here is one option that come to mind:

1) In itkMultiThreader.cxx lines 80-145 method
    GetGlobalDefaultNumberOfThreads()

    insert one option where the number of Threads
    is taken from the environment variable, like:

    std::string numberOfThreadsString =
     getenv("ITK_DEFAULT_NUMBER_OF_THREADS");
    m_GlobalDefaultNumberOfThreads =
      atoi(  numberOfThreadsString.c_str() )

2) Surrond that option with a CMake enabled define
    such as ITK_USE_NUMBER_OF_THREADS_FROM_ENVIRONMENT,
    this define will be set in the itkConfigure.h.in
    and will be controlled by an advanced option in
    CMake.


Note that the same can be done for the "Maximum"
number of Threads.


In this way, you can get ITK to choose the number of
threads from the environment variable, but *only* if
ITK was configured with that CMake variable enabled.



   Regards,


      Luis



-------------------------
Torsten Rohlfing wrote:
> Sean:
> 
> Two problems with your suggestion:
> 
> a) I have to put a command line switch etc. into EVERY application I 
> build based on ITK to replicate this functionality. That includes all 
> applications made by other people, so I have to potentially keep 
> patching other people's code.
> 
> b) if I don't have the source code of the application (possible 
> according to ITK licensing), then I'm screwed.
> 
> Does that answer your question?
> 
> Cheers!
>  TR
> 
> Sean McBride wrote:
> 
>> On 9/20/07 9:11 AM, Torsten Rohlfing said:
>>
>>  
>>
>>> Well, no, that's not quite what I meant. See, the function you're 
>>> referring to allows you to set the number of threads from INSIDE an 
>>> ITK application, whereas I was suggesting a way of setting it from 
>>> OUTSIDE the application.
>>>     
>>
>>
>> hmmm, perhaps I need more caffeine... :)  but ITK is just a big library
>> that is linked into an executable.  Can't your application just call
>> SetGlobalDefaultNumberOfThreads() early on (before you call other ITK
>> APIs), based on whatever env var you want?
>>
>>   
> 
> 
> 


More information about the Insight-developers mailing list