I. Amon
I. Amon

Reputation: 184

Abort execution of parsim

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:

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.

Upvotes: 1

Views: 838

Answers (1)

rkumar310
rkumar310

Reputation: 78

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();

Upvotes: 1

Related Questions