Block reduction
Description
Reduce execution time by collapsing or removing groups of blocks.
Category: Simulation Target
Settings
Default: On
On
Simulink® software searches for and reduces these block patterns:
Redundant type conversions — Unnecessary type conversion blocks, such as an
int
type conversion block with an input and output of typeint
Dead code — Blocks or signals in an unused code path
Fast-to-slow Rate Transition block in a single-tasking system — Rate Transition blocks with an input frequency faster than its output frequency
Off
Simulink software does not search for block patterns that can be optimized. Simulation and generated code are not optimized.
Tips
When you select Block reduction, Simulink software collapses certain groups of blocks into a single, more efficient block, or removes them entirely. This reduction results in faster execution during model simulation and in generated code.
Block reduction does not change the appearance of the source model.
Tunable parameters do not prevent a block from being reduced by dead code elimination.
Once block reduction takes place, Simulink software does not display the sorted order for blocks that have been removed.
You can determine programmatically which blocks are reduced in a model by querying the
ReducedNonVirtualBlockList
parameter of the model to obtain a vector of the block handles of the reduced blocks.ReducedBlockHandlesVector = get_param(ModelName,'ReducedNonVirtualBlockList');
If you have a Simulink Coder™ license, block reduction is intended to remove only the generated code that represents execution of a block. Other supporting data, such as definitions for sample time and data types might remain in the generated code.
Dead Code Elimination
Any blocks or signals in an unused code path are eliminated from generated code.
The following conditions need to be met for a block to be considered part of an unused code path:
All signal paths for the block end with a block that does not execute. Examples of blocks that do not execute include Terminator blocks, disabled Assertion blocks, S-Function blocks configured for block reduction, and To Workspace blocks when MAT-file logging is disabled for code generation.
No signal paths for the block include global signal storage downstream from the block.
Tunable parameters do not prevent a block from being reduced by dead code elimination.
Consider the signal paths in the following block diagram.
If you check Block reduction, Simulink Coder software responds to each signal path as follows:
For Signal Path... Simulink Coder Software... In1 to Out1 Generates code because dead code elimination conditions are not met. In2 to Terminator Does not generate code because dead code elimination conditions are met. In3 to Scope Generates code if MAT-file logging is enabled and eliminates code if MAT-file logging is disabled.
Highlight Reduced Blocks
When Block reduction is selected, you can highlight
nonvirtual blocks that are removed to reduce execution time during model simulation
and code generation. To highlight such blocks, on the Simulink toolstrip, go to the Debug tab. From the
Information Overlays menu, select Reduced
Blocks
.
Note
If there are no reduced blocks to highlight, the Reduced
Blocks
option is disabled.
Reduced blocks appear highlighted on the canvas. After you update or simulate your model, blocks that are reduced during normal simulation are highlighted. After you build your model, blocks that are reduced during code generation are highlighted.
To remove the highlighting, click in the upper-right corner of the canvas, or clear
the
Reduced Blocks
selection from the
Information Overlays menu.
Command-Line Information
Parameter:
BlockReduction |
Value:
'on' | 'off' |
Default:
'on' |
Recommended Settings
Application | Setting |
---|---|
Debugging | Off for simulation or during development No impact for production code generation |
Traceability | Off |
Efficiency | On |
Safety precaution | No impact |
Related Topics
- Remove Code for Blocks That Have No Effect on Computational Results (Simulink Coder)
- Eliminate Dead Code Paths in Generated Code (Simulink Coder)
- Time-Based Scheduling (Simulink Coder)
- Code Efficiency (Simulink Coder)
- Model Configuration Parameters: Simulation Target