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

Torsten Rohlfing torsten at synapse.sri.com
Thu Sep 20 12:11:47 EDT 2007


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.

In more detail, I am suggesting that 
MultiThreader::GetGlobalDefaultNumberOfThreads be modified to check for 
the existence of some sort of outside condition (e.g., environment 
variable), and if it exists to use its value as the default number of 
threads instead of the number of physical CPUs in the system. For 
example, at the beginning of the function, add

  if ( getenv( "ITK_MAX_NUM_THREADS" ) )
    {
    return (m_GlobalDefaultNumberOfThreads = atoi( getenv( 
"ITK_MAX_NUM_THREADS" ) ));
    }

Of course there should be error checking etc., but that's pretty much 
the entire idea.

The only disadvantage of this addition that I can see (given that 
nothing changes if that variable is NOT defined) is potential 
portability issues. But then again, I am not aware of a single platform 
that does NOT provide some sort of environment variables, and at least 
on all Unix-like systems, we should simply be able to use getenv(). 
Pretty sure it works on Windows too, although maybe with slightly 
different function interface?

Cheers!
  TR


Sean McBride wrote:
> On 9/19/07 5:41 PM, Torsten Rohlfing said:
>
>   
>> Can you think of another way of achieving the effect I am suggesting, 
>> one that doesn't use environment variables?
>>     
>
> There is already an API: itkMultiThre
> ader::SetGlobalDefaultNumberOfThreads()... unless I misunderstand
> something here...
>
>   


-- 
Torsten Rohlfing, PhD          SRI International, Neuroscience Program
 Research Scientist             333 Ravenswood Ave, Menlo Park, CA 94025
  Phone: ++1 (650) 859-3379      Fax: ++1 (650) 859-2743
   torsten at synapse.sri.com        http://www.stanford.edu/~rohlfing/

     "Though this be madness, yet there is a method in't"



More information about the Insight-developers mailing list