<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523</link>
    <title>MATLAB Central Newsreader - parfor: fopen Issues</title>
    <description>Feed for thread: parfor: fopen Issues</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, 24 Jun 2009 11:03:01 -0400</pubDate>
      <title>parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660005</link>
      <author>Mr. CFD</author>
      <description>I have a simulation which runs over &amp;#8216;n&amp;#8217; successive iterations using the parfor command. At each iteration, a series of scripts are generated using the fopen command; these contain user-defined commands for an external program. MATLAB then runs the script file and saves the results. The files are named according to the index of the parfor command (e.g parfor ii = 1:20). I am using the MATLABPOOL with a local scheduler. &lt;br&gt;
&lt;br&gt;
At each iteration the contents of the files are updated i.e. files are never deleted the naming index remains according to the state of the parfor command and the contents (user-defined script commands) are updated.&lt;br&gt;
&lt;br&gt;
On most occasions the simulations run successfully with no issues. However, on some rare occasions an error is reported relating the failure of fopen as:&lt;br&gt;
&lt;br&gt;
??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
Error in ==&amp;gt; Main_Flight at 70&lt;br&gt;
Invalid file identifier.  Use fopen to generate a valid file identifier.&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; Optz_v2 at 203&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;matlabpool local 4 &lt;br&gt;
&lt;br&gt;
The code where MATLAB is pointing to is as:&lt;br&gt;
script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
[fidd] = fopen(script, 'wt');&lt;br&gt;
fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
fclose all&lt;br&gt;
&lt;br&gt;
I&amp;#8217;m not sure why MATLAB won&amp;#8217;t open the file in question as it is in the working directory. As I mentioned earlier, the simulations run successfully on most occasions however, there is an obvious scenario which results in this error. Any suggestions please?</description>
    </item>
    <item>
      <pubDate>Wed, 24 Jun 2009 12:15:46 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660034</link>
      <author>Edric M Ellis</author>
      <description>&quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; I have a simulation which runs over &amp;#8216;n&amp;#8217; successive iterations&lt;br&gt;
&amp;gt; using the parfor command. At each iteration, a series of scripts are generated&lt;br&gt;
&amp;gt; using the fopen command; these contain user-defined commands for an external&lt;br&gt;
&amp;gt; program. MATLAB then runs the script file and saves the results. The files are&lt;br&gt;
&amp;gt; named according to the index of the parfor command (e.g parfor ii = 1:20). I&lt;br&gt;
&amp;gt; am using the MATLABPOOL with a local scheduler.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; At each iteration the contents of the files are updated i.e. files are never&lt;br&gt;
&amp;gt; deleted the naming index remains according to the state of the parfor command&lt;br&gt;
&amp;gt; and the contents (user-defined script commands) are updated.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; On most occasions the simulations run successfully with no issues. However, on&lt;br&gt;
&amp;gt; some rare occasions an error is reported relating the failure of fopen as:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
&amp;gt; Error in ==&amp;gt; Main_Flight at 70&lt;br&gt;
&amp;gt; Invalid file identifier.  Use fopen to generate a valid file identifier.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Error in ==&amp;gt; Optz_v2 at 203&lt;br&gt;
&amp;gt;     matlabpool local 4 &lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The code where MATLAB is pointing to is as:&lt;br&gt;
&amp;gt; script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
&amp;gt; [fidd] = fopen(script, 'wt');&lt;br&gt;
&amp;gt; fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&amp;gt; fclose all&lt;br&gt;
&lt;br&gt;
That seems to me as thought it should work. The main risk is that some other&lt;br&gt;
process has the file open for writing - on Windows, you cannot have two&lt;br&gt;
processes writing to the same file simultaneously, and any second call to fopen&lt;br&gt;
will fail. A couple of suggestions:&lt;br&gt;
&lt;br&gt;
1. Replace your fopen line with something like this:&lt;br&gt;
&lt;br&gt;
[fidd, message] = fopen( script, 'wt' );&lt;br&gt;
if fidd == -1&lt;br&gt;
&amp;nbsp;&amp;nbsp;error( 'Couldn''t write to %s: %s', script, message );&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
2. Replace your fclose line with something like this:&lt;br&gt;
&lt;br&gt;
st = fclose( fidd );&lt;br&gt;
if st ~= 0&lt;br&gt;
&amp;nbsp;&amp;nbsp;error( 'Error code from close: %d, file: %s', st, script );&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Hopefully that will help pinpoint which files are failing to open or close, and&lt;br&gt;
possibly even why.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Wed, 24 Jun 2009 14:53:02 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660127</link>
      <author>Mr. CFD</author>
      <description>Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytw1vp9omj1.fsf@uk-eellis-deb4-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have a simulation which runs over &amp;#8216;n&amp;#8217; successive iterations&lt;br&gt;
