Guy on Simulink

Simulink & Model-Based Design

Speeding up Initialization for Accelerator Mode

Some time ago, I wrote a post about Getting the most out of Rapid Accelerator mode. That post describes how to use the RapidAcceleratorUpToDateCheck = 'off' option to skip the initialization time.

Unfortunately, not all models can run in Rapid Accelerator mode. In order to generate the stand-alone executable required by the Rapid Accelerator mode, the model must respect certain criteria.

When your model is not compatible with Rapid Accelerator, it is always worth checking if Accelerator mode can speedup your simulation time. However Accelerator Mode does not have an option equivalent to RapidAcceleratorUpToDateCheck = 'off', and consequently every time the simulation starts, Simulink verifies if the model changed.

Today I want to share a trick to skip the initialization in accelerator mode.

The Problem

To see the effect of initialization time properly, we need a large model. So I put together a model made of almost 40,000 blocks:

Counting the number of blocks using sldiagnostics

This model simulates almost ten times faster in Accelerator mode compared to Normal mode. The accelerator target takes almost 30 minutes to generate code, but once the code has been generated, it takes about 1 minute to complete one simulation.

However, if we simulate for zero second, we see that just the time to initialize and terminate the model takes about 17 seconds. In other words, a quarter of the time needed to run this model is spent during the initialization.

Simulating the moel in Accelerator mode

Let see how we can improve that.

The Solution: Accelerated Model Reference

As you are probably aware, model reference allows you to run a model in accelerator mode within another model. I created a model with only one Model block and referenced my large model.

Counting blocks using sldiagnostics

When doing the same test as before, we get:

Simulating the model as accelerated reference model

Oups... the initialization time increased to 32 seconds. In addition to compiling the model, Simulink needs to do some additional work related to model referencing. But don't worry, the story is not over yet!

By default, new models have the Rebuild option set to If any changes detected. In this mode, the structural checksum of the referenced model is always computed to ensure that the model has not been modified since the accelerator mex-file has been generated.

Let's open the Model Referencing section of the Model Configuration and set the Rebuild option to If any changes in known dependencies detected.

Rebuild Option

And run our test to measure the initialization time:

Model Initialization timing

In this case, Simulink only verifies that the model.slx file and its dependencies have not changed since the MEX file was generated. If this is the case, the initialization of the referenced model is skipped entirely.

Now it's your turn

Are you taking advantage of accelerated model reference to speed up the initialization of your models? Let us know by leaving a comment here.

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.