<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263916</link>
    <title>MATLAB Central Newsreader - Problem with parfor</title>
    <description>Feed for thread: Problem with parfor</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 23 Oct 2009 07:22:19 -0400</pubDate>
      <title>Problem with parfor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263916#689188</link>
      <author>Pravin </author>
      <description>Hi everyone,&lt;br&gt;
&lt;br&gt;
Long-time reader, first time poster.&lt;br&gt;
&lt;br&gt;
I am currently trying to improve the performance of a program I am working on by carrying out operations in parallel. The basic code that I am using for this operation is something like:&lt;br&gt;
&lt;br&gt;
for i = 1:Mdivs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parfor j = 1:Ndivs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pic = fun1(img1((i-1)*step+1:min([factor+(i-1)*step,M]),(j-1)*step+1:min(factor+(j-1)*step,N),:));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;motion(i,j,:) = fun2(pic);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
fun1 takes an RGB image, processes it and returns a grayscale image. fun2 processes the grayscale image and returns a two-element vector (1x1x2 in size actually), which I store at the appropriate location in motion. step,factor,M and N are of class double. They are used to extract a subimage from the image img1.&lt;br&gt;
&lt;br&gt;
The problem that I have is that the code behaves very erratically. Sometimes, the execution is perfect, but at other times I get the following error message:-&lt;br&gt;
&lt;br&gt;
Error using ==&amp;gt; parallel_function at 594&lt;br&gt;
Subscripted assignment dimension mismatch.&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; control2 at 22&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parfor j = 1:Ndivs&lt;br&gt;
&amp;nbsp;&lt;br&gt;
I have spent a long time trying to figure out any pattern in the instances which cause the error, but have come up with squat. Any suggestions at all would be very helpful.&lt;br&gt;
&lt;br&gt;
Thanks and cheers!</description>
    </item>
    <item>
      <pubDate>Fri, 23 Oct 2009 09:28:16 -0400</pubDate>
      <title>Re: Problem with parfor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263916#689219</link>
      <author>Edric M Ellis</author>
      <description>&quot;Pravin &quot; &amp;lt;pravinkakar@gmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; I am currently trying to improve the performance of a program I am working on&lt;br&gt;
&amp;gt; by carrying out operations in parallel. The basic code that I am using for&lt;br&gt;
&amp;gt; this operation is something like:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; for i = 1:Mdivs&lt;br&gt;
&amp;gt;     parfor j = 1:Ndivs&lt;br&gt;
&amp;gt;                 pic = fun1(img1((i-1)*step+1:min([factor+(i-1)*step,M]),(j-1)*step+1:min(factor+(j-1)*step,N),:));&lt;br&gt;
&amp;gt;         motion(i,j,:) = fun2(pic);&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
Unfortunately, the subscripted assignment error appears to be due to a bug in&lt;br&gt;
PARFOR which incorrectly deals with some assignments - in this case, because&lt;br&gt;
you're slicing the second dimension out of 3. One workaround for this problem is&lt;br&gt;
to move the PARFOR loop to be the outer loop (generally a good idea in any&lt;br&gt;
case), but to do this you'll also need to calculate a whole chunk of your&lt;br&gt;
&quot;motion&quot; array, something like this:&lt;br&gt;
&lt;br&gt;
parfor i = 1:Mdivs&lt;br&gt;
&amp;nbsp;&amp;nbsp;tmp = zeros( Ndivs, 2 );&lt;br&gt;
&amp;nbsp;&amp;nbsp;for j = 1:Ndivs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tmp( j, : ) = fun2( fun1( ... ) );&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;motion( i, :, : ) = tmp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Sat, 24 Oct 2009 03:48:04 -0400</pubDate>
      <title>Re: Problem with parfor</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/263916#689427</link>
      <author>Pravin </author>
      <description>Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytw1vkuihn3.fsf@uk-eellis-deb5-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Unfortunately, the subscripted assignment error appears to be due to a bug in&lt;br&gt;
&amp;gt; PARFOR which incorrectly deals with some assignments - in this case, because&lt;br&gt;
&amp;gt; you're slicing the second dimension out of 3. One workaround for this problem is&lt;br&gt;
&amp;gt; to move the PARFOR loop to be the outer loop (generally a good idea in any&lt;br&gt;
&amp;gt; case), but to do this you'll also need to calculate a whole chunk of your&lt;br&gt;
&amp;gt; &quot;motion&quot; array, something like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; parfor i = 1:Mdivs&lt;br&gt;
&amp;gt;   tmp = zeros( Ndivs, 2 );&lt;br&gt;
&amp;gt;   for j = 1:Ndivs&lt;br&gt;
&amp;gt;     tmp( j, : ) = fun2( fun1( ... ) );&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt;   motion( i, :, : ) = tmp;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Edric.&lt;br&gt;
&lt;br&gt;
Well, I'll be... This worked like a charm. I did try to move the parfor to the outer loop earlier but couldn't quite figure out how to make the assignment.&lt;br&gt;
&lt;br&gt;
Thanks so much!&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Pravin</description>
    </item>
  </channel>
</rss>

