Main Content

Priority

Control application of optimizations based on priority

Model Configuration Pane: Code Generation / Optimization

Description

The Priority parameter optimizes the generated code for increased execution efficiency, decreased RAM consumption, or a balance between execution efficiency and RAM consumption.

Dependencies

This parameter is enabled by setting the Level parameter to Maximum.

Settings

Balance RAM and speed (default) | Maximize execution speed | Minimize RAM
Balance RAM and speed

Configure code generation settings to balance RAM and execution speed.

Maximize execution speed

Apply code generation settings to maximize execution speed.

Minimize RAM

Configure code generation settings to minimize RAM consumption.

Tips

For each Priority and Level parameter value, there are corresponding values for the parameters in the Details section. These are some important differences among these various settings:

  • If you set the Level parameter to Minimum (debugging), the parameters in the Details section are set to off. The code generator does not implement optimizations that remove variables or code making it easier to debug the generated code.

  • The parameter settings for Balanced with Readability and Balance RAM and speed are the same except for these three parameters:

    • Reuse buffers of different sizes and dimensions

    • Optimize global data access

    • Optimize block operation order in generated code

    The above optimizations can potentially hurt readability because they cross atomic subsystem boundaries and Optimize block operation order in generated code might change the block execution order in the generated code so that it is different than in simulation.

  • If you have limited RAM, choose the Minimize RAM setting. This setting enables these optimizations that reduce RAM at the expense of a potential slow-down in execution speed:

    • Pack Boolean data into bitfields

    • Reuse buffers of different sizes and dimensions

    • Use bitsets for storing state configuration

    • Use bitsets for storing Boolean data

    This setting also changes the Optimize block operation order in generated code from Improved Code Execution Speed to off.

For each Priority and Level parameter value, this table lists the corresponding values for the parameters in the Details section.

ParametersSettingsExample
LevelMinimum (debugging)Balanced with readabilityMaximum 
PriorityNot Applicable (N/A)N/ABalance RAM and speedMaximize execution speedMinimize RAM
Details  
Use memcpy for vector assignmentOffOnOnOnOnUse memcpy Function to Optimize Generated Code for Vector Assignments
Memcpy threshold (bytes)Off64646464Use memcpy Function to Optimize Generated Code for Vector Assignments
Enable local block outputsOffOnOnOnOnEnable and Reuse Local Block Outputs in Generated Code
Reuse local block outputsOffOnOnOnOnEnable and Reuse Local Block Outputs in Generated Code
Eliminate superfluous local variables (expression folding)OffOnOnOnOnMinimize Computations and Storage for Intermediate Results at Block Outputs
Reuse global block outputsOffOnOnOnOnReuse Global Block Outputs in the Generated Code
Perform in-place updates for Assignment and Bus Assignment blocksOffOnonOnOnPerform in-place updates for Assignment and Bus Assignment blocks
Reuse buffers for Data Store Read and Data Store Write blocksOffOnOnOnOnData Copy Reduction for Data Store Read and Data Store Write Blocks
Simplify array indexingOffOffOffOnOffSimplify Multiply Operations in Array Indexing
Pack Boolean data into bitfieldsOffOffOffOffOnOptimize Generated Code by Packing Boolean Data into Bitfields
Reuse buffers of different sizes and dimensionsOffOffOnOffOnReuse Buffers of Different Sizes and Dimensions
Reuse buffers for Model blocksOffOffOnOnOnReduce Memory Usage for Models Containing Referenced Models
Optimize global data accessNoneNoneUse global to hold temporary resultsNoneUse global to hold temporary resultsOptimize Global Variable Usage
Optimize block operation order in generated codeOffOffImproved Code Execution SpeedImproved Code Execution SpeedOffRemove Data Copies by Reordering Block Operations in the Generated Code
Use bitsets for storing state configurationOffOffOffOffOnReduce Memory Usage for Boolean and State Configuration Variables
Use bitsets for storing Boolean dataOffOffOffOffOnReduce Memory Usage for Boolean and State Configuration Variables

If you plan on upgrading your software, be aware that:

  • Setting the Level and Priority parameters enables the latest optimizations corresponding with the above parameter settings for each subsequent release.

  • Selecting the Specify custom optimizations parameter enables you to select individual parameters in the Details section. When you load a model in a future release, optimization parameters that were introduced in releases after you adopted the software to when you upgrade are set to off. If you want to reduce the number of changes in the generated code when you upgrade your software, this option can be a good choice.

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyMinimize RAM (RAM), Maximum execution speed (Speed), Balance RAM and speed (Balanced)
Safety precautionNo impact

Programmatic Use

Parameter: OptimizationPriority
Type character vector
Value: 'Balanced' | 'Speed'| 'RAM'
Default: 'Balanced'

Version History

Introduced in R2018a