- Rapid accelerator mode seems to be slower than normal mode
- Rapid accelerator mode is faster when running for a second time (and all future times, as long as the model is unchanged)
Rapid Accelerator vs Normal Simulation Time Difference
조회 수: 16 (최근 30일)
이전 댓글 표시
I am comparing the simulation time using Rapid Accelerator simulation mode versus normal simulation mode. I wrote the following two scripts to test this based on the MathWorks article and blog post I found here and here :
orig = warning;
warning('off','Simulink:Engine:UINotUpdatedDuringRapidAccelSim');
k = Simulink.Parameter;
k.CoderInfo.StorageClass = 'SimulinkGlobal';
k.Value = -0.9;
mdl = 'sldemo_bounce';
open_system(mdl);
set_param(sprintf('sldemo_bounce/Coefficient of\n Restitution'),'Gain','k');
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
k_values = [-0.9:0.1:-0.1];
for i = 1:length(k_values)
paramSet(i) = Simulink.BlockDiagram.modifyTunableParameters(rtp, ...
'k', k_values(i));
end
tStart = tic;
for i = 1:length(k_values)
simout(i) = sim(mdl,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',paramSet(i));
end
tFinal = toc(tStart);
disp(['Duration: ', num2str(tFinal)]);
warning(orig);
The script to run in normal mode:
mdl = 'sldemo_bounce';
open_system(mdl);
set_param(sprintf('sldemo_bounce/Coefficient of\n Restitution'),'Gain','k');
k_values = [-0.9:0.1:-0.1];
tStart = tic;
for i = 1:length(k_values)
k = k_values(i);
simout(i) = sim(mdl, 'ReturnWorkspaceOutputs', 'on');
end
tFinal = toc(tStart);
disp(['Duration: ', num2str(tFinal)]);
When I test each of these scripts I consistently find using Rapid Accelerator mode doubles the simulation time (~3.5 s vs ~1.5 s in normal mode).
Can anyone comment on this? I think I copied the example code mostly verbatim so am a little confused what I could be doing wrong.
I am using MATLAB R2015b in case that makes a difference.
Thanks!
댓글 수: 0
답변 (1개)
Omanshu Thapliyal
2018년 5월 17일
This is an excellent observation. I was readily able to recreate results same as yours using the script you've provided, using R2018b.
>> RapidAccelScript
### Building the rapid accelerator target for model: sldemo_bounce
### Successfully built the rapid accelerator target for model: sldemo_bounce
Duration: 14.1602
>> NormalScript
Duration: 6.2179
>> RapidAccelScript
Duration: 9.4121
A couple of things can be noted straightaway:
Going through the documentation of Acceleration mode , the second observation can be explained. Rapid Accelerator mode creates a standalone executable of your model. The reason why it takes more time the first time is that it is spending that time in building the said executable. For all subsequent runs, it calls this executable instead of the model, hence is faster than normal mode.
However, for small or not so complex models, this overhead time spent in communicating in external mode with the can be more than time spent in actual simulation (such as this example). To see where rapid accelerator mode shines, we can simply make the same model run for a longer duration. To do so, I added the following set_param command in both scripts.
set_param(mdl, 'StopTime', '3000')
And got the following result:
>> NormalScript
Duration: 15.9357
>> RapidAccelScript
Duration: 11.8157
We can clearly see that Rapid accelerator mode definitely is faster now.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Acceleration에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!