<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: parfor the Course</title>
	<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 08 Nov 2009 06:12:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Edric</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29700</link>
		<dc:creator>Edric</dc:creator>
		<pubDate>Thu, 14 Aug 2008 07:46:06 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29700</guid>
		<description>Steve W:

It should be possible to debug local workers simply locating the MATLAB process in task manager, and right-clicking on the worker process and selecting the "Debug" menu item. This will bring up the Visual Studio "just in time" debugger dialog. If you build your mex file with "-g", you should then be able to set breakpoints within your mex function source code. (I just verified that I could do this successfully, so let me know if you have problems here)

Having said that, I would not expect mexGetVariablePtr() to work as expected, as that violates workspace transparency - in other words, it attempts to read stuff from another workspace. In the same way, "evalin('caller', ...)" is disallowed.

When executing the body of a parfor loop, we only transmit from the client to the workers those variables that we can see (by analysing the code) are read from within the loop. This allows us to avoid sending the whole contents of the workspace. So, to work effectively with parfor, the variables used inside the body of the loop must be passed as arguments to your mex file.

One possible approach to avoiding sending large constant data repeatedly is to have the workers cache the data inside a persistent function workspace.

Cheers,

Edric.</description>
		<content:encoded><![CDATA[<p>Steve W:</p>
<p>It should be possible to debug local workers simply locating the MATLAB process in task manager, and right-clicking on the worker process and selecting the &#8220;Debug&#8221; menu item. This will bring up the Visual Studio &#8220;just in time&#8221; debugger dialog. If you build your mex file with &#8220;-g&#8221;, you should then be able to set breakpoints within your mex function source code. (I just verified that I could do this successfully, so let me know if you have problems here)</p>
<p>Having said that, I would not expect mexGetVariablePtr() to work as expected, as that violates workspace transparency - in other words, it attempts to read stuff from another workspace. In the same way, &#8220;evalin(&#8217;caller&#8217;, &#8230;)&#8221; is disallowed.</p>
<p>When executing the body of a parfor loop, we only transmit from the client to the workers those variables that we can see (by analysing the code) are read from within the loop. This allows us to avoid sending the whole contents of the workspace. So, to work effectively with parfor, the variables used inside the body of the loop must be passed as arguments to your mex file.</p>
<p>One possible approach to avoiding sending large constant data repeatedly is to have the workers cache the data inside a persistent function workspace.</p>
<p>Cheers,</p>
<p>Edric.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve W</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29697</link>
		<dc:creator>Steve W</dc:creator>
		<pubDate>Wed, 13 Aug 2008 10:51:03 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29697</guid>
		<description>Hi there, I've recently invested in the parallel computing toolbox and a quadcore cpu in the hope of being able to quickly speed up the execution of 'embarrassingly parallel' code that repeatedly calls a hand written mex function with different input each time. Response to reply 17 indicates this should work. I am trying to use parfor. Everything works fine using a for loop in local mode, but I get segmentation violation errors when using parfor (I get no pre-run time parfor related errors issued in the editor). Two questions:

(i) how do I debug code executing within the parfor loop, preferably both in Matlab and in C (I use ms visual studio 2005)? There does not seem to be a discussion of this in the relevant literature, but maybe I missed it.

(ii) Is it possible that the problem stems from the use of low level gateway routines? e.g. mexGetVariablePtr() to read Matlab memory locations as I'm not certain how the mex code knows to look for worker copies as opposed to the originally stored copy (and I'm not certain this should make a difference without debugging). I avoid using the mexPut... routines but have too many inputs (&#62;50) for the fetching of data, and prefer to pass pointers to large constant arrays rather than copying data to save time and memory.

Cheers,
Steve</description>
		<content:encoded><![CDATA[<p>Hi there, I&#8217;ve recently invested in the parallel computing toolbox and a quadcore cpu in the hope of being able to quickly speed up the execution of &#8216;embarrassingly parallel&#8217; code that repeatedly calls a hand written mex function with different input each time. Response to reply 17 indicates this should work. I am trying to use parfor. Everything works fine using a for loop in local mode, but I get segmentation violation errors when using parfor (I get no pre-run time parfor related errors issued in the editor). Two questions:</p>
<p>(i) how do I debug code executing within the parfor loop, preferably both in Matlab and in C (I use ms visual studio 2005)? There does not seem to be a discussion of this in the relevant literature, but maybe I missed it.</p>
<p>(ii) Is it possible that the problem stems from the use of low level gateway routines? e.g. mexGetVariablePtr() to read Matlab memory locations as I&#8217;m not certain how the mex code knows to look for worker copies as opposed to the originally stored copy (and I&#8217;m not certain this should make a difference without debugging). I avoid using the mexPut&#8230; routines but have too many inputs (&gt;50) for the fetching of data, and prefer to pass pointers to large constant arrays rather than copying data to save time and memory.</p>
<p>Cheers,<br />
Steve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul-Armand Verhaegen</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29494</link>
		<dc:creator>Paul-Armand Verhaegen</dc:creator>
		<pubDate>Thu, 12 Jun 2008 09:27:03 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29494</guid>
		<description>Dear Gaurav,

Thank you for your swift reply. And I surely don't like the trouble ahead... certainly when it come to my research :)

However, I've followed your instructions, and benchmarked an svd(A, 'econ'), with A = rand(1000);

The single core (directly in command window) takes 29 secs. The "non-interactive pmode" approach (my example) takes 13 secs. The "Parallel jobs" approach (your example) takes 32 secs (probably around 3 secs startup time). 

Maybe I haven't distributed my data in the correct manner, so I've included my test_par_svd function:
---
function u = test_par_svd (A)
    A_dist = distribute(A);
    [u_dist, s_dist, v_dist] = svd(A_dist, 'econ');
    u = gather(u_dist);
    s = gather(s_dist);
    v = gather(v_dist);
    clear u_dist; clear s_dist; clear v_dist;
    clear A_dist;
end
---

The results "o" also contains 4 times the "u" result from the function above, which kind of indicates that the labs cannot distribute the task among themselves, and every lab calculates the svd of the whole matrix in parallel, but not via a distributed parallel LAPACK SVD. Since my example uses less time, it surely is possible on my Intel MKL lib (version 9).

Please also note that I find it difficult to translate the easy example on parallel jobs (matlab docs) towards the use of an svd function, for which I can't control the calculation (function of MKL lib).

I'm now strugling with getting the "svds" function to work. MKL doesn't support this, so I've reworked my calculation via the "eigs" function (of the A*A' matrix), which gives the same results. But apparently this eigs function isn't supported in MKL 9 (it is in MKL 10). Does anybody know how to change the libs to MKL 10? (I've tried a couple of ways described in the matlab docs, but I really need the specific changes to blas.spec (or env. vars.) to get this to work I guess)

Best regards, and thanks a lot already for your time and effort,
Paul</description>
		<content:encoded><![CDATA[<p>Dear Gaurav,</p>
<p>Thank you for your swift reply. And I surely don&#8217;t like the trouble ahead&#8230; certainly when it come to my research :)</p>
<p>However, I&#8217;ve followed your instructions, and benchmarked an svd(A, &#8216;econ&#8217;), with A = rand(1000);</p>
<p>The single core (directly in command window) takes 29 secs. The &#8220;non-interactive pmode&#8221; approach (my example) takes 13 secs. The &#8220;Parallel jobs&#8221; approach (your example) takes 32 secs (probably around 3 secs startup time). </p>
<p>Maybe I haven&#8217;t distributed my data in the correct manner, so I&#8217;ve included my test_par_svd function:<br />
&#8212;<br />
function u = test_par_svd (A)<br />
    A_dist = distribute(A);<br />
    [u_dist, s_dist, v_dist] = svd(A_dist, &#8216;econ&#8217;);<br />
    u = gather(u_dist);<br />
    s = gather(s_dist);<br />
    v = gather(v_dist);<br />
    clear u_dist; clear s_dist; clear v_dist;<br />
    clear A_dist;<br />
end<br />
&#8212;</p>
<p>The results &#8220;o&#8221; also contains 4 times the &#8220;u&#8221; result from the function above, which kind of indicates that the labs cannot distribute the task among themselves, and every lab calculates the svd of the whole matrix in parallel, but not via a distributed parallel LAPACK SVD. Since my example uses less time, it surely is possible on my Intel MKL lib (version 9).</p>
<p>Please also note that I find it difficult to translate the easy example on parallel jobs (matlab docs) towards the use of an svd function, for which I can&#8217;t control the calculation (function of MKL lib).</p>
<p>I&#8217;m now strugling with getting the &#8220;svds&#8221; function to work. MKL doesn&#8217;t support this, so I&#8217;ve reworked my calculation via the &#8220;eigs&#8221; function (of the A*A&#8217; matrix), which gives the same results. But apparently this eigs function isn&#8217;t supported in MKL 9 (it is in MKL 10). Does anybody know how to change the libs to MKL 10? (I&#8217;ve tried a couple of ways described in the matlab docs, but I really need the specific changes to blas.spec (or env. vars.) to get this to work I guess)</p>
<p>Best regards, and thanks a lot already for your time and effort,<br />
Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaurav Sharma</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29486</link>
		<dc:creator>Gaurav Sharma</dc:creator>
		<pubDate>Wed, 11 Jun 2008 15:59:24 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29486</guid>
		<description>The last few lines in my previous post should actually read: 
&lt;pre&gt;
pjob = jm.createParallelJob();
t    = job.createTask(@myfunction, numOutputs, {input1, input2})); 
pjob.submit;

%% optionally: pjob.waitForState('Finished'); 
o = pjob.getAllOutputArguments; 
celldisp(o); 
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The last few lines in my previous post should actually read: </p>
<pre>
pjob = jm.createParallelJob();
t    = job.createTask(@myfunction, numOutputs, {input1, input2}));
pjob.submit;

%% optionally: pjob.waitForState('Finished');
o = pjob.getAllOutputArguments;
celldisp(o);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaurav Sharma</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29485</link>
		<dc:creator>Gaurav Sharma</dc:creator>
		<pubDate>Wed, 11 Jun 2008 15:57:27 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29485</guid>
		<description>Paul:

Using undocumented API is a surefire way to get into massive trouble. 

A much easier way is to use the documented "Parallel Job" API. See documentation: http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/bqur73g.html

Here is a quick recipe for going from interactive to non-interactive way:
1. Once you have tested your algorithm in "pmode", create a MATLAB function file using the commands/function calls that worked. 

1a. An easy way to do this is to enable command history in "pmode" window, select the commands that worked (CTRL+Click for multiple commands on Windows), right click and choose "Create M-File". 

2. Make it a MATLAB function, i.e., add "function" etc. at the top of the file . 

3. Create a parallel job (&lt;i&gt;createParallelJob&lt;/i&gt;), add a task to it (&lt;i&gt;createTask&lt;/i&gt;) and supply the MATLAB function you created as an input to the  task creation function. 

4. The &lt;i&gt;createParallelJob&lt;/i&gt; function returns a job object which you can &lt;i&gt;submit&lt;/i&gt; and later retrieve results, check status etc. 

4a. Add &lt;i&gt;FileDependencies&lt;/i&gt; to this job object if your function uses other functions created by you.

I noticed you are using the 'local' configuration. So here is what you can do:
&lt;pre&gt;
jm = findResource('scheduler', 'configuration', 'local'); &lt;/pre&gt; and then follow the regular steps for a parallel job. For example:
&lt;pre&gt;
pjob = jm.createParallelJob();
t   = job.createTask(@myfunction, numOutputs, {input1, input2})); 
pjob.submit;
%optionally: pjob.waitForState('Finished'); o = pjob.getAllOutputArguments; celldisp(o); &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Paul:</p>
<p>Using undocumented API is a surefire way to get into massive trouble. </p>
<p>A much easier way is to use the documented &#8220;Parallel Job&#8221; API. See documentation: <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/bqur73g.html" rel="nofollow">http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/bqur73g.html</a></p>
<p>Here is a quick recipe for going from interactive to non-interactive way:<br />
1. Once you have tested your algorithm in &#8220;pmode&#8221;, create a MATLAB function file using the commands/function calls that worked. </p>
<p>1a. An easy way to do this is to enable command history in &#8220;pmode&#8221; window, select the commands that worked (CTRL+Click for multiple commands on Windows), right click and choose &#8220;Create M-File&#8221;. </p>
<p>2. Make it a MATLAB function, i.e., add &#8220;function&#8221; etc. at the top of the file . </p>
<p>3. Create a parallel job (<i>createParallelJob</i>), add a task to it (<i>createTask</i>) and supply the MATLAB function you created as an input to the  task creation function. </p>
<p>4. The <i>createParallelJob</i> function returns a job object which you can <i>submit</i> and later retrieve results, check status etc. </p>
<p>4a. Add <i>FileDependencies</i> to this job object if your function uses other functions created by you.</p>
<p>I noticed you are using the &#8216;local&#8217; configuration. So here is what you can do:</p>
<pre>
jm = findResource('scheduler', 'configuration', 'local'); </pre>
<p> and then follow the regular steps for a parallel job. For example:</p>
<pre>
pjob = jm.createParallelJob();
t   = job.createTask(@myfunction, numOutputs, {input1, input2}));
pjob.submit;
%optionally: pjob.waitForState('Finished'); o = pjob.getAllOutputArguments; celldisp(o); </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul-Armand Verhaegen</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29484</link>
		<dc:creator>Paul-Armand Verhaegen</dc:creator>
		<pubDate>Wed, 11 Jun 2008 10:03:56 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29484</guid>
		<description>In reply to my own question: I've managed to send command to the (interactive) pmode, thus making it non-interactive. Example code below:
---
function par_svd(input_variable)
% Executes a distributed calculation of the svd

NR_OF_LABS = 4;

% opening pmode on 4 labs
pmode ('start', 'local', NR_OF_LABS);

% Distributing the array A over the labs
    % Copy A to the labs
    pmode('client2lab', input_variable, strcat('1:', int2str(NR_OF_LABS)));
    % Distribute on the labs
    iRunCmdOnLabs(strcat('A_dist = distribute(', input_variable, ');')); 

% Calculate the svd in a distributed manner
    iRunCmdOnLabs('[u_dist, s_dist, v_dist] = svd(A_dist , ''econ'');'); 

% Gather the data back into every lab
    iRunCmdOnLabs('u = gather(u_dist); s = gather(s_dist); v = gather(v_dist);'); 
    
% Clear intermediary results
    iRunCmdOnLabs('clear u_dist; clear s_dist; clear v_dist; clear A_dist'); 

% Send results back to the client
    pmode lab2client u 1;     
    pmode lab2client s 1;
    pmode lab2client v 1;

% Clean up the parallel labs
pmode cleanup;

end

function labs = iGetLabs()
%iGetLabs Can be called on the client to get the labs object.
    if ~iIsOnClient()
        error('Cannot execute par_svd from labs');
        return;
    end
    try
        session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession;
        labs = session.getLabs();
    catch
        error('distcomp:pmode:NotRunning, cannot execute par_svd');
    end
end

function iRunCmdOnLabs(cmd)
%iRunCmdOnLabs Send a command to the labs
    session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession; 
    if isempty(session)
        error('distcomp:pmode:NotRunning', ...
              'Cannot execute par_svd when pmode is not running.');
    end
    % Error messages will only be displayed in the main MATLAB command window, and
    % the command will only be executed in the MATLAB client when it is idle.
    fprintf('Sending command %s to the MATLAB labs for evaluation.', cmd);
    labs = iGetLabs();
    labs.evalConsoleOutput(cmd);
end

function onclient = iIsOnClient()
    onclient = ~system_dependent('isdmlworker');
end
---

If anybody know a more elegant solution, please let me know!

Ps: Use the code at own risk. One method (labs.evalConsoleOutput(cmd);) on the labs was undocumented, but seems to work. Have fun, and save time!

Best regards,
Paul</description>
		<content:encoded><![CDATA[<p>In reply to my own question: I&#8217;ve managed to send command to the (interactive) pmode, thus making it non-interactive. Example code below:<br />
&#8212;<br />
function par_svd(input_variable)<br />
% Executes a distributed calculation of the svd</p>
<p>NR_OF_LABS = 4;</p>
<p>% opening pmode on 4 labs<br />
pmode (&#8217;start&#8217;, &#8216;local&#8217;, NR_OF_LABS);</p>
<p>% Distributing the array A over the labs<br />
    % Copy A to the labs<br />
    pmode(&#8217;client2lab&#8217;, input_variable, strcat(&#8217;1:&#8217;, int2str(NR_OF_LABS)));<br />
    % Distribute on the labs<br />
    iRunCmdOnLabs(strcat(&#8217;A_dist = distribute(&#8217;, input_variable, &#8216;);&#8217;)); </p>
<p>% Calculate the svd in a distributed manner<br />
    iRunCmdOnLabs(&#8217;[u_dist, s_dist, v_dist] = svd(A_dist , &#8221;econ&#8221;);&#8217;); </p>
<p>% Gather the data back into every lab<br />
    iRunCmdOnLabs(&#8217;u = gather(u_dist); s = gather(s_dist); v = gather(v_dist);&#8217;); </p>
<p>% Clear intermediary results<br />
    iRunCmdOnLabs(&#8217;clear u_dist; clear s_dist; clear v_dist; clear A_dist&#8217;); </p>
<p>% Send results back to the client<br />
    pmode lab2client u 1;<br />
    pmode lab2client s 1;<br />
    pmode lab2client v 1;</p>
<p>% Clean up the parallel labs<br />
pmode cleanup;</p>
<p>end</p>
<p>function labs = iGetLabs()<br />
%iGetLabs Can be called on the client to get the labs object.<br />
    if ~iIsOnClient()<br />
        error(&#8217;Cannot execute par_svd from labs&#8217;);<br />
        return;<br />
    end<br />
    try<br />
        session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession;<br />
        labs = session.getLabs();<br />
    catch<br />
        error(&#8217;distcomp:pmode:NotRunning, cannot execute par_svd&#8217;);<br />
    end<br />
end</p>
<p>function iRunCmdOnLabs(cmd)<br />
%iRunCmdOnLabs Send a command to the labs<br />
    session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession;<br />
    if isempty(session)<br />
        error(&#8217;distcomp:pmode:NotRunning&#8217;, &#8230;<br />
              &#8216;Cannot execute par_svd when pmode is not running.&#8217;);<br />
    end<br />
    % Error messages will only be displayed in the main MATLAB command window, and<br />
    % the command will only be executed in the MATLAB client when it is idle.<br />
    fprintf(&#8217;Sending command %s to the MATLAB labs for evaluation.&#8217;, cmd);<br />
    labs = iGetLabs();<br />
    labs.evalConsoleOutput(cmd);<br />
end</p>
<p>function onclient = iIsOnClient()<br />
    onclient = ~system_dependent(&#8217;isdmlworker&#8217;);<br />
end<br />
&#8212;</p>
<p>If anybody know a more elegant solution, please let me know!</p>
<p>Ps: Use the code at own risk. One method (labs.evalConsoleOutput(cmd);) on the labs was undocumented, but seems to work. Have fun, and save time!</p>
<p>Best regards,<br />
Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul-Armand Verhaegen</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29482</link>
		<dc:creator>Paul-Armand Verhaegen</dc:creator>
		<pubDate>Tue, 10 Jun 2008 14:19:44 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29482</guid>
		<description>I have successfully computed the svd(..., 'econ') of a matrix on a quad core machine by using the interactive pmode. The instructions to do this were:
&#62;&#62; A = rand(1000);
&#62;&#62; pmode start local 4;
&#62;&#62; pmode client2lab A 1:4;

And in the parallel command window:
P&#62;&#62; A_dist = distribute(A);
P&#62;&#62; [u, s, v] = svd(A_dist, 'econ');
P&#62;&#62; u_comb = gather(u);

Back in the matlab command window
&#62;&#62; pmode lab2client u_comb;

I obtained a significant speedup (6,8 secs compared to 17 secs). However, I would like to do this non-interactive from an M-file. 

Ps: Doing more or less the same with the matlabpool command clearly indicates that no speedup is obtained. So I concluded that matlabpool only works for the parfor loop, is this correct? 

Can anybody guide me in the right direction? 

Thanks you,
Paul

However, I now want to</description>
		<content:encoded><![CDATA[<p>I have successfully computed the svd(&#8230;, &#8216;econ&#8217;) of a matrix on a quad core machine by using the interactive pmode. The instructions to do this were:<br />
&gt;&gt; A = rand(1000);<br />
&gt;&gt; pmode start local 4;<br />
&gt;&gt; pmode client2lab A 1:4;</p>
<p>And in the parallel command window:<br />
P&gt;&gt; A_dist = distribute(A);<br />
P&gt;&gt; [u, s, v] = svd(A_dist, &#8216;econ&#8217;);<br />
P&gt;&gt; u_comb = gather(u);</p>
<p>Back in the matlab command window<br />
&gt;&gt; pmode lab2client u_comb;</p>
<p>I obtained a significant speedup (6,8 secs compared to 17 secs). However, I would like to do this non-interactive from an M-file. </p>
<p>Ps: Doing more or less the same with the matlabpool command clearly indicates that no speedup is obtained. So I concluded that matlabpool only works for the parfor loop, is this correct? </p>
<p>Can anybody guide me in the right direction? </p>
<p>Thanks you,<br />
Paul</p>
<p>However, I now want to</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narfi</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29455</link>
		<dc:creator>Narfi</dc:creator>
		<pubDate>Thu, 05 Jun 2008 20:35:47 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29455</guid>
		<description>The MATLAB path problem you are experiencing is a little bit tricky because it depends on your exact setup, so I recommend you ask our technical support for help with these and other questions that you may have.  
The simplest general solution for problems with parfor and the way it manipulates variables is to move the loop body into a separate function.  E.g. in case b), the function would accept i and s as input arguments.  If this doesn’t work for you, I recommend you contact technical support.


Best,

Narfi</description>
		<content:encoded><![CDATA[<p>The MATLAB path problem you are experiencing is a little bit tricky because it depends on your exact setup, so I recommend you ask our technical support for help with these and other questions that you may have.<br />
The simplest general solution for problems with parfor and the way it manipulates variables is to move the loop body into a separate function.  E.g. in case b), the function would accept i and s as input arguments.  If this doesn’t work for you, I recommend you contact technical support.</p>
<p>Best,</p>
<p>Narfi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yannick</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29454</link>
		<dc:creator>Yannick</dc:creator>
		<pubDate>Thu, 05 Jun 2008 19:50:14 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29454</guid>
		<description>Ok, thanks... more questions! I received an evaluation license for the Parallel Computing toolbox and the distributed computing server, I'm attempting to test the functions thorougly and I have the following questions on the parfor loop (and the Product Help didn't bring an answer): 

a) I substituted parfor for a for loop in a script. A function is called in this loop. Somehow parfor does not look for the function in the same path as the for loop and was calling another version of that function in another directory. How is parfor looking for a function differently than for?

b) I have a struct that I declare outside of the for loop but one field is assigned within the loop. example
s.f1=1;
s.f2=2;
for i=1:10
s.f3=i
output(i)=myfunction(s);
end

This works fine in a for loop, but the parfor loop seems to erase the comple s struct instead of just the field f3. Is this normal? 

c) I can't seem to pass in a cell array of strings which is not assigned inside the loop, it seems to get erased as well. Example
Mystringarray;    %cell array of strings
for n=1:length(Mystringarray)
s.f3=Mystringarray(n);
end

Now when i use parfor, it seems like Mystringarray does not exist after the first iteration of the parfor. 

Thanks!!!</description>
		<content:encoded><![CDATA[<p>Ok, thanks&#8230; more questions! I received an evaluation license for the Parallel Computing toolbox and the distributed computing server, I&#8217;m attempting to test the functions thorougly and I have the following questions on the parfor loop (and the Product Help didn&#8217;t bring an answer): </p>
<p>a) I substituted parfor for a for loop in a script. A function is called in this loop. Somehow parfor does not look for the function in the same path as the for loop and was calling another version of that function in another directory. How is parfor looking for a function differently than for?</p>
<p>b) I have a struct that I declare outside of the for loop but one field is assigned within the loop. example<br />
s.f1=1;<br />
s.f2=2;<br />
for i=1:10<br />
s.f3=i<br />
output(i)=myfunction(s);<br />
end</p>
<p>This works fine in a for loop, but the parfor loop seems to erase the comple s struct instead of just the field f3. Is this normal? </p>
<p>c) I can&#8217;t seem to pass in a cell array of strings which is not assigned inside the loop, it seems to get erased as well. Example<br />
Mystringarray;    %cell array of strings<br />
for n=1:length(Mystringarray)<br />
s.f3=Mystringarray(n);<br />
end</p>
<p>Now when i use parfor, it seems like Mystringarray does not exist after the first iteration of the parfor. </p>
<p>Thanks!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Narfi</title>
		<link>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29437</link>
		<dc:creator>Narfi</dc:creator>
		<pubDate>Wed, 04 Jun 2008 17:51:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/10/03/parfor-the-course/#comment-29437</guid>
		<description>I presume that by "iteration", you mean a task in a job.  Currently, the job manager does not re-run tasks that fail due to workers being killed or other system errors like that, and instead simply marks those tasks as failed.  However, we have been actively working on this, so you can expect improvements in this area fairly soon.

Best,

Narfi</description>
		<content:encoded><![CDATA[<p>I presume that by &#8220;iteration&#8221;, you mean a task in a job.  Currently, the job manager does not re-run tasks that fail due to workers being killed or other system errors like that, and instead simply marks those tasks as failed.  However, we have been actively working on this, so you can expect improvements in this area fairly soon.</p>
<p>Best,</p>
<p>Narfi</p>
]]></content:encoded>
	</item>
</channel>
</rss>
