- Call model InitFcn callback.
- Call model SetupRuntimeResources method
- Call model Start method.
- Call model Initialize method.
- Call model and block StartFcn callbacks.
Is there a way to reduce initialization time during consecutive simulation operation?
5 views (last 30 days)
Show older comments
I have written the following code in Matlab/Simulink to repeatedly simulate at certain time intervals and restart the simulation from the last simstate.
stop_times = 15:15:15*3; % 15 second intervals upto 45 seconds
mdl = 'myModel' ; % model name
load_system(mdl) ;
set_param(mdl, 'FastRestart','off')
set_param(mdl,'SimulationMode','Accelerator') % in Accelerator mode
set_param(mdl,'SaveFinalState','on','FinalStateName','xFinal','SaveCompleteFinalSimState','on'); % save final state
set_param(mdl,'StartTime','0')
set_param(mdl, 'FastRestart','on') % FastRestart
simOut = sim(mdl,'StopTime','0'); % find SimState at t=0
simulationTimingInfo = cell(1,numel(stop_times));
for tdx = 1:numel(stop_times)
simOut = sim(mdl, 'StopTime', num2str(stop_times(tdx)),...
'LoadInitialState', 'on', 'InitialState', 'simOut.xFinal'); % perform consecutive simulations
simulationTimingInfo{tdx} = simOut.SimulationMetadata.TimingInfo ; % save timing information
end
As a result, from the simulationTimingInfo,
InitializationElapsedWallTime was about 5 s,
ExecutionElapsedWallTime was about 4.2 s,
TerminationElapsedWallTime was about 0.2 s in each 15 s simulations.
However, since I have set the 'FastRestart' option to 'on', I expected the InitializationElapsedWallTime to be close to zero as it eliminates the need for multiple compilations.
Certainly, when I set the 'FastRestart' option to 'off', the InitializationElapsedWallTime reaches 11 seconds, indicating that FastRestart reduces the InitializationElapsedWallTime. However, I am unsure why it is not close to zero in my case.
Is there a reason why InitializationElapsedWallTime cannot be reduced? Or are there other ways to reduce InitializationElapsedWallTime?
- Matlab version: 9.3.0.948333 (R2017b) Update 9, Simulink version: 9.0
0 Comments
Answers (1)
Song-Hyun Ji
on 29 Jun 2023
Edited: Song-Hyun Ji
on 29 Jun 2023
There are minimum steps regardless of using fast restart as below. You can get further information in the manual 'Get Startd with Fast Restart'.
--------------------------------------------------
Model Methods and Callbacks in Fast Restart
When fast restart is on, Simulink calls model and block methods and callbacks as follows:
Note
Steps 1–5 apply to all simulations in Simulink (with or without fast restart).
--------------------------------------------------
For your information, Rapid Accelerator mode with the option 'RapidAcceleratorUptoDateCheck' can minimize InitializationElapsedWallTime if you know the model has not changed. With this option, you can tell Simluink to skip to compute a checksum to verify if the model has changed and determine if it needs to re-generate code.
Ex.
modelname = 'vdp'
in(1:3) = Simulink.SimulationInput(modelname);
in(1) = in(1).setModelParameter('SimulationMode','Rapid');
in(2) = in(2).setModelParameter('SimulationMode','Rapid');
in(3) = in(3).setModelParameter('SimulationMode','Rapid');
in(3) = in(3).setModelParameter('RapidAcceleratorUpToDateCheck', 'off');
out = sim(in);
t1 = out(1).SimulationMetadata.TimingInfo.InitializationElapsedWallTime
t2 = out(2).SimulationMetadata.TimingInfo.InitializationElapsedWallTime
t3 = out(3).SimulationMetadata.TimingInfo.InitializationElapsedWallTime
t1 =
1.6355
t2 =
1.4808
t3 =
0.1567
2 Comments
Song-Hyun Ji
on 29 Jun 2023
Unfortunately, Saving Final Sim States(SaveCompleteFinalSimState) is not supported in Rapid Accelerator mode.
See Also
Categories
Find more on Acceleration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!