&amp;gt; &amp;gt; using the parfor command. At each iteration, a series of scripts are generated&lt;br&gt;
&amp;gt; &amp;gt; using the fopen command; these contain user-defined commands for an external&lt;br&gt;
&amp;gt; &amp;gt; program. MATLAB then runs the script file and saves the results. The files are&lt;br&gt;
&amp;gt; &amp;gt; named according to the index of the parfor command (e.g parfor ii = 1:20). I&lt;br&gt;
&amp;gt; &amp;gt; am using the MATLABPOOL with a local scheduler.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; At each iteration the contents of the files are updated i.e. files are never&lt;br&gt;
&amp;gt; &amp;gt; deleted the naming index remains according to the state of the parfor command&lt;br&gt;
&amp;gt; &amp;gt; and the contents (user-defined script commands) are updated.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; On most occasions the simulations run successfully with no issues. However, on&lt;br&gt;
&amp;gt; &amp;gt; some rare occasions an error is reported relating the failure of fopen as:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; Main_Flight at 70&lt;br&gt;
&amp;gt; &amp;gt; Invalid file identifier.  Use fopen to generate a valid file identifier.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; Optz_v2 at 203&lt;br&gt;
&amp;gt; &amp;gt;     matlabpool local 4 &lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; The code where MATLAB is pointing to is as:&lt;br&gt;
&amp;gt; &amp;gt; script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
&amp;gt; &amp;gt; [fidd] = fopen(script, 'wt');&lt;br&gt;
&amp;gt; &amp;gt; fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&amp;gt; &amp;gt; fclose all&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; That seems to me as thought it should work. The main risk is that some other&lt;br&gt;
&amp;gt; process has the file open for writing - on Windows, you cannot have two&lt;br&gt;
&amp;gt; processes writing to the same file simultaneously, and any second call to fopen&lt;br&gt;
&amp;gt; will fail. A couple of suggestions:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1. Replace your fopen line with something like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [fidd, message] = fopen( script, 'wt' );&lt;br&gt;
&amp;gt; if fidd == -1&lt;br&gt;
&amp;gt;   error( 'Couldn''t write to %s: %s', script, message );&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2. Replace your fclose line with something like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; st = fclose( fidd );&lt;br&gt;
&amp;gt; if st ~= 0&lt;br&gt;
&amp;gt;   error( 'Error code from close: %d, file: %s', st, script );&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hopefully that will help pinpoint which files are failing to open or close, and&lt;br&gt;
&amp;gt; possibly even why.&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;
Hi Edric,&lt;br&gt;
&lt;br&gt;
Thanks for the message. &lt;br&gt;
This could explain why the job also fails on some occasions on a cluster. Will try your suggestions and see how it goes.&lt;br&gt;
&lt;br&gt;
In the meantime, I did not know that a file could be operated on by two processes simulatenosuly. Just to avoid this scenario, seperate script files were created and named in accordance to the index of the parfor command; so that these files were analysed seperately by the proccesses depending on the distribution of 'n' in [parfor ii = 1:n]&lt;br&gt;
&lt;br&gt;
Assuming this is the reason why we have the error (have not tried your suggestions as yet), how do you propose to solve this please?</description>
    </item>
    <item>
      <pubDate>Wed, 24 Jun 2009 15:14:29 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660136</link>
      <author>Edric M Ellis</author>
      <description>&quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; In the meantime, I did not know that a file could be operated on by two&lt;br&gt;
