<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262541</link>
    <title>MATLAB Central Newsreader - Parfor counts backward?</title>
    <description>Feed for thread: Parfor counts backward?</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>Wed, 07 Oct 2009 15:36:02 -0400</pubDate>
      <title>Parfor counts backward?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262541#685369</link>
      <author>Yoav </author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
When using a parfor loop without the matlabpool open it is supposed to default to a regular for loop (see documentation). This works fine but it seems to be counting from the END of the numbering array to the beginning. For example, run the following code without opening a matlab pool:&lt;br&gt;
&lt;br&gt;
parfor x = 1:10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(x);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
And instead of seeing 1, 2, 3...10 (as you would with a for loop)  you see 10, 9, 8... 1.&lt;br&gt;
&lt;br&gt;
Any idea why it happens this way? It shouldn't matter much for results collection but still a curious behaviour.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Yoav</description>
    </item>
    <item>
      <pubDate>Wed, 07 Oct 2009 15:54:06 -0400</pubDate>
      <title>Re: Parfor counts backward?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262541#685376</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Yoav&quot; &amp;lt;yoav.farkash@utoronto.ca&amp;gt; wrote in message &lt;br&gt;
news:haich2$38a$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; When using a parfor loop without the matlabpool open it is supposed to &lt;br&gt;
&amp;gt; default to a regular for loop (see documentation). This works fine but it &lt;br&gt;
&amp;gt; seems to be counting from the END of the numbering array to the beginning. &lt;br&gt;
&amp;gt; For example, run the following code without opening a matlab pool:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; parfor x = 1:10&lt;br&gt;
&amp;gt;    disp(x);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; And instead of seeing 1, 2, 3...10 (as you would with a for loop)  you see &lt;br&gt;
&amp;gt; 10, 9, 8... 1.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Any idea why it happens this way? It shouldn't matter much for results &lt;br&gt;
&amp;gt; collection but still a curious behaviour.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brb2x57&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brb2x57&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
You should not depend on the order in which the iterations in your PARFOR &lt;br&gt;
loop are executed; each iteration of the loop body must be independent of &lt;br&gt;
the others.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brdew7t-1&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brdew7t-1&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
I believe this is designed to encourage that, but you shouldn't assume that &lt;br&gt;
it will always be the case that the loop runs in this particular order.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
    <item>
      <pubDate>Fri, 16 Oct 2009 11:41:16 -0400</pubDate>
      <title>Re: Parfor counts backward?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/262541#687514</link>
      <author>Mike Karr</author>
      <description>Steven Lord wrote:&lt;br&gt;
&amp;gt; &quot;Yoav&quot; &amp;lt;yoav.farkash@utoronto.ca&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:haich2$38a$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;&amp;gt; Hi,&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; When using a parfor loop without the matlabpool open it is supposed to &lt;br&gt;
&amp;gt;&amp;gt; default to a regular for loop (see documentation). This works fine but it &lt;br&gt;
&amp;gt;&amp;gt; seems to be counting from the END of the numbering array to the beginning. &lt;br&gt;
&amp;gt;&amp;gt; For example, run the following code without opening a matlab pool:&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; parfor x = 1:10&lt;br&gt;
&amp;gt;&amp;gt;    disp(x);&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; And instead of seeing 1, 2, 3...10 (as you would with a for loop)  you see &lt;br&gt;
&amp;gt;&amp;gt; 10, 9, 8... 1.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Any idea why it happens this way? It shouldn't matter much for results &lt;br&gt;
&amp;gt;&amp;gt; collection but still a curious behaviour.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brb2x57&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brb2x57&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You should not depend on the order in which the iterations in your PARFOR &lt;br&gt;
&amp;gt; loop are executed; each iteration of the loop body must be independent of &lt;br&gt;
&amp;gt; the others.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brdew7t-1&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html#brdew7t-1&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I believe this is designed to encourage that, but you shouldn't assume that &lt;br&gt;
&amp;gt; it will always be the case that the loop runs in this particular order.&lt;br&gt;
&lt;br&gt;
Steve is absolutely right that you should not depend on the order.  But &lt;br&gt;
running the loop backward was not designed to encourage that.  A more &lt;br&gt;
complete story is that when parfor goes truly parallel, it in fact sends &lt;br&gt;
&quot;chunks&quot; to workers in increasing e.g., for 1:10 the chunks might be &lt;br&gt;
1:3, 4:6, 7:8, 9:10.  But then in each worker, the loops are run &lt;br&gt;
backward, achieving the effect of a pre-allocation (which I won't &lt;br&gt;
discuss here; there are many references to it in this newsgroup).&lt;br&gt;
&lt;br&gt;
In other words, the parfor implementation does not merely encourage &lt;br&gt;
order-independence, it _relies_ on it.  When parfor is run on a single&lt;br&gt;
processor, the fact that the serial loop there goes backward is fallout &lt;br&gt;
from the general case.&lt;br&gt;
&lt;br&gt;
fyi,&lt;br&gt;
mike</description>
    </item>
  </channel>
</rss>

