Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: parfor: keep outputs with same output filename
Posted:
Jul 23, 2012 10:10 AM
|
|
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.
|
|
|
|