From: almmond on
Hi, friends
Recently, I need to run a time-consuming fortran executable program (half an hour for one time running) thousands of times to get a desired results, so I turned myself to matlab since I've noticed that there is parallel computing feature in matlab. However, I meet a strange situation in my simulation. Here is the parfor loop I've written:

matlabpool(4);
parfor (i=1:4)
system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ', strcat('H:\Mat_cod\folder', num2str(i), '\rundata.txt')]); % Parallel run 4 applications
end
matlabpool close;

Here, "ssvv.exe" is my fortran executable program, it needs "rundata.txt" to provide the required parameter inputs; and here I want to run 4 applications at the same time using 4 workers, 2 from my machine and the other 2 from another machine. The running can start successfully as I can see from the matlab command that 4 applications are running sinchronously, however, the problem comes when the applications are at its end and the prompts appeared on the command line said " Fortran Pause - Enter command<CR> or <CR> to continue." So I pressed the enter button, but the matlab is always busy and can't jump out of the parfor loop.

I'm a beginner in using parallel computing toolbox in matlab, I'm sure there is something that I didn't configure very well that lead to the above problem. Please help me, if you know how to solve it, I would really appreciate it!!!!!!!!!!!!!
From: Edric M Ellis on
"almmond " <allmmond(a)hotmail.com> writes:

> Recently, I need to run a time-consuming fortran executable program
> (half an hour for one time running) thousands of times to get a
> desired results, so I turned myself to matlab since I've noticed that
> there is parallel computing feature in matlab. However, I meet a
> strange situation in my simulation. Here is the parfor loop I've
> written:
>
> matlabpool(4);
> parfor (i=1:4)
> system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ', strcat('H:\Mat_cod\folder', num2str(i), '\rundata.txt')]); % Parallel run 4 applications
> end
> matlabpool close;
>
> Here, "ssvv.exe" is my fortran executable program, it needs
> "rundata.txt" to provide the required parameter inputs; and here I
> want to run 4 applications at the same time using 4 workers, 2 from my
> machine and the other 2 from another machine. The running can start
> successfully as I can see from the matlab command that 4 applications
> are running sinchronously, however, the problem comes when the
> applications are at its end and the prompts appeared on the command
> line said " Fortran Pause - Enter command<CR> or <CR> to continue." So
> I pressed the enter button, but the matlab is always busy and can't
> jump out of the parfor loop.

There's no way to send input from the MATLAB command window into stuff
running within a "system" command (in general, we wouldn't know which
process - the desktop, or one of the workers - you were trying to type
at), so you need to modify your system command so that it doesn't prompt
you for input. I'm not sure, but one way might be to do something like
this:

% Build up the original command using sprintf (watch out for backslashes)
cmd = sprintf( 'H:\\Mat_cod\\Program\\ssvv.exe .... ', ... );

% Build a new command which sends dummy input via a pipe to the
% program. You might need to tweak the echo command...
newcmd = ['echo " " | ', cmd]

% Check that it works without prompting outside a PARFOR loop
system( newcmd );

If that fixes things so that your program doesn't prompt for input, it
should work within the PARFOR loop.

Cheers,

Edric.
From: almmond on
Hi, Edric

Wish you have a nice day! Thank you very much for your help!
I've tried just to run system() in the way that you suggested. The fortran exe program can be called successfully, however at the end of its running there is hundreds of fortran pause lines as follows:

Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
Fortran Pause - Enter command<CR> or <CR> to continue.
....

Then, I think it might also not work with parfor loop. :(

Best Wishes!

Almmond











Edric M Ellis <eellis(a)mathworks.com> wrote in message <ytwaasgw096.fsf(a)uk-eellis-deb5-64.mathworks.co.uk>...
>
> There's no way to send input from the MATLAB command window into stuff
> running within a "system" command (in general, we wouldn't know which
> process - the desktop, or one of the workers - you were trying to type
> at), so you need to modify your system command so that it doesn't prompt
> you for input. I'm not sure, but one way might be to do something like
> this:
>
> % Build up the original command using sprintf (watch out for backslashes)
> cmd = sprintf( 'H:\\Mat_cod\\Program\\ssvv.exe .... ', ... );
>
> % Build a new command which sends dummy input via a pipe to the
> % program. You might need to tweak the echo command...
> newcmd = ['echo " " | ', cmd]
>
> % Check that it works without prompting outside a PARFOR loop
> system( newcmd );
>
> If that fixes things so that your program doesn't prompt for input, it
> should work within the PARFOR loop.
>
> Cheers,
>
> Edric.
From: Edric M Ellis on
"almmond " <allmmond(a)hotmail.com> writes:

> Wish you have a nice day! Thank you very much for your help! I've
> tried just to run system() in the way that you suggested. The fortran
> exe program can be called successfully, however at the end of its
> running there is hundreds of fortran pause lines as follows:
>
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> Fortran Pause - Enter command<CR> or <CR> to continue.
> ...
>
> Then, I think it might also not work with parfor loop. :(

Is there a "quit" command or similar that you could inject into the
fortran program? Perhaps your command could be

'echo quit | ssvv.exe ...'

or similar.

Or, perhaps you could modify the FORTRAN program to take a flag to tell
it to quit automatically on completion...

Cheers,

Edric.
From: almmond on
Hi, Edric

I've tried with "quit", or "stop", "end", "continue" ... No one worked. So I guess you are right, I have to ask the program provider to change the code and recompile it to me.

All the best!

Almmond











Edric M Ellis <eellis(a)mathworks.com> wrote in message <ytw4oiogghf.fsf(a)uk-eellis-deb5-64.mathworks.co.uk>...
> Is there a "quit" command or similar that you could inject into the
> fortran program? Perhaps your command could be
>
> 'echo quit | ssvv.exe ...'
>
> or similar.
>
> Or, perhaps you could modify the FORTRAN program to take a flag to tell
> it to quit automatically on completion...
>
> Cheers,
>
> Edric.
 | 
Pages: 1
Prev: Matlab to HDL
Next: Aborting fwrite