<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559</link>
    <title>MATLAB Central Newsreader - Parallel computing toolbox: help with parfor!</title>
    <description>Feed for thread: Parallel computing toolbox: help 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>Mon, 04 May 2009 23:15:08 -0400</pubDate>
      <title>Parallel computing toolbox: help with parfor!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559#647353</link>
      <author>Elizabeth Kusel</author>
      <description>Hi everyone,&lt;br&gt;
I have recently started using the parallel computing toolbox to take full advantage of my machine's 4 processors in my computations.&lt;br&gt;
&lt;br&gt;
My problem involves running simulations for different frequencies (25 in total). The iterations are independent from each other but I need to call a fortran executable to calculate what I need. I use parfor to loop over the different frequencies passing them to a matlab function which:&lt;br&gt;
1) writes the input file for the fortran routine containing the specific frequency&lt;br&gt;
2) calls the fortran executable&lt;br&gt;
3) uses the movefile command to change the name of the fortran output file, which is what I'm ultimately interested in.&lt;br&gt;
&lt;br&gt;
Here is the code that I wrote for that:&lt;br&gt;
matlabpool local 4&lt;br&gt;
parfor j=1:25&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;callbellhop(freq(j),zmax,zmax1,ndz,ndr,rmax,rotl);&lt;br&gt;
&amp;nbsp;end&lt;br&gt;
matlabpool close&lt;br&gt;
&lt;br&gt;
function callbellhop(freq,zmax,zmax1,ndz,ndr,rmax,rotl)&lt;br&gt;
write_envfl2(freq,zmax,zmax1,ndz,ndr,rmax,rotl); % writes the file AUTEC.env&lt;br&gt;
! bellhop.exe &amp;lt; AUTEC.env &lt;br&gt;
movefile('SHDFIL',(['SHDFIL' num2str(freq)]))&lt;br&gt;
&lt;br&gt;
When I first attempted to run it, it seemed everything was working fine. All the processors were being used, and the output files were being created for each frequency. However, when the iteration reached j&quot; I got an error:&lt;br&gt;
&lt;br&gt;
??? Error using ==&amp;gt; parallel_function at 594&lt;br&gt;
Error in ==&amp;gt; callbellhop at 4&lt;br&gt;
mv: cannot stat `/home/.../Trans1/SHDFIL': No such file or directory&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; bw_248bdive2_input at 99&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parfor j=1:25&lt;br&gt;
&lt;br&gt;
I repeated it more than once and I get the same problem. Does anyone have any clues why it would stop before it finished? Am I overseeing any issues regarding calling the fortran executable and renaming it's output inside a parfor loop?&lt;br&gt;
Thank you in advance for any input you could give me!&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Elizabeth</description>
    </item>
    <item>
      <pubDate>Mon, 04 May 2009 23:58:01 -0400</pubDate>
      <title>Re: Parallel computing toolbox: help with parfor!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559#647356</link>
      <author>Jiro Doke</author>
      <description>&quot;Elizabeth Kusel&quot; &amp;lt;elizabeth.kusel@oregonstate.com&amp;gt; wrote in message &amp;lt;gtnsts$no9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everyone,&lt;br&gt;
&amp;gt; I have recently started using the parallel computing toolbox to take full advantage of my machine's 4 processors in my computations.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My problem involves running simulations for different frequencies (25 in total). The iterations are independent from each other but I need to call a fortran executable to calculate what I need. I use parfor to loop over the different frequencies passing them to a matlab function which:&lt;br&gt;
&amp;gt; 1) writes the input file for the fortran routine containing the specific frequency&lt;br&gt;
&amp;gt; 2) calls the fortran executable&lt;br&gt;
&amp;gt; 3) uses the movefile command to change the name of the fortran output file, which is what I'm ultimately interested in.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Here is the code that I wrote for that:&lt;br&gt;
&amp;gt; matlabpool local 4&lt;br&gt;
&amp;gt; parfor j=1:25&lt;br&gt;
&amp;gt;      callbellhop(freq(j),zmax,zmax1,ndz,ndr,rmax,rotl);&lt;br&gt;
&amp;gt;  end&lt;br&gt;
&amp;gt; matlabpool close&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function callbellhop(freq,zmax,zmax1,ndz,ndr,rmax,rotl)&lt;br&gt;
&amp;gt; write_envfl2(freq,zmax,zmax1,ndz,ndr,rmax,rotl); % writes the file AUTEC.env&lt;br&gt;
&amp;gt; ! bellhop.exe &amp;lt; AUTEC.env &lt;br&gt;
&amp;gt; movefile('SHDFIL',(['SHDFIL' num2str(freq)]))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I first attempted to run it, it seemed everything was working fine. All the processors were being used, and the output files were being created for each frequency. However, when the iteration reached j&quot; I got an error:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; parallel_function at 594&lt;br&gt;
&amp;gt; Error in ==&amp;gt; callbellhop at 4&lt;br&gt;
&amp;gt; mv: cannot stat `/home/.../Trans1/SHDFIL': No such file or directory&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Error in ==&amp;gt; bw_248bdive2_input at 99&lt;br&gt;
&amp;gt;     parfor j=1:25&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I repeated it more than once and I get the same problem. Does anyone have any clues why it would stop before it finished? Am I overseeing any issues regarding calling the fortran executable and renaming it's output inside a parfor loop?&lt;br&gt;
&amp;gt; Thank you in advance for any input you could give me!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Elizabeth&lt;br&gt;
&lt;br&gt;
Elizabeth,&lt;br&gt;
&lt;br&gt;
I think the problem is that your fortran routine in each iteration is writing out to the same file &quot;SHDFIL&quot;. Since PARFOR loops are running in parallel, there are a lot of overwriting of the same file and different loops grabbing results from other loops. You should find a way to have your fortran routine write out to a different file name, or make sure that other iterations cannot touch the file from the current iteration.</description>
    </item>
    <item>
      <pubDate>Tue, 05 May 2009 00:22:01 -0400</pubDate>
      <title>Re: Parallel computing toolbox: help with parfor!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559#647365</link>
      <author>Elizabeth Kusel</author>
      <description>Jiro,&lt;br&gt;
