Stop Simulink simulation launched programatically on a machine without display

1 回表示 (過去 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 Center および File ExchangeSimulink Environment Customization についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by