Code Regeneration in Accelerated Models - MATLAB & Simulink (original) (raw)

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.

  1. Use the Simulink.BlockDiagram.getChecksum function to obtain the checksum for your model. For example:
    cs1 = Simulink.BlockDiagram.getChecksum('myModel');
  2. Obtain a second checksum after you have altered your model. The code regenerates if the new checksum does not match the previous checksum.
  3. 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:

You can change some block diagram parameters during simulation without causing a rebuild, including the parameters listed in these tables.

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:

  1. Create a Simulink.SimulationInput object to configure the simulation.
    simin = Simulink.SimulationInput(mdl);
  2. Use the setModelParameter function to set theSimulationMode parameter value to "rapid-accelerator" and theRapidAcceleratorUpToDateCheck parameter value to"off".
    simin = setModelParameter(simin,SimulationMode="rapid-accelerator");
    simin = setModelParameter(simin,RapidAcceleratorUpToDateCheck="off");
  3. Use the setVariable function to specify the values to use for runtime parameters in the simulation. For example, this code configures the runtime parameter named param1 with a value of 10.
    simin = setVariable(mdl,"param1",10);
  4. Run the simulation using theSimulationInput object. For example, this code runs the simulation by specifying the SimulationInput object as an input argument for thesim function.

When you disable the rapid accelerator up-to-date check, you cannot tune parameters for the rapid accelerator simulation using theset_param function. Theset_param function modifies the parameter in the model, while theSimulationInput object modifies the parameter only in the simulation. The configuration on theSimulationInput 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 theset_param function can result in extra rapid accelerator target rebuilds compared to tuning parameter values using aSimulationInput object.

For more information about parameter tunability limitations, see Tunability Considerations and Limitations for Other Modeling Goals.

See Also

Topics