Path: news.mathworks.com!not-for-mail
From: Edric M Ellis <eellis@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: parfor: fopen Issues
Date: Fri, 26 Jun 2009 08:57:40 +0100
Organization: The Mathworks, Ltd.
Lines: 67
Message-ID: <ytwfxdnmnpn.fsf@uk-eellis-deb4-64.mathworks.co.uk>
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> <h1utba$1us$1@fred.mathworks.com> <ytwk530n3wc.fsf@uk-eellis-deb4-64.mathworks.co.uk> <h1vbrp$6h5$1@fred.mathworks.com>
NNTP-Posting-Host: uk-eellis-deb4-64.mathworks.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: fred.mathworks.com 1246003060 15965 172.16.27.112 (26 Jun 2009 07:57:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 26 Jun 2009 07:57:40 +0000 (UTC)
X-Face: $Ahg}Iylezql"r1WV1Me5&)ng"a4v%D>==KMs-elCfj"o}$bh-VOt7lVXgLWsC?9mZ`mINT
 G6PDvca;nrgs$lfcr0l1ew'N]>nXKl}m|Zpg>,6*gLp~-N0N2*+b.iwv=u>@R$L4SEG&NYUU;lSR@u
 IHphdAy
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)
Cancel-Lock: sha1:eA+rSu/ygda0Qb/EJEN2HxddRC0=
Xref: news.mathworks.com comp.soft-sys.matlab:550801


"Mr. CFD" <s2108860@student.rmit.edu.au> writes:

> Edric M Ellis <eellis@mathworks.com> wrote in message <ytwk530n3wc.fsf@uk-eellis-deb4-64.mathworks.co.uk>...
>> "Mr. CFD" <s2108860@student.rmit.edu.au> writes:
>> 
>> > 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
>> 
>> I don't think that looks like concurrent access. Are you writing the files onto
>> a network drive somewhere? If so, that could be one possible cause of that error
>> message. It might be worth trying to use a local disk for the .bat files. It
>> might just also be worth pausing and trying again on failure to fopen.
>> 
>> Cheers,
>> 
>> Edric.
>
> Hi Edric, 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?

To be honest, I'm not sure - although it doesn't look like concurrent access
(and the way your code is structured should preclude that in any case). I must
admit I don't know why you're getting that error message from a local disk -
it's just about conceivable that you could get that message with a failed
connection to a network drive, but it shouldn't really apply to C:\. Perhaps you
could try something like this:

fh = -1; numTries = 0;
while fh == -1 && numTries < 5
  [fh, message] = fopen( script, 'wt' );
  numTries = numTries + 1;
  if fh == -1
    % failure - print a warning, wait
    pause(1);
    warning( 'Failed to open %s (%s), will try again', script, message );
  end
end
if fh == -1
  error( 'Failed to open file even with retries' );
end

(which is, of course, ugly and should be unncessary...)

Cheers,

Edric.