Script Iterative or Batch Simulations Using Fast Restart
You can use fast restart to speed up programmatic simulation workflows and MATLAB® scripts you write to run simulations. Fast restart saves time by compiling the model only once, for the first simulation you run after enabling fast restart. As a result, you can only modify parameters and settings in the model that do not require recompiling the model. For more information, see Get Started with Fast Restart.
Fast restart can speed up programmatic and scripted simulations you run:
Iteratively, one at a time, using the
simfunction or theSimulationobjectAs a batch or in parallel using an array of
Simulink.SimulationInputobjects and thesim,parsim, orbatchsimfunction
How you use fast restart in scripts and programmatic simulations depends on which of these workflows you use.
Script Individual, Iterative Simulations Using Fast Restart
To use fast restart for individual, iterative simulations you run one at a time,
use the FastRestart parameter. The FastRestart
parameter corresponds to the Fast Restart option in the
Simulink® Toolstrip. Enabling fast restart using the Simulink
Editor enables the FastRestart parameter, and enabling
the FastRestart parameter using the
set_param function enables the Fast
Restart option in the Simulink Toolstrip.
You can enable fast restart for individual, iterative simulations any of these ways:
Use the
setModelParameterfunction to set theFastRestartparameter on aSimulationInputobject or aSimulationobject.s = setModelParameter(s,FastRestart="on");Specify the
FastRestartparameter as input to thesimfunction. For example, when you specify the name of the model as the first input argument for thesimfunction, you can specify theFastRestartparameter as a name-value argument.mdl = "MyModel"; out = sim(mdl,FastRestart="on");
Enable the
FastRestartparameter in the model using theset_paramfunction.mdl = "MyModel"; set_param(mdl,FastRestart="on");
In the Simulink Toolstrip, on the Simulation tab, click Fast Restart.
No matter how you enable fast restart for individual, iterative simulations, once you enable fast restart, the model remains compiled and initialized in fast restart after each simulation you run until you exit or disable fast restart. When you finish running the individual, iterative simulations, use either of these options to exit fast restart:
Disable the
FastRestartparameter in the model using theset_paramfunction.mdl = "MyModel"; set_param(mdl,FastRestart="off");
In the Simulink Toolstrip, on the Simulation tab, click Fast Restart.
Tip
When you run simulations using the Simulation object, you can
exit or disable fast restart by calling the terminate function.
Script Batch and Parallel Simulations Using Fast Restart
To use fast restart when you run multiple simulations as a batch using an array of
SimulationInput objects and the sim,
parsim, or batchsim functions, specify
the UseFastRestart name-value argument as "on"
in the call to sim, parsim, or
batchsim. For example, this command enables fast restart to
run the batch of simulations represented by the array of
SimulationInput objects simin.
out = sim(simin,UseFastRestart="on");When you run fast restart simulations in parallel:
The software compiles the model once per simulation worker. Fast restart saves time in parallel simulations when each worker runs more than one simulation.
The last simulation on each worker terminates. After all the simulations complete, the model is no longer initialized in fast restart, and the simulation status is
inactive.
The FastRestart parameter does not apply for multiple
simulation workflows. The UseFastRestart parameter has no effect
on a single simulation run using a scalar SimulationInput
object.
Script Rapid Accelerator Simulations Using Fast Restart
Since R2025a
You can use fast restart to speed up programmatic and scripted rapid accelerator simulations. In rapid accelerator simulations, fast restart saves time by loading the rapid accelerator executable only once, for the first rapid accelerator simulation you run after enabling fast restart. The rapid accelerator executable remains loaded for subsequent simulations you run while initialized in fast restart. Fast restart is supported in rapid accelerator mode for both:
Individual, iterative simulations you run using the
simfunction or theSimulationobjectMultiple simulations you run as a batch using an array of
Simulink.SimulationInputobjects and thesim,parsim, orbatchsimfunction
Because the software does not close the rapid accelerator executable at the end of simulation, the software does not check whether the rapid accelerator executable is up to date and never rebuilds the rapid accelerator executable while fast restart is enabled.
To enable and disable fast restart for rapid accelerator simulations, follow the
same steps described for simulations run using normal or accelerator mode. If the
model is not configured to simulate in rapid accelerator mode, you can configure the
simulation to run in rapid accelerator mode by using the setModelParameter function or
specifying the simulation mode as input to the sim
function.
To run individual, iterative fast restart simulations in rapid accelerator mode, use one of these approaches:
Set the
SimulationModeandFastRestartparameters on a scalarSimulationInputobject or aSimulationobject using thesetModelParameterfunction.s = setModelParameter(s,FastRestart="on"); s = setModelParameter(s,SimulationMode="rapid-accelerator");
To run simulations when you use a scalar
SimulationInputobject, use thesimfunction.out = sim(s);
To run simulations when you use a
Simulationobject, use thestart,step, andresumefunctions.fs = step(s,PauseTime=t);
Configure the model using the
set_paramfunction before running simulations by calling thesimfunction.set_param(mdl,SimulationMode="rapid-accelerator") set_param(mdl,FastRestart="on") out = sim(mdl);
Configure the parameters in the call to the
simfunction using name-value arguments.out = sim(mdl,SimulationMode="rapid-accelerator",FastRestart="on");
To run multiple simulations in rapid accelerator mode, specify the
SimulationMode parameter as
rapid-accelerator on each Simulink.SimulationInput object by
using the setModelParameter function.
simin(1:n) = Simulink.SimulationInput(mdl); for 1:n simin(n) = setModelParameter(simin, SimulationMode="rapid-accelerator"; end
To enable fast restart, specify the UseFastRestart name-value
argument for the parsim, batchsim, or
sim function.
out = parsim(simin,UseFastRestart="on");When you use fast restart to run batch and parallel rapid accelerator simulations:
The software loads the rapid accelerator executable once per simulation worker. Fast restart saves time in parallel simulations when each worker runs more than one simulation.
The software closes the rapid accelerator executable once per simulation worker, as part of terminating the last simulation that worker runs. After all the simulations complete, the model is no longer initialized in fast restart, and the simulation status is
inactive.
Note
Fast restart is supported for only programmatic and scripted rapid accelerator
simulations. Fast restart is not supported for rapid accelerator simulations run
from a user interface, such as the Simulink Editor, or for
programmatic workflows that use the set_param function with
the SimulationCommand name-value argument to start a
simulation.
Fast Restart Scripting Workflow Summary
The table summarizes how to use fast restart for each programmatic simulation workflow.
| Simulation Workflow | How to Enable Fast Restart | Model Status After Simulation | How to Exit Fast Restart |
|---|---|---|---|
Run individual
simulations using | Set the mdl = "MyModel"; sm = simulation(mdl); sm = setModelParameter(sm,FastRestart="on"); start(sm) |
| Terminate the simulation using the terminate(sm) |
Run individual
simulations using the | Set the mdl = "MyModel"; simin = Simulink.SimulationInput(mdl); simin = setModelParameter(simin,FastRestart="on"); out = sim(simin); |
| Set the set_param(mdl,FastRestart="off") |
Run individual simulations using the sim
function | Specify the mdl = "MyModel"; out = sim(mdl,FastRestart="on"); | ||
Run multiple simulations using an array of
SimulationInput objects | Use the mdl = "MyModel": simin(1:10) = Simulink.SimulationInput(mdl); % Configure each simulation using % SimulationInput object out = sim(simin,UseFastRestart="on"); | The last simulation terminates and disables fast restart. Because the last simulation terminates, the model is no longer initialized in fast restart.
| Not applicable. The last simulation terminates and disables fast restart. |
See Also
Objects
Functions
setModelParameter|sim|parsim|batchsim|terminate