1

For the use case of being able to abort parallel simulations with a MATLAB GUI, I would like to stop all scheduled simulations after the user pressed the Stop button. All simulations are submitted at once using the parsim command, hence something like a callback to my GUI variables (App Designer) would be the most preferable solution.

Approaches I have considered but were not exactly providing a desirable solution:

  • The Simulation Manager provides the functionality to close simulations using its own interface. If I only had the code its Stop button executes...
  • parsim uses the Simulink.SimulationInput class as input to run simulations, allowing to modify the preSimFcn at the beginning of each simulation. I have not found a way to "skip" the simulation at its initialization phase apart from intentionally throwing an error so far.

Thank you for your help!


Update 1: Using the preSimFcn to set the the termination time equal to the start time drastically reduces simulation time. But since the first step still is computed there has to be a better solution.

simin = simin.setModelParameter('StopTime',get_param(mdl,'StartTime'))

Update 2: Intentionally throwing an error executing the preSimFcn, for example by setting it to

simin = simin.setModelParameter('SimulationCommand','stop')

provides the shortest termination times for me so far. Though, it requires catching and identifying the error in the ErrorMessageof the Simulink.SimulationOutput object. As this is exactly the "ugly" implementation I wanted to avoid, the issue is still active.

I. Amon
  • 174
  • 11

1 Answers1

1

If you are using 17b or later, parsim provides an option to 'RunInBackground'. It returns an array of Future objects.

F = parsim(in, 'RunInBackground', 'on')

Please note that is only available for parallel simulations. The Simulink.Simulation.Future object F provides a cancel method which will terminate the simulation. You can use the fetchOutputs methods to fetch the output from the simulation.

F.cancel();
rkumar310
  • 78
  • 6