Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: parfor: fopen Issues
Date: Thu, 25 Jun 2009 04:10:18 +0000 (UTC)
Organization: RMIT
Lines: 45
Message-ID: <h1utba$1us$1@fred.mathworks.com>
References: <h1t155$jbg$1@fred.mathworks.com> <ytw1vp9omj1.fsf@uk-eellis-deb4-64.mathworks.co.uk> <h1teke$q6c$1@fred.mathworks.com> <ytwws71mzoq.fsf@uk-eellis-deb4-64.mathworks.co.uk>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245903018 2012 172.30.248.38 (25 Jun 2009 04:10:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 25 Jun 2009 04:10:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1372013
Xref: news.mathworks.com comp.soft-sys.matlab:550485


Edric M Ellis <eellis@mathworks.com> wrote in message <ytwws71mzoq.fsf@uk-eellis-deb4-64.mathworks.co.uk>...
> "Mr. CFD" <s2108860@student.rmit.edu.au> writes:
> 
> > 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]
> 
> Your original code looked to me as though it should work, and basing the
> filename on the parfor loop variable is a good approach - so I was trying to
> suggest how you might find out why you can't write to the file.
> 
> > 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?
> 
> You could use "tempname" to generate a unique filename for each iteration; but
> it would probably be good to debug why you are getting the clashes with your
> current approach.
> 
> Cheers,
> 
> Edric.

Hi Edric, 
Added the things you suggested as:
script = [mesh_prefix, int2str(ii),'.bat'];
[fidd, message] = fopen(script, 'wt');
if fidd == -1
    error( 'Couldn''t write to %s: %s', script, message );    
end
fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');

Had the following error appear about an hour into the simulation:
=============================================
??? Error using ==> parallel_function at 587
Error in ==> Main_Flight at 76
Couldn't write to Airfoil_3.bat: Invalid argument

Error in ==> Main_Optz_v2 at 203
    matlabpool local 4
==============================================
So does this mean that more then one processor was trying to access 'Airfoil_3.bat' in this case? 
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?
Thanks