Accelerating Model Simulations and Analyses

What Is Acceleration?

Normally, when simulating or analyzing a model in SimBiology®, the model is expressed in MATLAB® code. You can accelerate the simulation by converting the model to
compiled C code, which executes faster. Because this compilation step has a small
time overhead, acceleration is not recommended for individual simulations of small
models. However, for large models, or for repeated simulations during analysis,
acceleration can provide a significant speed increase that outweighs the small time
overhead.

When to Accelerate

The functionality to accelerate simulations performs optimally under the following
conditions:

Running repeated simulations with different initial conditions

Running very long simulations (for example, simulations that take longer
than a minute to run)

Prerequisites for Accelerating Simulations and Analyses

To prepare your models for accelerated simulations, install and set up a
compiler:

Note

On 32-bit Windows® platforms, the LCC compiler is automatically installed.
However, for better performance of the acceleration functionality, you
may want to install a supported compiler other than LCC, and it will be selected
automatically.

On 64-bit Windows platforms, if you have not installed another compiler,
SimBiology uses the LCC64 compiler for model accelerations. If you
have installed another supported compiler, it will be selected
automatically.

Microsoft®
Visual
Studio® 2010 run-time libraries must be available on any computer
running accelerated models generated using Microsoft Windows SDK.

If you plan to redistribute your accelerated models to other
MATLAB users, be sure they have the same run-time
libraries.

Using accelerate

A SimFunction object is automatically accelerated at the
first function execution. Hence it is not necessary to accelerate the model
before you create the object. However, manually accelerate using the accelerate method of the object
if you want it accelerated in your deployment applications.

Accelerate Simulations using SimBiology Model Analyzer

You can enable the model acceleration in the SimBiology Model Analyzer
app by checking the Prepare the model for accelerated
simulation box in the Model step of the
program.

Troubleshooting Accelerated Simulations

If you have custom functions, use persistent variables only for those (constant)
variables that you do not want to recalculate or reload every function call. The
reason is that during the acceleration process, SimBiology converts the model and
custom functions to compiled C code. If you try to use a persistent variable to
share data across generated (or compiled) C functions, you may have different
results. For instance, if you use a persistent variable to count how many times a
function is called, each compiled function will have a separate count. Those
persistent variables in the corresponding compiled functions will be different from
the one used in the MATLAB function that you defined.

If you specify custom functions in SimBiology expressions, you might see the following warning if your code is not
compatible with code generation from MATLAB:

The SimBiology Expression and any user-defined functions
could not be accelerated. Please check that these expressions
and any user-defined functions are supported for code generation
as described in the Code Generation from MATLAB documentation.