Thanks for your reply. I just figured that out! &lt;br&gt;
&lt;br&gt;
I'm trying not to change the fortran routine if I can, since I don't have admin privileges to recompile the code myself. Also the code is part of a bigger fortran toolbox and compiling is not an easy process...&lt;br&gt;
May be I could try splitting the matlab calculations into 4 different temporary directories? &lt;br&gt;
&lt;br&gt;
Back to thinking of what and how to do it!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Jiro Doke&quot; &amp;lt;jiro.doke@mathworks.com&amp;gt; wrote in message &amp;lt;gtnve9$6sl$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Elizabeth Kusel&quot; &amp;lt;elizabeth.kusel@oregonstate.com&amp;gt; wrote in message &amp;lt;gtnsts$no9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi everyone,&lt;br&gt;
&amp;gt; &amp;gt; I have recently started using the parallel computing toolbox to take full advantage of my machine's 4 processors in my computations.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; My problem involves running simulations for different frequencies (25 in total). The iterations are independent from each other but I need to call a fortran executable to calculate what I need. I use parfor to loop over the different frequencies passing them to a matlab function which:&lt;br&gt;
&amp;gt; &amp;gt; 1) writes the input file for the fortran routine containing the specific frequency&lt;br&gt;
&amp;gt; &amp;gt; 2) calls the fortran executable&lt;br&gt;
&amp;gt; &amp;gt; 3) uses the movefile command to change the name of the fortran output file, which is what I'm ultimately interested in.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Here is the code that I wrote for that:&lt;br&gt;
&amp;gt; &amp;gt; matlabpool local 4&lt;br&gt;
&amp;gt; &amp;gt; parfor j=1:25&lt;br&gt;
&amp;gt; &amp;gt;      callbellhop(freq(j),zmax,zmax1,ndz,ndr,rmax,rotl);&lt;br&gt;
&amp;gt; &amp;gt;  end&lt;br&gt;
&amp;gt; &amp;gt; matlabpool close&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; function callbellhop(freq,zmax,zmax1,ndz,ndr,rmax,rotl)&lt;br&gt;
&amp;gt; &amp;gt; write_envfl2(freq,zmax,zmax1,ndz,ndr,rmax,rotl); % writes the file AUTEC.env&lt;br&gt;
&amp;gt; &amp;gt; ! bellhop.exe &amp;lt; AUTEC.env &lt;br&gt;
&amp;gt; &amp;gt; movefile('SHDFIL',(['SHDFIL' num2str(freq)]))&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; When I first attempted to run it, it seemed everything was working fine. All the processors were being used, and the output files were being created for each frequency. However, when the iteration reached j&quot; I got an error:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; parallel_function at 594&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; callbellhop at 4&lt;br&gt;
&amp;gt; &amp;gt; mv: cannot stat `/home/.../Trans1/SHDFIL': No such file or directory&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; bw_248bdive2_input at 99&lt;br&gt;
&amp;gt; &amp;gt;     parfor j=1:25&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I repeated it more than once and I get the same problem. Does anyone have any clues why it would stop before it finished? Am I overseeing any issues regarding calling the fortran executable and renaming it's output inside a parfor loop?&lt;br&gt;
&amp;gt; &amp;gt; Thank you in advance for any input you could give me!&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Cheers,&lt;br&gt;
&amp;gt; &amp;gt; Elizabeth&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Elizabeth,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think the problem is that your fortran routine in each iteration is writing out to the same file &quot;SHDFIL&quot;. Since PARFOR loops are running in parallel, there are a lot of overwriting of the same file and different loops grabbing results from other loops. You should find a way to have your fortran routine write out to a different file name, or make sure that other iterations cannot touch the file from the current iteration.</description>
    </item>
    <item>
      <pubDate>Tue, 05 May 2009 13:30:35 -0400</pubDate>
      <title>Re: Parallel computing toolbox: help with parfor!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559#647476</link>
      <author>Edric M Ellis</author>
      <description>&quot;Elizabeth Kusel&quot; &amp;lt;elizabeth.kusel@oregonstate.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; [...]&lt;br&gt;
&amp;gt; I'm trying not to change the fortran routine if I can, since I don't have&lt;br&gt;
&amp;gt; admin privileges to recompile the code myself. Also the code is part of a&lt;br&gt;
&amp;gt; bigger fortran toolbox and compiling is not an easy process...  May be I could&lt;br&gt;
&amp;gt; try splitting the matlab calculations into 4 different temporary directories?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Back to thinking of what and how to do it!&lt;br&gt;
&lt;br&gt;
One thing you need to be aware of is that MATLABPOOL attempts to synchronise the&lt;br&gt;
path and current directory between client and workers - usually this is very&lt;br&gt;
convenient, but it will get in the way for you. Therefore, to make this work,&lt;br&gt;
you need to be somewhat careful. Something like this should work:&lt;br&gt;
&lt;br&gt;
parfor ii=1:N&lt;br&gt;
&amp;nbsp;&amp;nbsp;% Concoct a temp dir for this worker that remains constant&lt;br&gt;
&amp;nbsp;&amp;nbsp;mytmpdir = fullfile( tempdir, sprintf( 'mytmp.%d', system_dependent( 'getpid' ) ) );&lt;br&gt;
&amp;nbsp;&amp;nbsp;if ~exist( mytmpdir, 'dir' )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mkdir( mytmpdir );&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;previousDir = cd( mytmpdir );&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;% Call your code here...&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;cd( previousDir );&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Tue, 05 May 2009 22:35:02 -0400</pubDate>
      <title>Re: Parallel computing toolbox: help with parfor!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559#647676</link>
      <author>Elizabeth Kusel</author>
      <description>Edric,&lt;br&gt;
Thank you so much for your suggestion! I had thought of doing that but didn't quite know how to translate into matlab! I was already on my way to talk to the sys admin to change the fortran code when I saw your reply :) The code is now working and the results are as they should be (that is, the output files are not being overwritten).&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Elizabeth&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytwprenpthg.fsf@uk-eellis-deb4-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Elizabeth Kusel&quot; &amp;lt;elizabeth.kusel@oregonstate.com&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [...]&lt;br&gt;
&amp;gt; &amp;gt; I'm trying not to change the fortran routine if I can, since I don't have&lt;br&gt;
&amp;gt; &amp;gt; admin privileges to recompile the code myself. Also the code is part of a&lt;br&gt;
&amp;gt; &amp;gt; bigger fortran toolbox and compiling is not an easy process...  May be I could&lt;br&gt;
&amp;gt; &amp;gt; try splitting the matlab calculations into 4 different temporary directories?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Back to thinking of what and how to do it!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; One thing you need to be aware of is that MATLABPOOL attempts to synchronise the&lt;br&gt;
&amp;gt; path and current directory between client and workers - usually this is very&lt;br&gt;
&amp;gt; convenient, but it will get in the way for you. Therefore, to make this work,&lt;br&gt;
&amp;gt; you need to be somewhat careful. Something like this should work:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; parfor ii=1:N&lt;br&gt;
&amp;gt;   % Concoct a temp dir for this worker that remains constant&lt;br&gt;
&amp;gt;   mytmpdir = fullfile( tempdir, sprintf( 'mytmp.%d', system_dependent( 'getpid' ) ) );&lt;br&gt;
&amp;gt;   if ~exist( mytmpdir, 'dir' )&lt;br&gt;
&amp;gt;       mkdir( mytmpdir );&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt;   previousDir = cd( mytmpdir );&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   % Call your code here...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   cd( previousDir );&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.</description>
    </item>
  </channel>
</rss>

