Why my simulation slow to run model that use for each block
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I got vehicle model with one wheel and I try to convert it to a four wheel model. To make it happen I used a for each block that represent the wheels in order to make the model simpler since each wheel are the same.
(The block alone on the left was at the position of the 'Wheels' subsystem block)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610446/image.png)
(This is insinde subsystem block named 'Wheels')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610451/image.png)
(This is what the wheel model look like)![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610456/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1610456/image.png)
Have you got some solution to improve the for each methode performance, because I still prefere this option since its a clearer model and this olso is easier to manipulate.
0 Commenti
Risposta accettata
Ayush
il 4 Mar 2024
Modificato: Ayush
il 4 Mar 2024
Hi Jean,
From the screenshots shared of your model, I can see that the visual representation of the model would be enhanced using “For Each” blocks but that also introduces computational overhead leading to loss in performance. Especially, if the block does not handle parallel processing or complex dynamics of the wheel subsystem. You can refer to some of the suggestions below in order to improve the performance of the model using the “For Each” method:
- Utilize the “Multicore Execution Support” for the “For Each” subsystem which enables multicore execution for faster simulation. It automatically profiles eligible subsystems for parallel processing and speeds up execution time. For more information you can refer to the below documentation:
- Look out for some calculations that are being done within the wheel subsystem that are same across each wheel and does not depend on iteration index in order to move these calculations out of the “For Each” block.
- Pre-allocate arrays and data structures within the “For Each” block or “Wheel Model” subsystem to avoid dynamic memory allocation during simulation. For more information on preallocation and increase in performance, refer to the below documentation:
Hope this helps!
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Subsystems in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!