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.
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:
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.
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.
When doing the same test as before, we get:
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.
And run our test to measure the initialization time:
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.
要发表评论，请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。