Speed Up Your Simulations with Rapid Accelerator Mode

By Guy Rouleau, MathWorks

If you are doing Monte Carlo simulation or system optimization on your Simulink model, you’ll need to run multiple simulations while varying model parameters. How do you get each simulation to run as quickly as possible?

In Simulink®, there are three desktop simulation modes: Normal, Accelerator, and Rapid Accelerator. For most models, Accelerator is faster than Normal, and Rapid Accelerator is faster still. Rapid Accelerator mode speeds up simulation by generating an executable for your model. The exact speedup varies depending on the model, but Rapid Accelerator can be more than 10 times faster than Normal mode.

Using Rapid Accelerator involves trading off flexibility and performance—Rapid Accelerator does not support the debugger or profiler, and it only works when the entire model is capable of generating C code—but if your goal is efficient batch and Monte Carlo simulations, then Rapid Accelerator is your best option.

This article shows how to set up your batch simulation script to get the maximum performance out of Rapid Accelerator.

Setting Up the Model—A Bouncing Ball Example

Each time you run a model or use the sim command, Simulink checks for changes in the model. Depending on the size of the model, this initialization phase can be time-consuming. In Rapid Accelerator mode, if you know that your model did not change structurally, you can skip this step by simply turning off the RapidAcceleratorUpToDateCheck option. For any model, no matter how large, this reduces initialization time to zero.

For illustration, we’ll use a simple model of a bouncing ball (Figure 1). In this model, a ball drops from a certain height onto a hard surface. The position and velocity of the ball are measured at each step of the simulation. The parameters are gravity, the ball’s initial height and velocity, and the coefficient of restitution (the bounciness of the ball).

Figure 1. Bouncing ball model.

Suppose we want to vary the coefficient of restitution, specified
as k
in the block dialog. To tune the value of k, we need to define it as a Simulink.Parameter object1:

The
buildRapidAcceleratorTarget
function
returns a structure containing all the information relevant to tunable parameters in the model. Using this structure, we can create an array of runtime parameter structures for all the values we want to run:

We are now ready to simulate the model multiple times in Rapid Accelerator mode using the sim command with the RapidAcceleratorUpToDateCheck and RapidAcceleratorParameterSets parameters:

for i = 1:length(k_values)
simout(i) = sim(mdl,'SimulationMode','rapid',...'RapidAcceleratorUpToDateCheck','off', ...'RapidAcceleratorParameterSets',paramSet(i));
end

Using this workflow with parallel computing is straightforward. All you do is
replace
for
with
parfor
in
the above code.

Rapid Accelerator mode is just one way to speed up simulations. You can also use the Performance Advisor, which lets you analyze your model for simulation bottlenecks, or Fast Restart, which lets you perform iterative simulations without recompiling the model or terminating the simulation each time.

1 If you are using Simulink R2015a or earlier, you also need to turn on the “Inline Parameters” option in the Configuration Parameters.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.