[Insight-users] Data Parallelization

Ron Inbar ron@mediguide.co.il
Mon, 17 Mar 2003 10:56:14 +0200


Hi Luis,

Thanks a lot for your answer!

I have one more question, though (in fact I have more than one, but I'll ask
them one at a time): When multithreading is enabled for a particular filter
F (using F->SetNumberOfThreads( N ) ) which of the following better
describes what takes place:

(a) The Input is updated; the RequestedRegion is partitioned into N pieces;
N threads are spawned; each thread generates its piece of the output; the
filter waits for all threads to finish; the next filter downstream (if there
is one) begins to execute.

(b) The RequestedRegion is partitioned into N pieces; N threads are spawned;
each thread updates its input and executes; the filter waits for all threads
to finish, and then the next filter downstream executes.

To make the point clearer: method (a) splits execution for one filter at a
time, but the pipeline as a whole still executes serially (i.e., each filter
has to finish executing before the one downstream can begin), while method
(b) splits execution all the way upstream from F (i.e., the section of the
pipeline upstream from F will be executed in each of the N threads
independently).

Method (b) is probably more efficient (because there's less thread
synchronization), but more difficult to implement.

Thanks in advance,

Ron

> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
> Sent: Sunday, March 16, 2003 9:06 PM
> To: Ron Inbar
> Cc: insight-users@public.kitware.com
> Subject: Re: [Insight-users] Data Parallelization
> 
> 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.*
> 


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.