Documentation Center

  • Trials
  • Product Updates

Contents

How to Use Parallel Computing

Configure Your System for Parallel Computing

You can speed up model optimization using parallel computing on multicore processors or multiprocessor networks. You can use parallel computing with the Design Optimization tool and sdo.optimize. When you optimize the model using parallel computing, the software uses the available parallel pool. If no parallel pool is available and Automatically create a parallel pool is selected in your Parallel Computing Toolbox™ preferences, then the software starts a parallel pool using the settings in those preferences.

When you begin the optimization, the software automatically detects model dependencies and temporarily adds them to the parallel pool workers. However, to ensure that workers are able to access the undetected file and path dependencies, create a cluster profile that specifies the same. The parallel pool used to optimize the model must be associated with this cluster profile. For information regarding creating a cluster profile, see Create and Modify Cluster Profiles in the Parallel Computing Toolbox documentation.

To manually open a parallel pool that uses a specific cluster profile, use:

parpool(MyProfile);

MyProfile is the name of a cluster profile.

Model Dependencies

Model dependencies are any referenced models, data (model variables etc.), S-functions, and additional files necessary to run the model. Before starting the optimization, you must verify that all the remote workers can access the model dependencies. Otherwise, you may get unexpected results.

Making File Dependencies Accessible to Remote Workers

When you use parallel computing, the Simulink® Design Optimization™ software helps you identify model path dependencies. To do so, the software uses the Simulink Manifest Tools. However, the dependency analysis may not find all the files required by your model. For example, folders containing code for your model or block callbacks may not be detected. To learn more, see Scope of Dependency Analysis in the Simulink documentation.

If your model has undetected file dependencies, then specify them in the Files and Folders section of the cluster profile.

If your model has path dependencies that are undetected or inaccessible by the remote workers, then add them to the list of model path dependencies. For more information, see:

Making Data Dependencies Accessible to Remote Workers

You can check whether a model has access to all its data dependencies, such as variables required for model initialization. On your local machine, complete the following steps:

  1. Close the model, and clear the MATLAB® workspace.

  2. Load the model. Verify that only the specified dependencies are accessible to the model.

  3. Simulate the model. If the model errors, a dependency is missing. For example, if a simulation error occurs because a variable is not defined, you can correct the problem in one of the following ways:

    • Add the variable to the model workspace.

    • Create a MATLAB script that creates the variable, and add the file to the list of dependencies. Modify the PreLoadFcn callback of the model to add a call to the MATLAB script.

Optimize Design Using Parallel Computing (GUI)

To optimize a model response using parallel computing in the Design Optimization tool:

  1. 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.

  2. Open the Design Optimization tool for the model.

  3. Configure the design variables, design requirements, and, optionally, optimization settings.

    For more information, see Specify Design Variables, Specify Time-Domain Design Requirements, Specify Frequency-Domain Design Requirements, and Optimization Options.

  4. Open the Parallel Options tab.

    1. In the Design Optimization tool, click Options.

    2. Click the Parallel Options tab.

  5. Select the Use the parallel pool during optimization check box.

    This option checks for model path dependencies in your Simulink model and displays them in the Model path dependencies list box.

      Note:   The automatic path dependencies check may not detect all the path dependencies in your model.

      For more information, see Model Dependencies.

  6. (Optional) Add the path dependencies that the automatic check does not detect.

    Specify the paths in the Model path dependencies list box. You can specify the paths separated with a semicolon or on a new line.

    Alternatively, you can click Add path dependency to open a dialog box, and select the folder to add.

  7. (Optional) In the Model path dependencies list box, update the paths on local drives to make them accessible to remote workers. For example, change C:\ to \\\\hostname\\C$\\.

  8. (Optional) If you modify the Simulink model such that it introduces a new path dependency, then you must resync the path dependencies. Click Sync path dependencies from model in the Parallel Options tab to rerun the automatic dependency check for your model.

    This action updates the Model path dependencies list box with any new path dependency found in the model.

  9. Click OK.

  10. In the Design Optimization tool, click Optimize to optimize the model response using parallel computing.

For information on troubleshooting problems related to optimization using parallel computing, see Troubleshooting.

Optimize Design Using Parallel Computing (Code)

To optimize a model response using parallel computing at the command line:

  1. 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.

  2. Open the model.

  3. Specify design requirements and design variables.

  4. Enable parallel computing using an optimization option set, opt.

    opt = sdo.OptimizeOptions;
    opt.UseParallel = 'always';
  5. Find the model path dependencies.

    dirs = sdo.getModelDependencies(modelname)
  6. (Optional) Modify dirs to include the path dependencies that sdo.getModelDependencies does not detect.

    dirs = vertcat(dirs,'\\hostname\C$\matlab\work')
  7. (Optional) Modify dirs to make paths on local drives accessible to remote workers.

    dirs = regexprep(dirs,'C:/','\\\\hostname\\C$\\')
  8. Add the path dependencies for optimization.

    opt.ParallelPathDependencies = dirs; 
  9. Run the optimization.

    [pOpt,opt_info] = sdo.optimize(opt_fcn,param,opt);

For information on troubleshooting problems related to optimization using parallel computing, see Troubleshooting.

Troubleshooting

Why are the optimization results with and without using parallel computing different?

  • Different numerical precision on the client and worker machines can produce marginally different simulation results. Thus, the optimization method can take a completely different solution path and produce a different result.

  • The client and worker machines must have models in identical states. For example, you must verify that the model running on the client uses exactly the same variable values as the workers. You must also verify that the client and workers are accessing model dependencies in identical states.

  • When you use parallel computing with the Pattern search method, the search is more comprehensive and can result in a different solution.

    To learn more, see Parallel Computing with the Pattern Search Method.

Why do I not see the optimization speedup I expected using parallel computing?

  • When you optimize a model that does not have a large number of parameters or does not take long to simulate, you might not see a speedup in the optimization time. In such cases, the overhead associated with creating and distributing the parallel tasks outweighs the benefits of running the optimization in parallel.

  • Using the Pattern search method with parallel computing might not speed up the optimization time. Without parallel computing, the method stops the search at each iteration when it finds a solution better than the current solution. The candidate solution search is more comprehensive when you use parallel computing. Although the number of iterations might be larger, the optimization without using parallel computing might be faster.

    To learn more about the expected speedup, see Parallel Computing with the Pattern Search Method.

Why does the optimization using parallel computing not make any progress?

In some cases, the gradient computations on the remote worker machines may silently error out when you use parallel computing. In such cases, the Optimization Progress window shows that the f(x) and max constraint values do not change, and the optimization terminates after two iterations with the message Unable to satisfy constraints. To troubleshoot the problem:

  1. Run the optimization for a few iterations without parallel computing to see if the optimization progresses.

  2. Check whether the remote workers have access to all model dependencies. Model dependencies include data variables and files required by the model to run.

    To learn more, see Model Dependencies.

Why does the optimization using parallel computing not stop when I click the Stop optimization button?

When you use parallel computing, the software must wait until the current optimization iteration completes before it notifies the workers to stop the optimization. The optimization does not terminate immediately when you click Stop, and, instead, appears to continue running.

See Also

| | |

Related Examples

More About

Was this topic helpful?