Interact with the Acceleration Modes Programmatically
Why Interact Programmatically?
You can build an accelerated model, select the simulation mode, and run the simulation programmatically. With this flexibility, you can create accelerator mode MEX-files in batch mode, allowing you to build the C code and executable before running the simulations. When you use accelerator mode interactively at a later time, it will not be necessary to generate or compile MEX-files at the start of the accelerated simulations.
Build JIT Accelerated Execution Engine
accelbuild command, you can build a
JIT accelerated execution engine without actually simulating
the model. For example, to build an accelerator mode
You can control the simulation mode programmatically using the
The simulation mode can be
For example, to simulate your model using accelerator mode, you would use:
simOut = sim('myModel','SimulationMode','accelerator');
You can use
bdroot to set parameters for the
currently active model (that is, the active model window)
modelname if you do
not wish to explicitly specify the model name.
For example, to simulate the currently opened system using rapid accelerator mode, you would use:
simOut = sim(bdroot,'SimulationMode','rapid');
Simulate Your Model
You can use
set_param to configure the model
parameters (such as the simulation mode and the stop time),
and use the
command to start the simulation:
However, the preferred method is to configure model parameters
directly using the
sim command, as
shown in the previous section.
You can substitute
if you do not want to explicitly specify the model name.
Unless target code has already been generated, the
sim function first builds the
executable and then runs the simulation. However, if the
target code has already been generated and no significant
changes have been made to the model (see Code Regeneration in Accelerated Models
for a description), the
executes the generated code without regenerating the code.
This process lets you run your model after making simple
changes without having to wait for the model to
The following sequence shows how to programmatically
myModel in rapid
accelerator mode for 10,000 seconds.
myModel, and then type
the following in the Command Window:
simOut = sim('myModel','SimulationMode','rapid', ... 'StopTime','10000');
sim function again to
simulate after making a change to your model. If
the change is minor (adjusting the gain of a gain
block, for instance), the simulation runs without
Customize the Acceleration Build Process
You can programmatically control the accelerator mode and rapid accelerator mode build process and the amount of information displayed during the build process. See Customize the Build Process for details on why doing so might be advantageous.
Controlling the Build Process
SimCompilerOptimization to set
the degree of optimization used by the compiler
when generating code for acceleration. The
permitted values are
off. The default is
Enter the following in the Command Window to turn on compiler optimization:
SimCompilerOptimization is set
on in JIT accelerated mode,
the simulation time for some models improves,
while the build time can become slower.
Controlling Verbosity During Code Generation
to display progress information during code
generation. The permitted values are
The default is
Enter the following in the Command Window to turn on verbose build: