[Insight-users] ThreadedGenerateData()

Bradley Lowekamp blowekamp at mail.nih.gov
Fri Mar 22 09:13:26 EDT 2013


Hello Vikash,

Just to clarify some terminology, some of it may have been mixed up, and I am a little confused ( I'd like a laptop with 4 CPUs ):

CPU or socket
core or physical processor
logical processor or virtual core


So ITK by defaults tries to use all the logical processor or virtual cores. In my experience with large data sets the virtual cores generally don't hurt performance, and some of the RecursiveGaussian related filters have gotten up to a 50% speed up.

The operating system does the task of assigning processed and threads to logical processors. The scheduling even include things like CPU temperature to add in CPU features like turbo boost.

Most threading libraries have an thread affinity attribute which can be set I have never messed with it.

I generally multi-thread on the whole data-set in the standard ITK way, or have a bunch of objects I process with multiple processes or threads. For example if I have to process 1000 objects, I may write a program to perform the processing, and then use shell scripting to batch it out. I'd try to run the number of processes as physical processors, and tell ITK to only run 2 threads. I have found this to be a very efficient, with hyper-threading.

This is really  a problem specific and system specific issue with how to get the best performance with modern heterogeneous  systems. And it's important to keep in mind the NUMA with regards to the memory layout and the shared and unshared layers of CPU cache, when considering how to break up your problem.

Also I generally try to avoid doing two layers of ITK multi-threading. As the pipeline object's are not thread safe in a concurrent access with regards to the pipeline, it's seems more problematic than beneficial.

I hope my ramblings on this issue are helpful.

Brad

On Mar 21, 2013, at 4:47 PM, Vikash Gupta <vikash.gupta at inria.fr> wrote:

> Hi Matt and Willi, 
> Thanks for your insights in the Insight ToolKit :) . Yes I agree that the the number of threads will be divided on the number of cpus, my only worry was what happens in multithreading when I am assigning one particular job to one particular CPU, and from your answeres i feel that on the second level of multi-threading I should be little bit careful, as in if the CPU has 4 cores i shouldnt assign it 8 using SetNumberOfThreads() and the computing will be restricted to the CPU itself..
> 
> Thanks 
> Vikash 
> 
> From: "Willi Huber" <surfersparadise85-itk at yahoo.com>
> To: "insight-users at itk org" <insight-users at itk.org>, "vikash gupta" <vikash.gupta at inria.fr>
> Sent: Friday, March 22, 2013 2:07:18 AM
> Subject: AW: [Insight-users] ThreadedGenerateData()
> 
> Hello Vikash,
> this might not be correct since I have no deep insight into ITK an wether or not they have their own threading library but usually your OS, i.e. Windows or Linux, takes care of the distribution of threads.
> I don't know of any threading library that fixes threads to a certain Core or CPU since that is the idea behind threads: "Loadbalancing". 
> Therefore it (OS or some hardware) attaches threads to a Core which is currently out of work.
> Cheers,
> Willi
> 
> From: Vikash Gupta <vikash.gupta at inria.fr>; 
> To: itk <insight-users at itk.org>; 
> Subject: [Insight-users] ThreadedGenerateData() 
> Sent: Thu, Mar 21, 2013 8:02:22 PM 
> 
> Dear Itk-Users, 
> This might be a naive question but I am pondering over it for some time. When the ThreadedGenerateData() function is called in an itk filter, the threads refer to the number of CPUs on a computer or the number of cores on each CPU. 
> 
> For example, 	i have 8 cpus on my laptop with 4 cores on each, so if I call SetNumberOfThreads(4), these 4 cores will belong to the same CPU ? 
> 
> On the next lever, if I divide the work on each cpu and then also do multithreading in each CPU, will the number of threads correspond to the number of cores on each CPU ?
> Thanks a lot for any insight..
> 
> Vikash
> 
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130322/a58e07ad/attachment.htm>


More information about the Insight-users mailing list