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: 1   Last Post: Jul 23, 2012 10:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Edric Ellis

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

Mike <SulfateIon@gmail.com> writes:

> thank you for your info.
> To be more clear, I simply my question with follows:
> 1) I create a fortran file with following:
>
> program main
> integer:: i
> open(10,file='inputpar.dat',status='old')
> read(10,*) i
> write(30,*) i
> write(*,*) 'fortran main :', i
> end
>
> I compile it within the project and have Console2.exe in 'D:\temp\Console2\Console2\Debug'.
>
> 2) in matlab, I have following:
> fid2=fopen('test.dat','a'); % this file should be run parallel'
> matlabpool open local 3
> parfor i=1:100
> fid1=fopen('inputpar.dat','w'); % be read by Console2.exe
> fprintf(fid1,'%2d\n',i);
> fclose(fid1);
> dos('Console2.exe<inputpar.dat');
> out=importdata('fort.30')
> fprintf(fid2,'%2d\n',out);
> end
> matlabpool close
> s=load('test.dat')


I'm not 100% sure I understand the FORTRAN code, but the MATLAB code is
definitely trying to have each worker write to the same 'inputpar.dat'
file. This is bound to fail. One option would be to make the PARFOR loop
choose a filename based on the loop index, like this:

parfor i=1:100
fname = sprintf('inputpar_%d.dat', i);
fid1 = fopen(fname, 'w');
if fid == -1, error('Could not write to: %s', fname); end
...
end

I suspect you'll also need to modify your FORTRAN code to do something
similar.

Cheers,

Edric.



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.