<div dir="ltr"><div><div><div>Hi Laurent,<br><br></div>If you are using a recent version of VTK you may want to give vtkSMPTools a try. It is a new, simplified framework for doing parallelism in VTK and it can target TBB or OpenMP as backends. It has support for a "parallel_for" and maybe a simpler way to implement your code. Please refer to this blog: <a href="http://www.kitware.com/blog/home/post/915">http://www.kitware.com/blog/home/post/915</a>. Let me know if you have any questions about this framework.<br><br></div>Thanks<br></div>Sujin<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 11, 2015 at 12:08 PM, Dan Lipsa <span dir="ltr"><<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Laurent,<div>I think a good function to look at is</div><div><br></div><div><a href="http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Common/Core/Testing/Cxx/TestConditionVariable.cxx" target="_blank">http://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Common/Core/Testing/Cxx/TestConditionVariable.cxx</a><br></div><div><br></div><div>When you do SingleMethodExecute, the method you set is run an all processors.</div><div>Then, by looking at threadId you can execute different parts of the method on different processors.</div><div><br></div><div>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.</div><div><br></div><div>This would be the same as spliting a 2D array into chunks and executing a chunk on each processor.</div><div>However, you'll have to do this explicitly, VTK does not do it automatically.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Dan</div><div><br></div><div><br></div><div><br></div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 9, 2015 at 6:22 PM, Chauvin, Laurent,Ph.D. <span dir="ltr"><<a href="mailto:lchauvin@bwh.harvard.edu" target="_blank">lchauvin@bwh.harvard.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif">
<div>Thank you for your answer.</div>
<div><br>
</div>
<div>I actually looked at it, but I’m still not sure what happen in this example.</div>
<div>Is each function run in one separated thread, or each function run in multiple threads ?</div>
<div><br>
</div>
<div>Here is what I have:</div>
<div><br>
</div>
<div>myMethod(void* arg)</div>
<div>{</div>
<div><span style="white-space:pre-wrap"></span>For loop</div>
<div> For loop</div>
<div> Computation()</div>
<div>}</div>
<div><br>
</div>
<div>And then I use vtkMultiThreader to execute this method like this:</div>
<div><br>
</div>
<div>Threader->SetSingleMethod(myMethod,NULL);</div>
<div>Threader->SingleMethodExecute()</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>But I think I got it wrong. I think I have to do something like that:</div>
<div><br>
</div>
<div>For Loop</div>
<div> For Loop</div>
<div> Threader->SetSingleMethod(myMethod,data[i][j])</div>
<div> Threader->SingleMethodExecute()</div>
<div><br>
</div>
<div>Is it correct ?</div>
<div><br>
</div>
<div>Thank you.</div>
<div>-Laurent</div>
<div><br>
</div>
<span>
<div style="font-family:Calibri;font-size:11pt;text-align:left;color:black;BORDER-BOTTOM:medium none;BORDER-LEFT:medium none;PADDING-BOTTOM:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in;BORDER-TOP:#b5c4df 1pt solid;BORDER-RIGHT:medium none;PADDING-TOP:3pt">
<span style="font-weight:bold">From: </span>Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>><br>
<span style="font-weight:bold">Date: </span>Friday, October 9, 2015 at 11:18 PM<br>
<span style="font-weight:bold">To: </span>"Chauvin, Laurent,Ph.D." <<a href="mailto:lchauvin@bwh.harvard.edu" target="_blank">lchauvin@bwh.harvard.edu</a>><br>
<span style="font-weight:bold">Cc: </span>Franz Neubert via vtkusers <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [vtkusers] vtkMultiThreader question<br>
</div><div><div>
<div><br>
</div>
<div>
<div>
<div dir="ltr">Laurent,
<div>Did you look at the tests that come with this class. Do they work?</div>
<div><br>
</div>
<div><a href="http://www.vtk.org/doc/nightly/html/c2_vtk_t_12.html#c2_vtk_t_vtkMultiThreader" target="_blank">http://www.vtk.org/doc/nightly/html/c2_vtk_t_12.html#c2_vtk_t_vtkMultiThreader</a><br>
</div>
<div><br>
</div>
<div>Dan</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Oct 9, 2015 at 5:00 PM, Chauvin, Laurent,Ph.D. <span dir="ltr">
<<a href="mailto:lchauvin@bwh.harvard.edu" target="_blank">lchauvin@bwh.harvard.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif">
<div>Hello,</div>
<div><br>
</div>
<div>I’m trying to use a vtkMultiThreader to compute several thing in parallel.</div>
<div>However I’m not sure how it works.</div>
<div><br>
</div>
<div>Here is what I did.</div>
<div>I created a single method that calculate some metric pairwise. So I have 2 for loops in this method.</div>
<div>What I want to do, is to have one thread per iteration (kind of), so I can calculate all metrics simultaneously.</div>
<div><br>
</div>
<div>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 ?</div>
<div><br>
</div>
<div>Should I put the loops out of the single method then, and spawn a thread for each iteration, with different data as input ?</div>
<div><br>
</div>
<div>Thank you very much.</div>
<div>-Laurent</div>
<p></p>
<p>The information in this e-mail is intended only for the person to whom it is<br>
addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
contains patient information, please contact the Partners Compliance HelpLine at<br>
<a href="http://www.partners.org/complianceline" target="_blank">http://www.partners.org/complianceline</a> . If the e-mail was sent to you in error<br>
but does not contain patient information, please contact the sender and properly<br>
dispose of the e-mail.</p>
</div>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">
http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">
http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div></div></span>
</div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>