Effacer les filtres
Effacer les filtres

Running code inspector with a For Loop Iterator

9 vues (au cours des 30 derniers jours)
Mathieu
Mathieu le 18 Mar 2024
Commenté : Mathieu le 11 Juin 2024 à 9:41
Hello,
I have a model running with a For Iterator (to read an Input Array and write some of its datas to another one shorter array).
The model must go through both Model Advisor and Code Inspector to be embedded in the calculator.
As for the Model Advisor everything is passed and generated code is about 120 lines, however when I try to run the code inspector, it runs for more than 2.5hrs (on the inspection only) and I am forced to kill the Matlab task afterward because it stops running. Here is a screenshot of the model.
Here is what I tried:
  • include the "add" and the "unitDelaty" inside the referenced model => it creates an algebraic loop
  • add the triggered block within a referenced model => impossible as it contain an "assignement" block and therefore cannot be referenced.
  • Simplify the referenced model to reduce load capacity of the model containg.
I can provide the generated C code if necessary
Thank you,

Réponses (1)

Debadipto
Debadipto le 28 Mar 2024
It's difficult to tell exactly what's causing the Code Inspector to slow down by just looking at the model. Could you please check if the iteration count, denoted by the parameter 'N' in the For Iterator, is not set too high?
I recommend reaching out to MathWorks Technical Support for further assistance with this issue:
https://www.mathworks.com/support/contact_us.html
  3 commentaires
Davide Scarabattoli
Davide Scarabattoli le 11 Juin 2024 à 8:16
Modifié(e) : Davide Scarabattoli le 11 Juin 2024 à 8:19
Hello,
I have the same problem (with revision 2023b). After a month of testing with “technical support” it turns out that it is a known issue. In general code inspector (SLCI), with iterators has serious problems. This is because it executes all iterations of the loop (For or While), allocating an incredible amount of memory (in my case I had a loop of 4192 elements).
Mathworks technical support did not give a solution to this problem.
I can tell you that the original issue number is 3302091.
We for SW compatibility reduced the loop to 12 iterations to validate with SLCI and then regenerate the final code with the correct number of iterations. Horrible solution, but I think it is the only viable one (for the time being).
Mathieu
Mathieu le 11 Juin 2024 à 9:41
Hello David,
I have been in contact with Mathworks technical support since late march regarding this issue and I have some updates that I can provide that might be helpful for you.
It seems like this running time error occurs more often when running through code generated as "Referenced Model". You can try generating it as "Top model" if possible to verify if the error is kept.
As for my case, I cannot afford to generate as "Top model". Mathworks support team suggested to call the following function before opening the models:
>> slcifeature('LoopSupport', 3);
It solves the running time issue on my side (using R2024a update 3).
HOWEVER: This function is still under development on Mathworks side, thus it is not documented yet. Thus it might not be usable regarding the application (which is my case).
FYI, Code Inspector handles loop iterators by unrolling them. Therefore, the more iterations the more resources will be required and a new inspection algorithm for loops is being developted for a future MATLAB version in which none of the above errors are encountered (using the same models).

Connectez-vous pour commenter.

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by