&amp;gt; processes simulatenosuly. Just to avoid this scenario, seperate script files&lt;br&gt;
&amp;gt; were created and named in accordance to the index of the parfor command; so&lt;br&gt;
&amp;gt; that these files were analysed seperately by the proccesses depending on the&lt;br&gt;
&amp;gt; distribution of 'n' in [parfor ii = 1:n]&lt;br&gt;
&lt;br&gt;
Your original code looked to me as though it should work, and basing the&lt;br&gt;
filename on the parfor loop variable is a good approach - so I was trying to&lt;br&gt;
suggest how you might find out why you can't write to the file.&lt;br&gt;
&lt;br&gt;
&amp;gt; Assuming this is the reason why we have the error (have not tried your&lt;br&gt;
&amp;gt; suggestions as yet), how do you propose to solve this please?&lt;br&gt;
&lt;br&gt;
You could use &quot;tempname&quot; to generate a unique filename for each iteration; but&lt;br&gt;
it would probably be good to debug why you are getting the clashes with your&lt;br&gt;
current approach.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Thu, 25 Jun 2009 04:10:18 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660316</link>
      <author>Mr. CFD</author>
      <description>Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytwws71mzoq.fsf@uk-eellis-deb4-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; In the meantime, I did not know that a file could be operated on by two&lt;br&gt;
&amp;gt; &amp;gt; processes simulatenosuly. Just to avoid this scenario, seperate script files&lt;br&gt;
&amp;gt; &amp;gt; were created and named in accordance to the index of the parfor command; so&lt;br&gt;
&amp;gt; &amp;gt; that these files were analysed seperately by the proccesses depending on the&lt;br&gt;
&amp;gt; &amp;gt; distribution of 'n' in [parfor ii = 1:n]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Your original code looked to me as though it should work, and basing the&lt;br&gt;
&amp;gt; filename on the parfor loop variable is a good approach - so I was trying to&lt;br&gt;
&amp;gt; suggest how you might find out why you can't write to the file.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Assuming this is the reason why we have the error (have not tried your&lt;br&gt;
&amp;gt; &amp;gt; suggestions as yet), how do you propose to solve this please?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You could use &quot;tempname&quot; to generate a unique filename for each iteration; but&lt;br&gt;
&amp;gt; it would probably be good to debug why you are getting the clashes with your&lt;br&gt;
&amp;gt; current approach.&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;
Hi Edric, &lt;br&gt;
Added the things you suggested as:&lt;br&gt;
script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
[fidd, message] = fopen(script, 'wt');&lt;br&gt;
if fidd == -1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error( 'Couldn''t write to %s: %s', script, message );    &lt;br&gt;
end&lt;br&gt;
fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&lt;br&gt;
Had the following error appear about an hour into the simulation:&lt;br&gt;
=============================================&lt;br&gt;
??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
Error in ==&amp;gt; Main_Flight at 76&lt;br&gt;
Couldn't write to Airfoil_3.bat: Invalid argument&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; Main_Optz_v2 at 203&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;matlabpool local 4&lt;br&gt;
==============================================&lt;br&gt;
So does this mean that more then one processor was trying to access 'Airfoil_3.bat' in this case? &lt;br&gt;
I really don't know how I can avoid this. The use of parfor is necessary to accelerate computation, but how do we avoid this file conflict?&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Thu, 25 Jun 2009 07:55:47 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660330</link>
      <author>Edric M Ellis</author>
      <description>&quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi Edric, &lt;br&gt;
