https://www.acsysteme.com/wp-content/uploads/2021/08/saga2021-SSu-6-scope2.png

S01E07: Simulink parallelisation by Sébastien SALIOU

The What’s New in MATLAB and Simulink R2021a video from the Matlab Expo 2021 conference addressed new features in parallelisation capabilities with Simulink. This announcement was an opportunity for Acsystème to remind you of the main parallelisation possibilities in Simulink in order to speed up your simulations. A first approach consists of parallelising the different simulations of a set of simulations carried out within the scope of a sensitivity study for example. The second approach (that mentioned at the Matlab Expo) consists of parallelising the calculations within a Simulink model. Which will you choose?

Approach 1: Parallelising simulations

If the Parallel Computing Toolbox is available, it is relatively simple to parallelise a range of simulations, provided that the result of one simulation does not impact those that follow. This is especially the case for a sensitivity study which consists of simulating the same model for several different values ​​of one or more parameters. To do this, we will use the parfor or the parsim command.

The video below shows the conversion of a for loop by a parfor loop, and the saving obtained in terms of simulation time (from 16.79 s to 10.32 s).

More info on parallelisation using the parfor command here.

 

The video below shows the conversion of a for loop using the parsim function. The syntax is quite different, but this method is that recommended by Mathworks to parallelise a large number of simulations. Note that using the parsim function gives access to a graphics interface, the Simulation Manager, to view the details of each simulation. The Simulation Manager also allows you to use the Simulation Data Inspector to compare the results of different simulations. Ronan Blanchard considers this last tool in Episode 6 of our saga.

In the example used to create this video, we observe very little saving of simulation time (from 26.12 s to 25.44 s). This is explained by the limited number of iterations and the simplicity of the model used for this demonstration.

More info on parallelisation using the parsim function here.

A comparison of the calculation times for the three methods (for/parfor/parsim) for a higher number of iterations is presented in the figure below.

https://www.acsysteme.com/wp-content/uploads/2021/08/Loops_1000simu-750×580.png

Consult the full saga

Approach 2: parallelising calculations within a model

At Matlab Expo 2021 conferences, Mathworks announced the possibility of parallelising calculations within a Simulink model if it contains s-functions or referenced models and these can be parallelised. The figure below presents both types of execution for a model of this type.

https://www.acsysteme.com/wp-content/uploads/2021/08/saga2021-SSu-4-exemple_modele-750×699.png

Mathworks specifies that this functionality is automatic, but is limited to three types of block:

  • Model reference in accelerator mode,
  • S-function,
  • Functional Mock-up Unit (FMU) Co-Simulation.

Matlab/Simulink documentation provides an example that illustrates this functionality very well in the case of an example with s-functions.

To validate this functionality in the case of referenced models, at Acsystème we have created an example similar to that referenced above. The two figures below illustrate this example.

https://www.acsysteme.com/wp-content/uploads/2021/08/saga2021-SSu-5-scope1.png
https://www.acsysteme.com/wp-content/uploads/2021/08/saga2021-SSu-6-scope2.png

Implementing this feature requires several limitations to be considered: referenced models used in accelerator mode, no continuous states, use of a fixed-step solver, etc. Despite these limitations (some of which will certainly be removed in future versions of Matlab), this feature is definitely a good approach for reducing simulation times. It requires the creation of referenced models. This is also a good technique for reducing simulation times as is described very well in the article “reduce your Simulink simulation times with the Reference Model” by Marouane Benaziz.

Conclusion

This article presents two approaches based on parallelisation to speed up your simulations in Simulink, the second approach being a new feature of the R2021a release. For your information, Mathworks provides a range of videos entitled Five Practical Tips to Speed Up Your Simulink Simulations which deals with s other approaches, namely the use of Performance Advisor, Fast Restart mode, Model References, and the choice of the simulation mode (Normal, Accelerator and Rapid Accelerator).

Consult the full saga

Share this post: