As a solution I was able to find the block which was the problem but execution time using sim was very slow. Thus the best speed solution was to compile using real-time worksop and interface with the .exe using .mat files. This took the per execution time from ~2.5s down to ~0.2s.
supress simulink re-compile on every call
59 views (last 30 days)
I have a somewhat odd problem so bear with me.
I was presented with a rather large simulation suite written in Matlab which calculates sensory returns in an environment. Part of what I had to do was to re-make part of it in Simulink.
The simulink model I have made is called every so often in the model (at a regular number of time steps) and executed once on the current system parameters and sensor returns.
The output of my model will affect the system model for the next four steps and thus affect my inputs for my next execution. It is for this reason I cant simply make a big time based array of inputs and squirt them in in one go simulating a whole run. (Think of it like a feedback element whose tunining parameters can be changed on the through path as well as internal to itself).
This means that I have to call the model every time it is needed rather than pre-generating. My problem is that every time I call the sim command it re-compiles the simulink. This slows down my one simulation run from 30 mins to 11 hours (due to the sim call every n time steps). Is there a way to prevent it from having to recompile? All my inputs are presented as constants as I cant ammend the data structures to include time steps as each execution is only a single time step.
More Answers (3)
Titus Edelhofer on 9 Nov 2011
in this case I'd suggest to take a look at the following link: <http://www.mathworks.de/support/solutions/en/data/1-1HRSN0/index.html?product=ML&solution=1-1HRSN0>
Additionally take a look at the doc for
which can be used to find out, which blocks have changed in a way the accelerator does not like.
Giovanni on 2 Aug 2017
I have just received this technical support that solved this problem. It is a particular situation using simscape (topic is 'run-time parametres Vs compile-time parameters'). So if you do not need to change any simscape parameters but only need to change simulink parameters the 'set_param' lines are not needed, and the , 'FastRestart', option is enough! I love this team!
Support starts here (see also model option about automatic data save):
I understand that you want to avoid compilation time when running multiple simulations of the same Simscape model in a loop, while changing the value of a parameter.
Please note that Simscape run-time parameters are different from Simulink tunable parameters. You can visit the documentation for more information on how Simscape run-time parameters differs from Simulink.
A possible solution is to enable fast restart while specifying run-time parameters as follows :
% First we load the example model 'ssc_bipolar_nonlinear'
model = 'ssc_bipolar_nonlinear';
% In this model, the R3 resistor is varied within a for-loop.
% The result is then plotted for each value of R3.
set_param([model '/R3'], 'R', 'R3_par' )
set_param([model '/R3'], 'R_conf', 'runtime')
for R = [1000 2000 3000 4000 5000 6000 7000 8000]
R3_par = R;
% The simulations are launched using the FastRestart mode to avoid compilation time
simout = sim(model, 'FastRestart', 'on');
You can visit the following link for additional information on run-time parameters : http://www.mathworks.com/help/physmod/simscape/run-time-parameters.html
Charles Harrison on 9 Oct 2013
I feel your pain and have experienced similar situations before. As such there are two solutions that I can think of that can solve your problem:
1st Solution: Instead of using the 'sim' command, I suggest using the model command. Specifically the model command is advantageous if you are just trying to treat your model as a funciton and get outputs for a given set of inputs. Additionally make sure that you 'compile' and 'term' the model as few times as possible to prevent initialization overhead.
output_vector = model_name(0,state_vector,input_vector);
Tell the reference models not to rebuild. This is a two step process. First Go to Simulation->Configuration Parameters -> Model Referenceing -> Rebuild -> Never (Alternatively this can be also done progratically from the command line if needed. Just reply to this post if you need to know how). After that, make sure the secondary setting next to the rebuild parameter (regarding the error message) is set to None. I think it is the stupidest thing, but even if you tell Simulink not to rebuild, and dont set the error checking message also not to check, then it will still rebuild! Once this step is complete if you need to make changes to the reference models (like make a data or structural change) you need to temporarily set the Rebuild parameter to 'If out of Date' and then run the sim to recompile. Another alternative is if you need changes to be recognize, you can use the slbuild command.