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 ]
Mike

Posts: 336
Registered: 4/17/07
Re: parfor: keep outputs with same output filename
Posted: Aug 1, 2013 2:35 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi

I encounter this problem again and review your suggestion. Allow me to reiterate the problem.
What I want to do is to run a fortran .exe file by using matlab-created input parameter file. And I'd like to run it thousand times and be fast.
Since that fortran .exe read and write both fixed filenames:'inputpar.dat' and 'fort.30' (this fortran program causes me headache so I don't want to compile/link it again), I can't create various input filenames and also expect have various output filenames. Hence, I decide to do it by creating various directory, and creating input file and output file in that directory. At last, collect all output files (fort.30). Although it works, it tends to be lengthy. I am wondering if this can be improve or better thought?

Here is:
% run FORTRAN program 'Console2.exe' with input parameter file 'inputpar.dat'
% created by matlab. And run many times parallel. Console2.exe will always read
% 'inputpar.dat' and write 'fort.30'
nimg=100;
outArr=zeros(nimg,1);
matlabpool open local 3
t = cputime;
parfor i=1:nimg
% make several dir
dirname=['a' num2str(i)];
mkdir(dirname);
% cd every dir and create input parameter file
oldfolder=cd(dirname);
% input parameter file to be run by 'Console2.exe'
[fid1,msg]=fopen('inputpar.dat','w'); % be read by Console2.exe
fprintf(fid1,'%2d\n',i);
fclose(fid1);
% cd dir and run fortran .exe file and save in a matrix
% run FORTRAN program 'Console2.exe' with the above file
dos('D:\temp\Console2\Console2\Debug\Console2.exe<inputpar.dat');
% import output file 'fort.30' of 'Console2.exe'
out=importdata('fort.30');
outArr(i)=out;
cd(oldfolder);
% remove dir
dos(['rmdir/s/q ' dirname]);
end
matlabpool close
e = cputime-t;
fprintf('cputime: %f \n',e);
save('z.mat','outArr');



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

[Privacy Policy] [Terms of Use]

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