Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: parfor: keep outputs with same output filename
Replies: 12   Last Post: Aug 1, 2013 2:35 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,945
Registered: 12/7/04
Re: parfor: keep outputs with same output filename
Posted: Jul 24, 2012 9:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

<mike23liu@gmail.com> wrote in message
> Hi,
> Thank you all.
> I've modified the section to
> [fid1,msg]=fopen('inputpar.dat','wt'); % be read by Console2.exe
> if fid1==-1
> error(msg)
> end
> fprintf(fid1,'%2d\n',i);
> after parfor and re-run it, then also have the same message:

If you run this code BEFORE you enter the PARFOR loop, then when fid1 gets
passed to the workers it's just a double scalar. They didn't open the file
themselves, so they don't treat it as a file identifier. It's like you SAVEd
the identifier to a MAT-file, restarted MATLAB, then LOADed the MAT-file.

If you run this code INSIDE your PARFOR loop, you're in a race condition
situation. Don't do this.

As I said, I think your best options are to have each iteration write to a
file with a unique, iteration dependent name and either store the values
from that file into a variable inside the PARFOR loop or combine them into
one file AFTER the PARFOR loop is done.


Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.