Main Content

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

WhenArray layout(Simulink Coder)is set toRow-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 theUse algorithms optimized for row-major array layoutconfiguration parameter to enable efficient algorithms that are optimized for certain blocks. TheUse algorithms optimized for row-major array layoutparameter 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
  • WhenArray layoutis set toRow-major, this parameter enables the use of efficient algorithms that traverse the data in row-major order. The generated code is efficient.

  • WhenArray layoutis set toColumn-major, this parameter enables the use of algorithms that traverse the data in row-major order. The generated code is inefficient.

Off
  • WhenArray layoutis set toRow-major, the code generator uses algorithms that traverse the data in column-major order. The generated code is inefficient.

  • WhenArray layoutis set toColumn-major, the code generator uses algorithms that traverse the data in column-major order. The generated code is efficient.

Tips

WhenArray layoutis set toRow-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, selectUse algorithms optimized for row-major array layoutwhen theArray layoutis set toRow-majorfor 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:特征向量
Value:'on'|'off'
Default:'off'

Recommended Settings

Application Setting
Debugging No impact
Traceability No impact
Efficiency No impact
Safety precaution No impact

Related Topics