Use algorithms optimized for row-major array layout
Description
For certain blocks, enable optimized algorithms for row-major format code generation and corresponding row-major algorithms for model simulation.
Category: Math and Data Types
Settings
Default: Off
When Array layout (Simulink Coder) is set to
Row-major
, the code generator uses algorithms to
maintain consistency of numeric results between the simulation and the generated
code. Sometimes, the generated code for these algorithms might be inefficient. You
can enable the Use algorithms optimized for row-major array
layout configuration parameter to enable efficient algorithms that
are optimized for certain blocks. The Use algorithms optimized for
row-major array layout parameter affects the simulation and the
generated code.
This parameter affects only these blocks:
Sum of Elements
Product of Elements
n-D Lookup Table
Interpolation Using Prelookup
Direct Lookup Table (n-D)
For these blocks, the column-major and row-major algorithms might differ in the order of output calculations, possibly resulting in slightly different numeric values.
On
When Array layout is set to
Row-major
, this parameter enables the use of efficient algorithms that traverse the data in row-major order. The generated code is efficient.When Array layout is set to
Column-major
, this parameter enables the use of algorithms that traverse the data in row-major order. The generated code is inefficient.
Off
When Array layout is set to
Row-major
, the code generator uses algorithms that traverse the data in column-major order. The generated code is inefficient.When Array layout is set to
Column-major
, the code generator uses algorithms that traverse the data in column-major order. The generated code is efficient.
Tips
When Array layout is set to
Row-major
, the row-major algorithm operates on table
data that is contiguous in memory. This table data leads to faster cache access,
making these algorithms cache-friendly.
This table summarizes the relationship between array layout and cache-friendly
algorithms. It is a best practice to use the algorithm that is optimized for the
specified array layout to achieve good performance. For example, select
Use algorithms optimized for row-major array layout when
the Array layout is set to Row-major
for code generation.
ArrayLayout | UseRowMajorAlgorithm | Algorithm Applied |
---|---|---|
Column-major | 'off' | Efficient column-major algorithm Recommended |
Row-major | 'off' | Inefficient column-major algorithm Not recommended |
Column-major | 'on' | Inefficient row-major algorithm Not recommended |
Row-major | 'on' | Efficient row-major algorithm Recommended |
Command-Line Information
Parameter:
UseRowMajorAlgorithm |
Type: character vector |
Value:
'on' | 'off' |
Default:
'off' |
Recommended Settings
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | No impact |
Safety precaution | No impact |
Related Topics
- Math and Data Types Pane
- Code Generation of Matrices and Arrays (Simulink Coder)
- Row-Major Algorithms for Row-Major Array Layout (Simulink Coder)