Hi Dimosthenis Michaloudis,
I understand that you are attempting to utilize the 'parsim' function to run simulations in parallel, aiming to reduce the simulation time. However, it appears that the simulation time using 'parsim' is significantly higher than the normal simulation time.
The 'parsim' function was employed to simulate multiple models specified in the 'SimulationInput' object concurrently. While 'parsim' can effectively reduce the simulation time, it is crucial to structure the model appropriately. Specifically, the simulation should not rely on the results of previous steps. In other words, there should be no dependency between the simulations of the model at different time steps.
Assuming the model is suitable for simulation in parallel, follow the below steps to reduce the runtime,
- Make sure ‘Parallel Computing Toolbox’ (PCT) is installed, since ‘parsim’ requires PCT to utilize parallelism.
- In the following line, avoid using 'TransferBaseWorkspaceVariables' option to reduce simulation time. The 'TransferBaseWorkspaceVariables”option is not recommended for large scale simulations.
simOut = parsim(simIn, 'TransferBaseWorkspaceVariables', 'on', 'ShowSimulationManager', 'on');
- The following line will not result in simulation starting from the specified time as you would have expected, instead this will change the ‘SampleTime’ for the entire model. Review this line and made necessary changes
simIn(idx) = simIn(idx).setBlockParameter(variablePath, 'SampleTime', num2str(sweep(idx)));
- Experiment with the number of workers in your parallel pool to find the optimal configuration.
For more information on ‘parsim’ and multiple model simulation, refer the following MATLAB documentation,
- https://www.mathworks.com/help/parallelcomputing/parpool.html#d126e79413
- https://www.mathworks.com/help/simulink/slref/parsim.html#bvnh103-2
- https://www.mathworks.com/help/simulink/ug/optimize-estimate-and-sweep-block-parameter-values.html
Hope this is helpful.