Main Content

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 sim function or the Simulation object

  • As a batch or in parallel using an array of Simulink.SimulationInput objects and the sim, parsim, or batchsim function

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 setModelParameter function to set the FastRestart parameter on a SimulationInput object or a Simulation object.

    s = setModelParameter(s,FastRestart="on");
  • Specify the FastRestart parameter as input to the sim function. For example, when you specify the name of the model as the first input argument for the sim function, you can specify the FastRestart parameter as a name-value argument.

    mdl = "MyModel";
    out = sim(mdl,FastRestart="on");
  • Enable the FastRestart parameter in the model using the set_param function.

    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 FastRestart parameter in the model using the set_param function.

    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 sim function or the Simulation object

  • Multiple simulations you run as a batch using an array of Simulink.SimulationInput objects and the sim, parsim, or batchsim function

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 SimulationMode and FastRestart parameters on a scalar SimulationInput object or a Simulation object using the setModelParameter function.

    s = setModelParameter(s,FastRestart="on");
    s = setModelParameter(s,SimulationMode="rapid-accelerator");

    To run simulations when you use a scalar SimulationInput object, use the sim function.

    out = sim(s);

    To run simulations when you use a Simulation object, use the start, step, and resume functions.

    fs = step(s,PauseTime=t);
  • Configure the model using the set_param function before running simulations by calling the sim function.

    set_param(mdl,SimulationMode="rapid-accelerator")
    set_param(mdl,FastRestart="on")
    out = sim(mdl);
  • Configure the parameters in the call to the sim function 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 WorkflowHow to Enable Fast RestartModel Status After SimulationHow to Exit Fast Restart

Run individual simulations using Simulation object (since R2024a)

Set the FastRestart parameter on the Simulation object using the setModelParameter function.

mdl = "MyModel";
sm = simulation(mdl);
sm = setModelParameter(sm,FastRestart="on");
start(sm)

  • Normal and accelerator mode simulations — Compiled and initialized in fast restart. Simulation status is initialized.

  • Rapid accelerator simulations — Initialized in fast restart with the rapid accelerator executable still loaded in memory. (since R2025a)

Terminate the simulation using the terminate function.

terminate(sm)

Run individual simulations using the sim function and scalar SimulationInput objects (since R2024a)

Set the FastRestart parameter on the SimulationInput object using the setModelParameter function.

mdl = "MyModel";
simin = Simulink.SimulationInput(mdl);
simin = setModelParameter(simin,FastRestart="on");
out = sim(simin);

  • Normal and accelerator mode simulations — Compiled and initialized in fast restart.

  • Rapid accelerator simulations — Initialized in fast restart with the rapid accelerator executable still loaded in memory. (since R2025a)

Set the FastRestart parameter for the model to "off".

set_param(mdl,FastRestart="off")
Run individual simulations using the sim function

Specify the FastRestart parameter as a name-value argument.

mdl = "MyModel";
out = sim(mdl,FastRestart="on");
Run multiple simulations using an array of SimulationInput objects

Use the UseFastRestart name-value argument for the sim, parsim, or batchsim function.

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.

  • Normal and accelerator mode simulations — Model is not compiled.

  • Rapid accelerator simulations — The rapid accelerator executable is not loaded in memory. (since R2025a)

Not applicable. The last simulation terminates and disables fast restart.

See Also

Objects

Functions

Topics