&amp;gt; Added the things you suggested as:&lt;br&gt;
&amp;gt; script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
&amp;gt; [fidd, message] = fopen(script, 'wt');&lt;br&gt;
&amp;gt; if fidd == -1&lt;br&gt;
&amp;gt;     error( 'Couldn''t write to %s: %s', script, message );    &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Had the following error appear about an hour into the simulation:&lt;br&gt;
&amp;gt; =============================================&lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
&amp;gt; Error in ==&amp;gt; Main_Flight at 76&lt;br&gt;
&amp;gt; Couldn't write to Airfoil_3.bat: Invalid argument&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Error in ==&amp;gt; Main_Optz_v2 at 203&lt;br&gt;
&amp;gt;     matlabpool local 4&lt;br&gt;
&amp;gt; ==============================================&lt;br&gt;
&amp;gt; So does this mean that more then one processor was trying to access 'Airfoil_3.bat' in this case? &lt;br&gt;
&amp;gt; I really don't know how I can avoid this. The use of parfor is necessary to&lt;br&gt;
&amp;gt; accelerate computation, but how do we avoid this file conflict?  Thanks&lt;br&gt;
&lt;br&gt;
I don't think that looks like concurrent access. Are you writing the files onto&lt;br&gt;
a network drive somewhere? If so, that could be one possible cause of that error&lt;br&gt;
message. It might be worth trying to use a local disk for the .bat files. It&lt;br&gt;
might just also be worth pausing and trying again on failure to fopen.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Thu, 25 Jun 2009 08:18:01 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660335</link>
      <author>Mr. CFD</author>
      <description>Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytwk530n3wc.fsf@uk-eellis-deb4-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Hi Edric, &lt;br&gt;
&amp;gt; &amp;gt; Added the things you suggested as:&lt;br&gt;
&amp;gt; &amp;gt; script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
&amp;gt; &amp;gt; [fidd, message] = fopen(script, 'wt');&lt;br&gt;
&amp;gt; &amp;gt; if fidd == -1&lt;br&gt;
&amp;gt; &amp;gt;     error( 'Couldn''t write to %s: %s', script, message );    &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Had the following error appear about an hour into the simulation:&lt;br&gt;
&amp;gt; &amp;gt; =============================================&lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; Main_Flight at 76&lt;br&gt;
&amp;gt; &amp;gt; Couldn't write to Airfoil_3.bat: Invalid argument&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; Main_Optz_v2 at 203&lt;br&gt;
&amp;gt; &amp;gt;     matlabpool local 4&lt;br&gt;
&amp;gt; &amp;gt; ==============================================&lt;br&gt;
&amp;gt; &amp;gt; So does this mean that more then one processor was trying to access 'Airfoil_3.bat' in this case? &lt;br&gt;
&amp;gt; &amp;gt; I really don't know how I can avoid this. The use of parfor is necessary to&lt;br&gt;
&amp;gt; &amp;gt; accelerate computation, but how do we avoid this file conflict?  Thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I don't think that looks like concurrent access. Are you writing the files onto&lt;br&gt;
&amp;gt; a network drive somewhere? If so, that could be one possible cause of that error&lt;br&gt;
&amp;gt; message. It might be worth trying to use a local disk for the .bat files. It&lt;br&gt;
&amp;gt; might just also be worth pausing and trying again on failure to fopen.&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;
Hi Edric,&lt;br&gt;
All files are created and saved in the working directory where the original code is launched from (c:\ drive). So is this suggesting that more then one processor is trying to access a single .bat file, which may already be open? &lt;br&gt;
&amp;nbsp;&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Fri, 26 Jun 2009 07:57:40 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#660629</link>
      <author>Edric M Ellis</author>
      <description>&quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Edric M Ellis &amp;lt;eellis@mathworks.com&amp;gt; wrote in message &amp;lt;ytwk530n3wc.fsf@uk-eellis-deb4-64.mathworks.co.uk&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; &quot;Mr. CFD&quot; &amp;lt;s2108860@student.rmit.edu.au&amp;gt; writes:&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Hi Edric, &lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Added the things you suggested as:&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; script = [mesh_prefix, int2str(ii),'.bat'];&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; [fidd, message] = fopen(script, 'wt');&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; if fidd == -1&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;     error( 'Couldn''t write to %s: %s', script, message );    &lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Had the following error appear about an hour into the simulation:&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; =============================================&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; ??? Error using ==&amp;gt; parallel_function at 587&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Error in ==&amp;gt; Main_Flight at 76&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Couldn't write to Airfoil_3.bat: Invalid argument&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; Error in ==&amp;gt; Main_Optz_v2 at 203&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;     matlabpool local 4&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; ==============================================&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; So does this mean that more then one processor was trying to access 'Airfoil_3.bat' in this case? &lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; I really don't know how I can avoid this. The use of parfor is necessary to&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; accelerate computation, but how do we avoid this file conflict?  Thanks&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; I don't think that looks like concurrent access. Are you writing the files onto&lt;br&gt;
