[Insight-users] Data Parallelization
Luis Ibanez
luis.ibanez@kitware.com
Sun, 16 Mar 2003 14:05:46 -0500
Hi Ron,
The support for multithreading is built-in
in the data pipeline structure. The only
thing you have to do for trigerring multitreading
is to invoke the method:
myFilter->SetNumberOfThreads( N );
before the filter is executed
(e.g. any call to Update() ).
The data-pipepline mechanism will take care
of all the details for you. Including the
selection of the platform-specific mechanism
for managing threads (e.g. pthreads in Linux
versus sproc() in SGI.
Note however that not all the filters are well
suited for multithreading. This is sometimes
due to implemntation limitations, sometimes to
algorithmic limitations.
As you may be endowed with an skeptical mind,
here is a simple experiment you can do for
verifying the use of multithreading in the code.
This experiment requires you to modify a couple
of files in Insight.
1) Edit the file
Insight/Code/BasicFilters/
itkUnaryFunctorImageFilter.txx
in line 45, you will find the method:
ThreadedGenerateData(). Please add in line 48
the following statement:
std::cout << "Thread Id = " << threadId << std::endl;
This will printout the thread number in which
this message is being executed.
2) Go to the directory: Insight/Examples/Filtering
and edit the file: SigmoidImageFilter.cxx
in line 197 add the following statements
if( argc >7 )
{
sigmoidFilter->SetNumberOfThreads( atoi(argv[7] ) );
}
This will take the number of threads as a parameter
from the command line.
3) Recompile the example
4) run it as:
SigmoidImageFilter input.png output.png 0 255 10 128 5
where the last parameter is the number of threads.
play executing the filter for several values of this
last parameter.
Note that the print-out may end up appearing intertwined
on the screen. Yet another verification that they are
running in different threads.
5) BTW, this illustrates that any filter deriving from the
Functor filters inherits the capability for running in
multiple threads.
-----------------
All the magic of multi-platform suppor for threads
is localized in the itkMultithreader class, that
you can find in Insight/Code/Common.
The Doxygen documentation provides a list of grouping
criteria in
http://www.itk.org/Insight/Doxygen/html/modules.html
Among the classifications, you will find, the list of
filters supporting multithreading, in
http://www.itk.org/Insight/Doxygen/html/group__MultithreadingGroup.html
An easy way to tell whether a filter supports
multi-threading or not, is to look if it implements
the method GenerateData() of the method ThreadedGenerateData().
Those filters implementing the second method, are of course,
supporting multi-threading.
Please let us know if you have further questions.
Thanks
Luis
----------------------
Ron Inbar wrote:
> Hi,
>
>
>
> I would like to see how ITK does multi-threading.
>
> Specifically, I'd like to run one of the filters, say the
> CurvatureFlowImageFilter, in two threads in parallel, on different parts
> of the input (i.e. data parallelization).
>
> Could you please point me to some examples that do a similar thing?
>
>
>
> Thanks in advance,
>
>
>
> Ron
>
>
>
> **
> **
> *This e-mail message has been sent by MediGuide*
> *and is for the use of the intended recipients only.
> The message may contain privileged or confidential information .
> If you are not the intended recipient you are hereby notified that any use,
> distribution or copying of this communication is strictly prohibited,
> and you are requested to delete the e-mail and any attachments*
> *and notify the sender immediately.*