[vtkusers] vtkMultiThreader question

Dan Lipsa dan.lipsa at kitware.com
Sun Oct 11 12:08:53 EDT 2015


Laurent,
I think a good function to look at is

http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Common/Core/Testing/Cxx/TestConditionVariable.cxx

When you do SingleMethodExecute, the method you set is run an all
processors.
Then, by looking at threadId you can execute different parts of the method
on different processors.

So for your 2 for loops you can set different range indexes to run on
different processors - if there are no dependencies between different index
computations.

This would be the same as spliting a 2D array into chunks and executing a
chunk on each processor.
However, you'll have to do this explicitly, VTK does not do it
automatically.

Dan





On Fri, Oct 9, 2015 at 6:22 PM, Chauvin, Laurent,Ph.D. <
lchauvin at bwh.harvard.edu> wrote:

> Thank you for your answer.
>
> I actually looked at it, but I’m still not sure what happen in this
> example.
> Is each function run in one separated thread, or each function run in
> multiple threads ?
>
> Here is what I have:
>
> myMethod(void* arg)
> {
> For loop
>               For loop
>                     Computation()
> }
>
> And then I use vtkMultiThreader to execute this method like this:
>
> Threader->SetSingleMethod(myMethod,NULL);
> Threader->SingleMethodExecute()
>
> What I was expecting was that thread detect the function could be split in
> multiple thread (because of the loops) and run each iteration of
> Computation() in a different thread.
>
> But I think I got it wrong. I think I have to do something like that:
>
> For Loop
>      For Loop
>          Threader->SetSingleMethod(myMethod,data[i][j])
>          Threader->SingleMethodExecute()
>
> Is it correct ?
>
> Thank you.
> -Laurent
>
> From: Dan Lipsa <dan.lipsa at kitware.com>
> Date: Friday, October 9, 2015 at 11:18 PM
> To: "Chauvin, Laurent,Ph.D." <lchauvin at bwh.harvard.edu>
> Cc: Franz Neubert via vtkusers <vtkusers at vtk.org>
> Subject: Re: [vtkusers] vtkMultiThreader question
>
> Laurent,
> Did you look at the tests that come with this class. Do they work?
>
>
> http://www.vtk.org/doc/nightly/html/c2_vtk_t_12.html#c2_vtk_t_vtkMultiThreader
>
> Dan
>
>
> On Fri, Oct 9, 2015 at 5:00 PM, Chauvin, Laurent,Ph.D. <
> lchauvin at bwh.harvard.edu> wrote:
>
>> Hello,
>>
>> I’m trying to use a vtkMultiThreader to compute several thing in parallel.
>> However I’m not sure how it works.
>>
>> Here is what I did.
>> I created a single method that calculate some metric pairwise. So I have
>> 2 for loops in this method.
>> What I want to do, is to have one thread per iteration (kind of), so I
>> can calculate all metrics simultaneously.
>>
>> So I created a vtkMultiThreader and set the single method, which contains
>> the loops, and executed it. However when I do that, I can only see one core
>> working. I thought SingleMethod was using multiple thread to run this
>> method. Is it true ? Why then it is not using all my other cores ?
>>
>> Should I put the loops out of the single method then, and spawn a thread
>> for each iteration, with different data as input ?
>>
>> Thank you very much.
>> -Laurent
>>
>> The information in this e-mail is intended only for the person to whom it
>> is
>> addressed. If you believe this e-mail was sent to you in error and the
>> e-mail
>> contains patient information, please contact the Partners Compliance
>> HelpLine at
>> http://www.partners.org/complianceline . If the e-mail was sent to you
>> in error
>> but does not contain patient information, please contact the sender and
>> properly
>> dispose of the e-mail.
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151011/c066ca8a/attachment.html>


More information about the vtkusers mailing list