Stop Simulink simulation launched programatically on a machine without display
8 views (last 30 days)
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 !