How to speed up simulink parallel simulation using parsim command inside a for loop
12 views (last 30 days)
I have made one simulink model, which takes workspace variables during simulation. I put the below code inside a for loop.
in = Simulink.SimulationInput(model);
simOut = parsim(in,'TransferBaseWorkspaceVariables','on');
While running the complete program (for loop containing above code) MATLAB took a lot of time to transfer the workspace variables in each worker and also it took considerable amount of time to load simulink model in each worker. For running the above code I used 2 workers. I found that the time taken to run the complete program using parallel computing toolbox (using parsim command) is more than the normal simulation time without parallel computing toolbox. I used PCs with 2 workers and 8 workers but the simulation using parallel computing took more time in both cases.
So give me a solution to speed up my simulation using parallel computing toolbox.
Edric Ellis on 3 Mar 2021
To see the benefit of parsim, you need to set up multiple SimulationInput instances ahead of time, and then make a single call to parsim. This is shown in the documentation.
I'm going to guess that currently your for loop sets up different workspace parameters for the model? If so, you're going to need to change things sligthly so that instead of doing that, you change the parameters via the SimulationInput object. One way to do this is via the setVariable method of the SimulationInput object.