<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using parfor Loops: Getting Up and Running</title>
	<atom:link href="http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Mon, 13 Feb 2012 13:24:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Sarah Zaranek</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32889</link>
		<dc:creator>Sarah Zaranek</dc:creator>
		<pubDate>Tue, 10 Jan 2012 23:13:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32889</guid>
		<description>@Tatiana

The maximum number of workers was raised from 4 to 8 (in R2009a) and from 8 to 12 (in R2011b).  So, make sure you have at least R2009a.

The maximum number of workers is usually set to the number of cores that the OS tells MATLAB you have.  You can change this by changing the local configuration by going to the parallel pulldown menu and managing the local configuration.  If you look at the properties, you can set the cluster size to 8.  However, if you only have 4 cores - this will not help you in terms of speed up.

Cheers,
Sarah</description>
		<content:encoded><![CDATA[<p>@Tatiana</p>
<p>The maximum number of workers was raised from 4 to 8 (in R2009a) and from 8 to 12 (in R2011b).  So, make sure you have at least R2009a.</p>
<p>The maximum number of workers is usually set to the number of cores that the OS tells MATLAB you have.  You can change this by changing the local configuration by going to the parallel pulldown menu and managing the local configuration.  If you look at the properties, you can set the cluster size to 8.  However, if you only have 4 cores &#8211; this will not help you in terms of speed up.</p>
<p>Cheers,<br />
Sarah</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tatiana</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32885</link>
		<dc:creator>Tatiana</dc:creator>
		<pubDate>Mon, 09 Jan 2012 10:28:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32885</guid>
		<description>Dear Loren

Could you please describe how to configure the &#039;local&#039; configuration so that it allows to use 8 workers (or any number more than 4) during the parallel computations?

Thank you very much in advance!</description>
		<content:encoded><![CDATA[<p>Dear Loren</p>
<p>Could you please describe how to configure the &#8216;local&#8217; configuration so that it allows to use 8 workers (or any number more than 4) during the parallel computations?</p>
<p>Thank you very much in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Free screen recorder</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32750</link>
		<dc:creator>Free screen recorder</dc:creator>
		<pubDate>Mon, 28 Nov 2011 08:00:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32750</guid>
		<description>&quot;d_3x = rand(100,4);
d_3y = rand(10,4);
d_3z = rand(10,4);
r3d_3 = rand(10,4);
k3d_3 = rand(10,4);

for x = 1:100
    d_x = d_3x(x,:);

    for y = 1:10
        d_y = d_3y(y,:);

        parfor z = 1:10

            k1 = [ d_x ,d_y , d_3z(z,:) ];
            %Where d_x, d_y &amp; d_3z(z,:) are 1x4 double
            k1 = sum(k1);
            %[r t] = corr_spear(k1 , mod3d_3);
            % don&#039;t have function, so set r equal to
            % random number
            r = rand;
            if abs(r) &lt; abs(r3d_3(z,1))
                r3d_3(z,1) = r;
                k3d_3(z,1) = k1;
            end

        end
    end
end&quot;

Sarah, this looks good! Thanks for your contribution!</description>
		<content:encoded><![CDATA[<p>&#8220;d_3x = rand(100,4);<br />
d_3y = rand(10,4);<br />
d_3z = rand(10,4);<br />
r3d_3 = rand(10,4);<br />
k3d_3 = rand(10,4);</p>
<p>for x = 1:100<br />
    d_x = d_3x(x,:);</p>
<p>    for y = 1:10<br />
        d_y = d_3y(y,:);</p>
<p>        parfor z = 1:10</p>
<p>            k1 = [ d_x ,d_y , d_3z(z,:) ];<br />
            %Where d_x, d_y &amp; d_3z(z,:) are 1&#215;4 double<br />
            k1 = sum(k1);<br />
            %[r t] = corr_spear(k1 , mod3d_3);<br />
            % don&#8217;t have function, so set r equal to<br />
            % random number<br />
            r = rand;<br />
            if abs(r) &lt; abs(r3d_3(z,1))<br />
                r3d_3(z,1) = r;<br />
                k3d_3(z,1) = k1;<br />
            end</p>
<p>        end<br />
    end<br />
end&#8221;</p>
<p>Sarah, this looks good! Thanks for your contribution!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32644</link>
		<dc:creator>Sarah</dc:creator>
		<pubDate>Mon, 14 Nov 2011 18:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32644</guid>
		<description>This relates to the restrictions spelled out in the above section of the blog post entitled - Classification.  

For parfor loops, when you index into a sliced variables, restrictions are placed on the first-level variable indices. This allows parfor to easily distribute the right part of the variable to the right workers. One of these first-level indices must be the loop counter variable or the counter variable plus or minus a constant. Every other first-level index must be a constant, a non-loop counter variable, a colon, or an end.

See a possible fix below.

&lt;pre&gt;

topNodes    = [2 3 4 5 6 7];
bottomNodes = [1 2 3 4 5 6];
polarity    = [1 1 -1 1 1 1];
nodes       = max([topNodes bottomNodes]);
T           = zeros(numel(polarity),nodes);
parfor i = 1:numel(polarity);
  myData = T(i,:);  
  if polarity(i) &lt; 0
      myData(i,bottomNodes(i)) = -1;
      myData(i,topNodes(i)) = 1;
  else
      myData(i,bottomNodes(i)) = 1;
      myData(i,topNodes(i)) = -1;
  end
  T(i,:) = myData;
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This relates to the restrictions spelled out in the above section of the blog post entitled &#8211; Classification.  </p>
<p>For parfor loops, when you index into a sliced variables, restrictions are placed on the first-level variable indices. This allows parfor to easily distribute the right part of the variable to the right workers. One of these first-level indices must be the loop counter variable or the counter variable plus or minus a constant. Every other first-level index must be a constant, a non-loop counter variable, a colon, or an end.</p>
<p>See a possible fix below.</p>
<pre>

topNodes    = [2 3 4 5 6 7];
bottomNodes = [1 2 3 4 5 6];
polarity    = [1 1 -1 1 1 1];
nodes       = max([topNodes bottomNodes]);
T           = zeros(numel(polarity),nodes);
parfor i = 1:numel(polarity);
  myData = T(i,:);
  if polarity(i) &lt; 0
      myData(i,bottomNodes(i)) = -1;
      myData(i,topNodes(i)) = 1;
  else
      myData(i,bottomNodes(i)) = 1;
      myData(i,topNodes(i)) = -1;
  end
  T(i,:) = myData;
end
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barend</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32639</link>
		<dc:creator>Barend</dc:creator>
		<pubDate>Mon, 14 Nov 2011 07:11:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32639</guid>
		<description>Dear Loren

I have not used the parallel computing features of matlab before, so I am quite new with the implementation of it. I might be asking a question that has already been adressed - apologies if this is the case.  I have the following code:

&lt;pre&gt;

topNodes    = [2 3 4 5 6 7];
bottomNodes = [1 2 3 4 5 6];
polarity    = [1 1 1 -1 -1 -1];
nodes       = max([topNodes bottomNodes]);
T           = zeros(nodes,numel(polarity));

for i = 1:numel(polarity);
    if polarity(i) &lt; 0
        T(i,bottomNodes(i)) = -1;
        T(i,topNodes(i)) = 1;
    else
        T(i,bottomNodes(i)) = 1;
        T(i,topNodes(i)) = -1;
    end
end

&lt;/pre&gt;

Okay, so now if I use a parfor loop this does not work.  There are many of my applications where I have an array with values that represent index values of a matrix and for some reason this is a challenge for me when I try to implement a par for loop.

Hope to hear from you soon.

Kind regards,

Barend</description>
		<content:encoded><![CDATA[<p>Dear Loren</p>
<p>I have not used the parallel computing features of matlab before, so I am quite new with the implementation of it. I might be asking a question that has already been adressed &#8211; apologies if this is the case.  I have the following code:</p>
<pre>

topNodes    = [2 3 4 5 6 7];
bottomNodes = [1 2 3 4 5 6];
polarity    = [1 1 1 -1 -1 -1];
nodes       = max([topNodes bottomNodes]);
T           = zeros(nodes,numel(polarity));

for i = 1:numel(polarity);
    if polarity(i) &lt; 0
        T(i,bottomNodes(i)) = -1;
        T(i,topNodes(i)) = 1;
    else
        T(i,bottomNodes(i)) = 1;
        T(i,topNodes(i)) = -1;
    end
end
</pre>
<p>Okay, so now if I use a parfor loop this does not work.  There are many of my applications where I have an array with values that represent index values of a matrix and for some reason this is a challenge for me when I try to implement a par for loop.</p>
<p>Hope to hear from you soon.</p>
<p>Kind regards,</p>
<p>Barend</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Felix</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32613</link>
		<dc:creator>Felix</dc:creator>
		<pubDate>Wed, 09 Nov 2011 20:58:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32613</guid>
		<description>Now it worked somehow. And how did I solve it? I did nothing! So I think I got this error, because I changed something in the sourcecode of the class and saved it, while the simulation tried to use it and got confused. Could that be?

Doesn&#039;t matter, it works, thanks!</description>
		<content:encoded><![CDATA[<p>Now it worked somehow. And how did I solve it? I did nothing! So I think I got this error, because I changed something in the sourcecode of the class and saved it, while the simulation tried to use it and got confused. Could that be?</p>
<p>Doesn&#8217;t matter, it works, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Felix</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32605</link>
		<dc:creator>Felix</dc:creator>
		<pubDate>Tue, 08 Nov 2011 22:52:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32605</guid>
		<description>Hi,
I get this error message:

??? Error using ==&gt; parallel_function at 598
Input argument &quot;initRobotList&quot; is undefined

I have no clue how this message could arise. I set up a simulation based on matlab-classes, that should run for 5 different parameter sets simultaneously.
In the beginning there is the parameter &#039;initRobotList&#039; that is handed over to the constructor.
The instances of the class are created successfully for all 5 simulations. This variable is nowhere else used but in the constuctor of the class, but after 5 min, and approx. 5000 simulation-steps in each of the 5 simulations, there is this message.

What could that be?
Where should I start looking?
It is a really big simulation so it is impossible to comment to a minimal example and see if it&#039;s working.

Thanks alot and kind regards

Fx</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I get this error message:</p>
<p>??? Error using ==&gt; parallel_function at 598<br />
Input argument &#8220;initRobotList&#8221; is undefined</p>
<p>I have no clue how this message could arise. I set up a simulation based on matlab-classes, that should run for 5 different parameter sets simultaneously.<br />
In the beginning there is the parameter &#8216;initRobotList&#8217; that is handed over to the constructor.<br />
The instances of the class are created successfully for all 5 simulations. This variable is nowhere else used but in the constuctor of the class, but after 5 min, and approx. 5000 simulation-steps in each of the 5 simulations, there is this message.</p>
<p>What could that be?<br />
Where should I start looking?<br />
It is a really big simulation so it is impossible to comment to a minimal example and see if it&#8217;s working.</p>
<p>Thanks alot and kind regards</p>
<p>Fx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Coen</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32546</link>
		<dc:creator>Coen</dc:creator>
		<pubDate>Thu, 13 Oct 2011 08:57:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32546</guid>
		<description>Dear Sarah,

I have been a (happy) Matlab user for many years now but have run into a limitation (?) of the distributed computing toolbox. For my research, I require parallel execution of a very large number of matrix-vector multiplications of differing sizes in Real-Time. These matrices are constructed offline, in an extremely expensive operation, and saved in a static data structure (MatSet in the example below). This static data structure is used by all workers, and is not modified after creation. 

When I run the code, which is equivalent to the code below, I find that the PARFOR loop takes 10x more time to complete than the FOR loop in Matlab 2009b. As I understand from your earlier explanations, this is because of the constant transfer of data (MatSet in this case) between workers. In my case, however, this data transfer is completely unnecessary!

My question is whether there is some way of loading a static dataset into the workspace of the workers so as to prevent unnecessary communication overhead between workers?

Thanks in advance,
Coen


&lt;pre&gt;
matlabpool(4); 
Msize = 100; Nloop = 1000; 
c1 = zeros(Msize, Nloop); c2 = zeros(Msize, Nloop);

% initialization loop (runs fine!)
MatSet = cell(Nloop, 1);
parfor i=1:Nloop
    MatSet{i} = rand(Msize); % in real life this would contain an extremely expensive code operation
end

% real-time parallel loop (SLOW!)
tic;
parfor i=1:Nloop
    c1(:,i) = MatSet{i} * rand(Msize, 1);
end
time1 = toc;

% real-time serial loop
tic;
for i=1:Nloop
    c2(:,i) = MatSet{i} * rand(Msize, 1);
end
time2 = toc;

fprintf(&#039;Parallel time: %2.4f ms, Serial Time: %2.4f ms\n&#039;, 1000*time1, 1000*time2);

&lt;pre&gt;</description>
		<content:encoded><![CDATA[<p>Dear Sarah,</p>
<p>I have been a (happy) Matlab user for many years now but have run into a limitation (?) of the distributed computing toolbox. For my research, I require parallel execution of a very large number of matrix-vector multiplications of differing sizes in Real-Time. These matrices are constructed offline, in an extremely expensive operation, and saved in a static data structure (MatSet in the example below). This static data structure is used by all workers, and is not modified after creation. </p>
<p>When I run the code, which is equivalent to the code below, I find that the PARFOR loop takes 10x more time to complete than the FOR loop in Matlab 2009b. As I understand from your earlier explanations, this is because of the constant transfer of data (MatSet in this case) between workers. In my case, however, this data transfer is completely unnecessary!</p>
<p>My question is whether there is some way of loading a static dataset into the workspace of the workers so as to prevent unnecessary communication overhead between workers?</p>
<p>Thanks in advance,<br />
Coen</p>
<pre>
matlabpool(4);<br />
Msize = 100; Nloop = 1000;<br />
c1 = zeros(Msize, Nloop); c2 = zeros(Msize, Nloop);
<p>% initialization loop (runs fine!)<br />
MatSet = cell(Nloop, 1);<br />
parfor i=1:Nloop<br />
    MatSet{i} = rand(Msize); % in real life this would contain an extremely expensive code operation<br />
end</p>
<p>% real-time parallel loop (SLOW!)<br />
tic;<br />
parfor i=1:Nloop<br />
    c1(:,i) = MatSet{i} * rand(Msize, 1);<br />
end<br />
time1 = toc;</p>
<p>% real-time serial loop<br />
tic;<br />
for i=1:Nloop<br />
    c2(:,i) = MatSet{i} * rand(Msize, 1);<br />
end<br />
time2 = toc;</p>
<p>fprintf('Parallel time: %2.4f ms, Serial Time: %2.4f ms\n', 1000*time1, 1000*time2);</p>
</pre><pre>
</pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32525</link>
		<dc:creator>Sarah</dc:creator>
		<pubDate>Fri, 30 Sep 2011 18:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32525</guid>
		<description>Suresh.

It is hard to diagnose this without the actual code. Usually it is either a network issue or a data size limit issue.  I have talked to support, and they encourage you to contact them to help you pinpoint the issue.  Their number is listed below:

Monday-Friday
Hours: 08:30 - 20:00 ET
Tel: 508-647-7000, option 2

Cheers,
Sarah</description>
		<content:encoded><![CDATA[<p>Suresh.</p>
<p>It is hard to diagnose this without the actual code. Usually it is either a network issue or a data size limit issue.  I have talked to support, and they encourage you to contact them to help you pinpoint the issue.  Their number is listed below:</p>
<p>Monday-Friday<br />
Hours: 08:30 &#8211; 20:00 ET<br />
Tel: 508-647-7000, option 2</p>
<p>Cheers,<br />
Sarah</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suresh</title>
		<link>http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32523</link>
		<dc:creator>Suresh</dc:creator>
		<pubDate>Fri, 30 Sep 2011 10:14:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/#comment-32523</guid>
		<description>Hi,

I have been using parfor for sometime on my quadcore pc for some pretty big optimization probelm which generally takes hours to solve..
I found sometime my code works fine but sometimes it breakes with the error .

??? Error using ==&gt; parallel_function at 598
The session that parfor is using has shut down

??? The client lost connection to lab 4.
This might be due to network problems, or the interactive matlabpool job might have
errored.

Please suggest how to deal with this issue.

Regards,
Suresh</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have been using parfor for sometime on my quadcore pc for some pretty big optimization probelm which generally takes hours to solve..<br />
I found sometime my code works fine but sometimes it breakes with the error .</p>
<p>??? Error using ==&gt; parallel_function at 598<br />
The session that parfor is using has shut down</p>
<p>??? The client lost connection to lab 4.<br />
This might be due to network problems, or the interactive matlabpool job might have<br />
errored.</p>
<p>Please suggest how to deal with this issue.</p>
<p>Regards,<br />
Suresh</p>
]]></content:encoded>
	</item>
</channel>
</rss>

