Is there a way to reduce initialization time during consecutive simulation operation?

4 visualizaciones (últimos 30 días)
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

Respuestas (1)

Song-Hyun Ji
Song-Hyun Ji el 29 de Jun. de 2023
Editada: Song-Hyun Ji el 29 de Jun. de 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:
  1. Call model InitFcn callback.
  2. Call model SetupRuntimeResources method
  3. Call model Start method.
  4. Call model Initialize method.
  5. Call model and block StartFcn callbacks.
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 comentarios
Jeong Kuk Hong
Jeong Kuk Hong el 29 de Jun. de 2023
I need to consequently run simulations at regular time intervals in Simulink, and I need to save the final state of each simulation using SimState to communicate with other programs at regular intervals. However, I'm aware that SimState cannot be used in Rapid Accelerator mode. Is it possible to use SimState to save the final state in Rapid Accelerator mode?
Song-Hyun Ji
Song-Hyun Ji el 29 de Jun. de 2023
Unfortunately, Saving Final Sim States(SaveCompleteFinalSimState) is not supported in Rapid Accelerator mode.

Iniciar sesión para comentar.

Categorías

Más información sobre Acceleration en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by