coder.loop.interchange
R2026bDescription
coder.loop.interchange(
directs the code generator to swap the nesting order of the loopA_ID,loopB_ID)for-loops
with index names loopA_ID and loopB_ID in the
generated code.
Use this directive to improve memory locality if you access array elements stored in contiguous memory blocks. This directive can improve cache performance by enabling cache reuse without requiring a cache refresh.
This directive can improve performance only when the current loop order results in a memory access pattern with poor locality. Use this directive for nested loops that have independent iterations and compatible bounds where reordering does not affect correctness.
For more information about loop optimizations, see Optimize Loops in Generated Code.
Examples
Input Arguments
Tips
To view potential issues that the code generator encounters when applying the
coder.loop.interchangedirective, review the Code Insights section of the code generation report. See Code Generation Reports.
Extended Capabilities
Version History
Introduced in R2023a