# Documentation

## Speed Up Parameter Estimation Using Parallel Computing

### When to Use Parallel Computing for Parameter Estimation

You can use Simulink® Design Optimization™ software with Parallel Computing Toolbox™ software to speed up parameter estimation of Simulink models. Using parallel computing may reduce the estimation time in the following cases:

• The model contains a large number parameters to estimate, and the estimation method is specified as either ```Nonlinear least squares``` or `Gradient descent`.

• The `Pattern search` method is selected as the estimation method.

• The model is complex and takes a long time to simulate.

When you use parallel computing, the software distributes independent simulations to run them in parallel on multiple MATLAB® sessions, also known as workers. The time required to simulate the model dominates the total estimation time. Therefore, distributing the simulations significantly reduces the estimation time.

For information on how the software distributes the simulations and the expected speedup, see How Parallel Computing Speeds Up Estimation.

For information on configuring your system and using parallel computing, see Use Parallel Computing for Parameter Estimation.

### How Parallel Computing Speeds Up Estimation

You can enable parallel computing with the ```Nonlinear least squares```, `Gradient descent` and ```Pattern search``` estimation methods. The following sections describes the potential speedup using parallel computing for estimation:

#### Parallel Computing with Nonlinear least squares and Gradient descent Methods

When you select `Gradient descent` as the estimation method, the model is simulated during the following computations:

• Objective value computation — One simulation per iteration

• Objective gradient computations — Two simulations for every tuned parameter per iteration

• Line search computations — Multiple simulations per iteration

The total time, $Ttotal$, taken per iteration to perform these simulations is given by the following equation:

`$Ttotal=T+\left(Np×2×T\right)+\left(Nls×T\right)=T×\left(1+\left(2×Np\right)+Nls\right)$`

where $T$ is the time taken to simulate the model and is assumed to be equal for all simulations, $Np$ is the number of parameters to estimate, and $Nls$ is the number of line searches. $Nls$ is difficult to estimate and you generally assume it to be equal to one, two, or three.

When you use parallel computing, the software distributes the simulations required for objective gradient computations. The simulation time taken per iteration when the gradient computations are performed in parallel, $TtotalP$, is approximately given by the following equation:

`$TtotalP=T+\left(ceil\left(\frac{Np}{Nw}\right)×2×T\right)+\left(Nls×T\right)=T×\left(1+2×ceil\left(\frac{Np}{Nw}\right)+Nls\right)$`

where $Nw$ is the number of MATLAB workers.

 Note:   The equation does not include the time overheads associated with configuring the system for parallel computing and loading Simulink software on the remote MATLAB workers.

The expected reduction of the total estimation time is given by the following equation:

`$\frac{TtotalP}{Ttotal}=\frac{1+2×ceil\left(\frac{Np}{Nw}\right)+Nls}{1+\left(2×Np\right)+Nls}$`

For example, for a model with `Np=3`, `Nw=4`, and `Nls=3`, the expected reduction of the total estimation time equals $\frac{1+2×ceil\left(\frac{3}{4}\right)+3}{1+\left(2×3\right)+3}=0.6$.

#### Parallel Computing with the Pattern search Method

The `Pattern search` method uses search and poll sets to create and compute a set of candidate solutions at each estimation iteration.

The total time, $Ttotal$, taken per iteration to perform these simulations, is given by the following equation:

`$Ttotal=\left(T×Np×Nss\right)+\left(T×Np×Nps\right)=T×Np×\left(Nss+Nps\right)$`

where $T$ is the time taken to simulate the model and is assumed to be equal for all simulations, $Np$ is the number of parameters to estimate, $Nss$ is a factor for the search set size, and $Nps$ is a factor for the poll set size. $Nss$ and $Nps$ are typically proportional to $Np$.

When you use parallel computing, Simulink Design Optimization software distributes the simulations required for the search and poll set computations, which are evaluated in separate `parfor` loops. The simulation time taken per iteration when the search and poll sets are computed in parallel, $TtotalP$, is given by the following equation:

`$\begin{array}{c}TtotalP=\left(T×ceil\left(Np×\frac{Nss}{Nw}\right)\right)+\left(T×ceil\left(Np×\frac{Nps}{Nw}\right)\right)\\ =T×\left(ceil\left(Np×\frac{Nss}{Nw}\right)+ceil\left(Np×\frac{Nps}{Nw}\right)\right)\end{array}$`

where $Nw$ is the number of MATLAB workers.

 Note:   The equation does not include the time overheads associated with configuring the system for parallel computing and loading Simulink software on the remote MATLAB workers.

The expected speed up for the total estimation time is given by the following equation:

`$\frac{TtotalP}{Ttotal}=\frac{ceil\left(Np×\frac{Nss}{Nw}\right)+ceil\left(Np×\frac{Nps}{Nw}\right)}{Np×\left(Nss+Nps\right)}$`

For example, for a model with `Np=3`, `Nw=4`, `Nss=15`, and `Nps=2`, the expected speedup equals $\frac{ceil\left(3×\frac{15}{4}\right)+ceil\left(3×\frac{2}{4}\right)}{3×\left(15+2\right)}=0.27$.

Using the `Pattern search` method with parallel computing may not speed up the estimation time. When you do not use parallel computing, the method stops searching for a candidate solution at each iteration as soon as it finds a solution better than the current solution. When you use parallel computing, the candidate solution search is more comprehensive. Although the number of iterations may be larger, the estimation without using parallel computing may be faster.