Order Matlab not to continue until the external run is completed
Show older comments
Dear all,
I am runing Ansys Fluent in Matlab by the system command and using journal file. I want Matlab to wait until the Fluent run is finished and the results are ready then go to other sections and manipulate data. However, when I run the code it just run fluent and go to the other sections afterward without hesitation. how I can define for Matlab wait until the run is completed then go to the other sections?
BR
4 Comments
dpb
on 6 Jul 2022
Don't tell us; show us...the exact command syntax you are using...and OS
Walter Roberson
on 7 Jul 2022
Perhaps use the -gr option to turn off graphics? https://www.afs.enea.it/project/neptunius/docs/fluent/html/ug/node15.htm
zeinab seifi
on 7 Jul 2022
zeinab seifi
on 8 Jul 2022
Accepted Answer
More Answers (1)
Karim
on 7 Jul 2022
Asuming you are using windows. You can can just add the
[~,~]
as output to the system command, this way matlab will wait until the process is finished. The last of the two outputs would normally gather the command output.
I'm not familiair with the calling fluent from matlab. But in the case of nastran it looks like this:
NastranExec = "C:\Program Files\NXNASTRAN\bin\nastran.exe";
InputFile = "C:\Data\TestFile.bdf";
[~,~] = system([NastranExec,' "',InputFile,'" out="C:\MyRes\" sdir="C:\ScratchDir\" scr=yes old=yes']);
5 Comments
zeinab seifi
on 7 Jul 2022
Karim
on 7 Jul 2022
hmmm in the case of nastran matlab does wait for the compuation to finish (no matter how long it takes)
Note that the nastran excectuable is the main process that actuall performs the computation, i.e. nastran doesn't call a subprocess. Does fluent call another program for the actual simulation?
zeinab seifi
on 7 Jul 2022
Walter Roberson
on 7 Jul 2022
When you call system(), whether you use any outputs for the call or not, system() follows these rules:
- if the command ends in & then the process is run in the background and system() returns as soon as the process starts. This is handled by MATLAB examining the command, regardless of what shell is being used
- if you are using MacOS or Linux, then some command forms result in the process running in the background. For example system('ls & > ~/MyOutput.txt') would (probably) not have the & detected by MATLAB itself (since the & is not at the end) but Unix-type shells would interpret it as a background request
- otherwise, MATLAB waits for the command itself to finish. However... if the command causes a graphic program to start, then that graphic program is probably going to be a different process than the command itself, and the command itself would return immediately after starting the graphic program. For example, if you were to start Microsoft Word, then that would launch the graphic user interface and return, and system() would believe that the command is finished (because in a sense it is finished.) It would be a technical challenge to program system() to be able to detect such cases and not return until all the spawned processes were finished.
That last point is why I was talking about the -gr option: if a graphic window is permitted to start, then the graphic window would likely be disconnected from the command that started it, but if you tell the ANSYS not to start graphics then it should operate in "batch mode" and wait for the journal to finish.
zeinab seifi
on 8 Jul 2022
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!