Level
Optimization level for generated code
Model Configuration Pane: Code Generation / Optimization
Description
The Level parameter specifies the optimization level to apply to the generated code.
Settings
Maximum
(default) | Minimum (Debugging)
| Balanced with Readability
Minimum (Debugging)
Configure code generation settings for debugging.
Balanced with Readability
Apply code generation optimizations that balance RAM efficiency and execution speed with the readability of the generated code. For example, selecting this value disables optimizations that cross atomic subsystem boundaries.
Maximum
Configure code generation settings based on your code efficiency objectives. Choosing this setting enables the Priority parameter. Set the Priority parameter to one of these values:
Balance RAM and speed (default setting)
Maximum execution speed
Minimize RAM
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
andBalance 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
tooff
.
For each Priority and Level parameter value, this table lists the corresponding values for the parameters in the Details section.
Parameters | Settings | Example | ||||
---|---|---|---|---|---|---|
Level | Minimum (debugging) | Balanced with readability | Maximum | |||
Priority | Not Applicable (N/A) | N/A | Balance RAM and speed | Maximize execution speed | Minimize RAM | |
Details | ||||||
Use memcpy for vector assignment | Off | On | On | On | On | Use memcpy Function to Optimize Generated Code for Vector Assignments |
Memcpy threshold (bytes) | Off | 64 | 64 | 64 | 64 | Use memcpy Function to Optimize Generated Code for Vector Assignments |
Enable local block outputs | Off | On | On | On | On | Enable and Reuse Local Block Outputs in Generated Code |
Reuse local block outputs | Off | On | On | On | On | Enable and Reuse Local Block Outputs in Generated Code |
Eliminate superfluous local variables (expression folding) | Off | On | On | On | On | Minimize Computations and Storage for Intermediate Results at Block Outputs |
Reuse global block outputs | Off | On | On | On | On | Reuse Global Block Outputs in the Generated Code |
Perform in-place updates for Assignment and Bus Assignment blocks | Off | On | on | On | On | Perform in-place updates for Assignment and Bus Assignment blocks |
Reuse buffers for Data Store Read and Data Store Write blocks | Off | On | On | On | On | Data Copy Reduction for Data Store Read and Data Store Write Blocks |
Simplify array indexing | Off | Off | Off | On | Off | Simplify Multiply Operations in Array Indexing |
Pack Boolean data into bitfields | Off | Off | Off | Off | On | Optimize Generated Code by Packing Boolean Data into Bitfields |
Reuse buffers of different sizes and dimensions | Off | Off | On | Off | On | Reuse Buffers of Different Sizes and Dimensions |
Generate parallel for-loops | Off | Off | Off | On | Off | Generate Parallel for-Loops Using the Open Multiprocessing (OpenMP) Application Interface |
Automatically schedule for-loops | Off | Off | Off | On | Off | Automatically Schedule for-Loops for Neighborhood Processing Subsystems |
Reuse buffers for Model blocks | Off | Off | On | On | On | Reduce Memory Usage for Models Containing Referenced Models |
Optimize global data access | None | None | Use global to hold temporary results | None | Use global to hold temporary results | Optimize Global Variable Usage |
Optimize block operation order in generated code | Off | Off | Improved Code Execution Speed | Improved Code Execution Speed | Off | Remove Data Copies by Reordering Block Operations in the Generated Code |
Use bitsets for storing state configuration | Off | Off | Off | Off | On | Reduce Memory Usage for Boolean and State Configuration Variables |
Use bitsets for storing Boolean data | Off | Off | Off | Off | On | Reduce 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
Application | Setting |
---|---|
Debugging | Minimum (debugging) |
Traceability | Minimum (debugging) |
Efficiency | Based on your goals, choose Balanced with Readability or Maximum . If you choose Maximum , set the Priority parameter. |
Safety precaution | No impact |
Programmatic Use
Parameter: OptimizationLevel |
Type character vector |
Value: 'level0' (UI Setting Minimum (debugging) )| 'level1' (UI Setting Balanced with Readability )| 'level2' (UI Setting Maximum ) |
Default: 'level2' |
Version History
Introduced in R2007b