Use Parallel Computing for Sensitivity Analysis
Configure Your System for Parallel Computing
To perform global sensitivity analysis, you sample the model parameters and states, define a cost function by creating a design requirement on the model signals, and evaluate the cost function for each sample. Evaluating the model for many samples can be time consuming. You can speed up evaluation in the Sensitivity Analyzer, or at the command line, using parallel computing on multicore processors or multiprocessor networks.
When you evaluate the cost function with the parallel computing option enabled, the software uses the available parallel pool. If none is available, and Automatically create a parallel pool is selected in your Parallel Computing Toolbox™ preferences, the software starts a parallel pool using the settings in those preferences. To open a parallel pool that uses a specific cluster profile, use:
parpool(MyProfile);
MyProfile
is the name of a cluster profile.
For information regarding creating a cluster profile, see Add and Modify Cluster Profiles (Parallel Computing Toolbox).
Model Dependencies
Model dependencies are any referenced models, data such as model variables, S-functions, or additional files necessary to run the model. Before starting the parallel model evaluation, verify that the model dependencies are complete. Otherwise, you may get unexpected results.
Making Model Dependencies Accessible to Remote Workers
When you use parallel computing, the Simulink® Design Optimization™ software helps you identify model dependencies. To do so, the software uses the Dependency Analyzer. The dependency analysis may not find all the files required by your model. To learn more, see Dependency Analyzer Scope and Limitations. If your model has dependencies that are undetected or inaccessible by the parallel pool workers, then add them to the list of model dependencies.
The dependencies are made accessible to the parallel pool workers by specifying one of the following:
File dependencies: the model dependency files are copied to the parallel pool workers.
Path dependencies: the paths to the model dependencies are added to the paths of the parallel pool workers. If you are working in a multi-platform scenario, ensure that the paths are compatible across platforms.
Using file dependencies is recommended, however, in some cases it can be better to choose path dependencies. For example, if parallel computing is set up on a local multi-core computer, using path dependencies is preferred as using file dependencies creates multiple copies of the dependent files on the local computer.
Perform Sensitivity Analysis Using Parallel Computing (GUI)
To perform sensitivity analysis using parallel computing in the Sensitivity Analyzer:
Ensure that the software can access parallel pool workers that use the appropriate cluster profile.
For more information, see Configure Your System for Parallel Computing.
Open the Sensitivity Analyzer for the Simulink model.
Specify the parameter set, generate parameter samples, and specify the requirements for sensitivity analysis. For example, see Design Exploration Using Parameter Sampling (GUI) and Identify Key Parameters for Estimation (GUI).
On the Sensitivity Analysis tab, click Options to open the Evaluation Options dialog box.
Select the Parallel Options tab.
Select the Use the parallel pool during evaluation check box.
This option checks for dependencies in your Simulink model. The file dependencies are displayed in the Model file dependencies list box, and corresponding path to the files in Model path dependencies. The files listed in Model file dependencies are copied to the remote workers.
Note
The automatic dependencies check may not detect all the dependencies in your model.
For more information, see Model Dependencies. In this case, add the undetected dependencies manually.
Add any file dependencies that the automatic check does not detect.
Specify the files in the Model file dependencies list box separated by semicolons or on separate lines.
Alternatively, click Add file dependency to open a dialog box, and select the file to add.
Note
If you do not want to copy the files to the remote workers, delete all entries in the Model file dependencies list box. Populate the Model path dependencies list box by clicking the Sync path dependencies from model, and add any undetected path dependencies. In addition, in the list box, update the paths on local drives to make them accessible to remote workers. For example, change
C:\
to\\\\hostname\\C$\\
.If you modify the Simulink model, resync the dependencies to ensure that any new dependencies are detected. Click Sync file dependencies from model in the Parallel Options tab to rerun the automatic dependency check for your model.
This action updates the Model file dependencies list box with any new file dependency found in the model.
Click OK.
In the Sensitivity Analyzer, click Evaluate to perform sensitivity analysis using parallel computing. The design requirements are evaluated for each combination of parameter values in your parameter set.
Perform Sensitivity Analysis Using Parallel Computing (Code)
To evaluate a model using parallel computing:
Ensure that the software can access parallel pool workers that use the appropriate cluster profile.
For more information, see Configure Your System for Parallel Computing.
Open the model.
Specify the cost function and generate parameter samples for sensitivity analysis. For example, see Design Exploration Using Parameter Sampling (Code).
Enable parallel computing using an evaluation option set.
opt = sdo.EvaluateOptions; opt.UseParallel = true;
Find the model dependencies.
[dirs,files] = sdo.getModelDependencies(modelname)
Note
sdo.getModelDependencies
may not detect all the dependencies in your model. For more information, see Model Dependencies. In this case, add the undetected dependencies manually.Modify
files
to include any file dependencies thatsdo.getModelDependencies
does not detect.files = vertcat(files,'C:\matlab\work\filename.m')
Note
If you do not want to copy the files to the remote workers, add any undetected path dependencies to
dirs
and update the paths on local drives to make them accessible to remote workers. Seesdo.getModelDependencies
for more details.Add the file dependencies for evaluation.
opt.ParallelFileDependencies = files;
Specify the name of the model to be evaluated in parallel.
opt.EvaluatedModel = modelname;
Evaluate the model.
[pOpt,opt_info] = sdo.evaluate(fcn,samples,opt);
Troubleshooting
Why Don’t I See the Evaluation Speed up I Expected Using Parallel Computing?
When you evaluate a model that does not require a large number of evaluations or does not take long to simulate, you might not see a speedup in the evaluation time. In such cases, the overhead associated with creating and distributing the parallel tasks outweighs the benefits of running the evaluation in parallel.
See Also
sdo.evaluate
| sdo.EvaluateOptions
| sdo.getModelDependencies
| parpool
(Parallel Computing Toolbox)