How to force Embedded Coder to unroll the generated for loop of "For Each Subsystem" in generated code?

10 visualizaciones (últimos 30 días)
I am using for each subsystem to simulate and generate the embedded code for embedded hardware.
I have attached the simple example of For Each Subsystem and generated code.
I tried different Code generation Optimazation settings to unroll the loop in generated code but I am unable to solve it.
I tried also different values for loop unrolling threshold but this does not help or may be I am doing something wrong.
Does anyone know how to solve this issue?
Thank you.

Respuestas (1)

Harsh
Harsh el 22 de Abr. de 2025
Hi @SG,
The code generator unrolls loops when the number of iterations is below the threshold set in "Loop unrolling threshold" in advanced parameters. In the attached "For_Each_Subsystem_Example", there are iterations present in the for loop. Therefore you can set the value for "Loop unrolling threshold" as 4. There are two ways to do this:
  • Go to "Code Generation" > "Optimization" > "Advanced Parameters" and set the "Loop unrolling threshold" as 4.
  • Use the "set_param" function in command line.
set_param('For_Each_Example', 'RollThreshold', 4)
Here's how the generated code looks like after optimization -

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by