&amp;gt;&amp;gt; a network drive somewhere? If so, that could be one possible cause of that error&lt;br&gt;
&amp;gt;&amp;gt; message. It might be worth trying to use a local disk for the .bat files. It&lt;br&gt;
&amp;gt;&amp;gt; might just also be worth pausing and trying again on failure to fopen.&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Cheers,&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Edric.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Hi Edric, All files are created and saved in the working directory where the&lt;br&gt;
&amp;gt; original code is launched from (c:\ drive). So is this suggesting that more&lt;br&gt;
&amp;gt; then one processor is trying to access a single .bat file, which may already&lt;br&gt;
&amp;gt; be open?&lt;br&gt;
&lt;br&gt;
To be honest, I'm not sure - although it doesn't look like concurrent access&lt;br&gt;
(and the way your code is structured should preclude that in any case). I must&lt;br&gt;
admit I don't know why you're getting that error message from a local disk -&lt;br&gt;
it's just about conceivable that you could get that message with a failed&lt;br&gt;
connection to a network drive, but it shouldn't really apply to C:\. Perhaps you&lt;br&gt;
could try something like this:&lt;br&gt;
&lt;br&gt;
fh = -1; numTries = 0;&lt;br&gt;
while fh == -1 &amp;&amp; numTries &amp;lt; 5&lt;br&gt;
&amp;nbsp;&amp;nbsp;[fh, message] = fopen( script, 'wt' );&lt;br&gt;
&amp;nbsp;&amp;nbsp;numTries = numTries + 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;if fh == -1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% failure - print a warning, wait&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pause(1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;warning( 'Failed to open %s (%s), will try again', script, message );&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
if fh == -1&lt;br&gt;
&amp;nbsp;&amp;nbsp;error( 'Failed to open file even with retries' );&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
(which is, of course, ugly and should be unncessary...)&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
&lt;br&gt;
Edric.</description>
    </item>
    <item>
      <pubDate>Fri, 17 Sep 2010 02:55:09 -0400</pubDate>
      <title>Re: parfor: fopen Issues</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254523#780180</link>
      <author>Ian </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
-The issue is several processes are performing I/O on the same file.&lt;br&gt;
-The solution is dicussed here:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559&quot;&gt;http://www.mathworks.com/matlabcentral/newsreader/view_thread/250559&lt;/a&gt;&lt;br&gt;
and suggested added feature to MATLAB:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.cn/matlabcentral/newsreader/view_thread/291583#779525&quot;&gt;http://www.mathworks.cn/matlabcentral/newsreader/view_thread/291583#779525&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
-In particular; &lt;br&gt;
-Use the memory location the process is using to name a directory (I call a workspace) and perform all your calculations for that process there.  OR&lt;br&gt;
-Rename the file with the extension of the memory location. (or similar).&lt;br&gt;
&lt;br&gt;
-To obtain the memory address being used by the instance of MATLAB.  Run:&lt;br&gt;
Memory_Addresss = system_dependent('getpid');&lt;br&gt;
-The output will be a number such as:  2260.&lt;br&gt;
&lt;br&gt;
kind regards,&lt;br&gt;
Ian Gregory, Sydney.</description>
    </item>
  </channel>
</rss>

