Code Regeneration in Accelerated Models
Changing the structure of your model causes rapid accelerator mode to regenerate the standalone executable, and for the accelerator mode to regenerate the target code and update (overwrite) the existing MEX-file. Changing the value of a tunable parameter does not trigger a rebuild.
Determine Whether Change Requires Rebuild
The accelerator and rapid accelerator modes use a checksum to determine if the model has changed, indicating that the code should be regenerated. The checksum is an array of four integers computed using an MD5 checksum algorithm based on attributes of the model and the blocks it contains.
Use the
Simulink.BlockDiagram.getChecksumfunction to obtain the checksum for your model. For example:cs1 = Simulink.BlockDiagram.getChecksum('myModel');Obtain a second checksum after you have altered your model. The code regenerates if the new checksum does not match the previous checksum.
Use the information in the checksum to determine why the simulation target rebuilt.
For a detailed explanation of this procedure, see Determine Why Simulink Accelerator Is Regenerating Code.
Parameter Tuning in Rapid Accelerator Mode
In model rebuilds, rapid accelerator mode handles model configuration parameters and runtime parameters differently from other parameters.
Tune Model Configuration Parameters
To tune model configuration parameter values, you can:
Specify the parameter value on the
Simulink.SimulationInputobject that configures the simulation by using thesetModelParameterfunction.Programmatically change the configuration parameter value in the model using the
set_paramfunction.Change the value in the model using the Configuration Parameters dialog box. To open the Configuration Parameters dialog box, in the Simulink® Toolstrip, on the Modeling tab, click Model Settings.
You can change some block diagram parameters during simulation without causing a rebuild, including the parameters listed in these tables.
| Solver Parameters | ||
|---|---|---|
| AbsTol | MaxConsecutiveZCs | Refine |
| ConsecutiveZCsStepRelTol | MaxOrder | RelTol |
| ExtrapolationOrder | MaxStep | StartTime |
| InitialStep | MinStep | StopTime |
| MaxConsecutiveMinStep | OutputTimes | |
Tune Runtime Parameters
The technique you use to tune runtime parameters in rapid accelerator simulations can affect whether the software rebuilds the rapid accelerator executable. Because rebuilding the executable can take significant time, avoiding rebuilds due to tuning parameters improves the efficiency of your rapid accelerator simulation workflow.
First, confirm that the parameters you want to tune
are tunable and your model is set up to support
tuning the desired parameters. To identify runtime
parameters in your model, use the Simulink.BlockDiagram.buildRapidAcceleratorTarget.
Directly tuning block parameter values in rapid
accelerator simulations is not supported. When you
want to tune a block parameter value in rapid
accelerator simulations, define the block
parameter value as a variable. Then, tune the
variable value instead.
To tune runtime parameter values in your model without rebuilding the rapid accelerator executable, follow these steps:
Create a
Simulink.SimulationInputobject to configure the simulation.simin = Simulink.SimulationInput(mdl);
Use the
setModelParameterfunction to set theSimulationModeparameter value to"rapid-accelerator"and theRapidAcceleratorUpToDateCheckparameter value to"off".simin = setModelParameter(simin,SimulationMode="rapid-accelerator"); simin = setModelParameter(simin,RapidAcceleratorUpToDateCheck="off");
Use the
setVariablefunction to specify the values to use for runtime parameters in the simulation. For example, this code configures the runtime parameter namedparam1with a value of10.simin = setVariable(mdl,"param1",10);Run the simulation using the
SimulationInputobject. For example, this code runs the simulation by specifying theSimulationInputobject as an input argument for thesimfunction.out = sim(simin);
When you disable the rapid accelerator up-to-date
check, you cannot tune parameters for the rapid
accelerator simulation using the
set_param function. The
set_param function modifies
the parameter in the model, while the
SimulationInput object modifies
the parameter only in the simulation. The
configuration on the
SimulationInput object is applied
during simulation and reverts when the simulation
completes.
For the rapid accelerator simulation to reflect
changes you make to the model, you need to
regenerate the rapid accelerator simulation
target. Leaving the rapid accelerator up-to-date
check enabled to tune parameter values using the
set_param function can result
in extra rapid accelerator target rebuilds
compared to tuning parameter values using a
SimulationInput object.
For more information about parameter tunability limitations, see Tunability Considerations and Limitations for Other Modeling Goals.