Stop Simulink simulation launched programatically on a machine without display

조회 수: 4 (최근 30일)
Felix Arnoux
Felix Arnoux 2021년 4월 13일
편집: Mario Malic 2021년 4월 13일
Hello,
I launch Simulink simulations programatically from another program, on HPC machines (without display).
To do that, I use the Matlab Engine via the C++ API and after some setup I use the sim() command in a C++ separate thread to run the simulation itself. This thread will wait for the end of the simulation, retreive messages and catch exceptions if any.
When the user clicks on a button in my program, I want to stop the simulation.
However, I have no "clean" way to stop the Simulink run. The documentation states that when using sim() you have to use Ctrl+C to stop a simulation.
Moreover, I can't use the set_param() command to run the simulation, it is forbidden to use it on a machine without display (why ?).
Therefore I came out with some workarounds:
  • attach a listener on a Simulink block to check periodically if a stop flag has been defined in the Matlab workspace (can we interact with the workspace from another C++ thread ?)
  • send a SIGTERM signal to Matlab (what is Matlab state after that ?)
  • add a S-function to the simulink model (very intrusive !)
  • use the C API instead of the C++ one with set_param() to run the simulation (seems to work, even without display ?)
Well, as you can see, I need some help to find the right solution...
Any advice is most welcome !
  댓글 수: 1
Mario Malic
Mario Malic 2021년 4월 13일
편집: Mario Malic 2021년 4월 13일
Just a note, I am not super familiar with the Simulink.
When you start your sim with separate thread is the MATLAB instance busy, or you are able to interact with it? It's even questionable whether your Simulink can see MATLAB when ran on separate thread?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by