| Contents | Index |
| On this page… |
|---|
If you have a multicore processor, you might see speedup using parallel processing. You can establish a matlabpool of several parallel workers with a Parallel Computing Toolbox license. For a description of Parallel Computing Toolbox software, and the maximum number of parallel workers, see Parallel Computing with MathWorks Products.
Suppose you have a dual-core processor, and want to use parallel computing:
Enter
matlabpool open 2
at the command line. The 2 specifies the number of MATLAB processes to start.
Set your solver to use parallel processing.
| MultiStart | Patternsearch | GA |
|---|---|---|
ms = MultiStart('UseParallel', 'always'); or ms.UseParallel = 'always' | options = psoptimset('UseParallel', 'always', 'CompletePoll', 'on', 'Vectorized', 'off'); | options = gaoptimset('UseParallel', 'always', 'Vectorized', 'off'); |
For Optimization Tool:
| For Optimization Tool:
|
When you run an applicable solver with options, applicable solvers automatically use parallel computing.
To stop computing optimizations in parallel, set UseParallel to 'never', or set the Optimization Tool not to compute in parallel. To halt all parallel computation, enter
matlabpool close
If you have multiple processors on a network, use Parallel Computing Toolbox functions and MATLAB Distributed Computing Server™ software to establish parallel computation. Here are the steps to take:
Make sure your system is configured properly for parallel computing. Check with your systems administrator, or refer to the Parallel Computing Toolbox documentation, or the Administrator Guide documentation for MATLAB Distributed Computing Server.
To perform a basic check:
At the command line, enter
matlabpool open conf
or
matlabpool open conf n
where conf is your configuration, and n is the number of processors you want to use.
If network_file_path is the network path to your objective or constraint functions, enter
pctRunOnAll('addpath network_file_path')so the worker processors can access your objective or constraint files.
Check whether a file is on the path of every worker by entering
pctRunOnAll('which filename')If any worker does not have a path to the file, it reports
filename not found.
Set your solver to use parallel processing.
| MultiStart | Patternsearch | GA |
|---|---|---|
ms = MultiStart('UseParallel', 'always'); or ms.UseParallel = 'always' | options = psoptimset('UseParallel', 'always', 'CompletePoll', 'on', 'Vectorized', 'off'); | options = gaoptimset('UseParallel', 'always', 'Vectorized', 'off'); |
For Optimization Tool:
| For Optimization Tool:
|
After you establish your parallel computing environment, applicable solvers automatically use parallel computing whenever you call them with options.
To stop computing optimizations in parallel, set UseParallel to 'never', or set the Optimization Tool not to compute in parallel. To halt all parallel computation, enter
matlabpool close
To have a patternsearch search function run in parallel, or a hybrid function for ga or simulannealbnd run in parallel, do the following.
Set up parallel processing as described in Multicore Processors or Processor Network.
Ensure that your search function or hybrid function has the conditions outlined in these sections:
patternsearch uses a parallel search function under the following conditions:
CompleteSearch is 'on'.
The search method is not @searchneldermead or custom.
If the search method is a patternsearch poll method or Latin hypercube search, UseParallel is 'always'. Set at the command line with psoptimset:
options = psoptimset('UseParallel','always',...
'CompleteSearch','on','SearchMethod',@GPSPositiveBasis2N);Or you can use the Optimization Tool.


If the search method is ga, the search method option structure has UseParallel set to 'always'. Set at the command line with psoptimset and gaoptimset:
iterlim = 1; % iteration limit, specifies # ga runs
gaopt = gaoptimset('UseParallel','always');
options = psoptimset('SearchMethod',...
{@searchga,iterlim,gaopt});In the Optimization Tool, first create the gaopt structure as above, and then use these settings:

For more information about search functions, see Using a Search Method.
ga and simulannealbnd can have other solvers run after or interspersed with their iterations. These other solvers are called hybrid functions. For information on using a hybrid function with gamultiobj, see Parallel Computing with gamultiobj. Both patternsearch and fmincon can be hybrid functions. You can set options so that patternsearch runs in parallel, or fmincon estimates gradients in parallel.
Set the options for the hybrid function as described in Hybrid Function Options for ga, or Hybrid Function Options for simulannealbnd. To summarize:
If your hybrid function is patternsearch
Create a patternsearch options structure:
hybridopts = psoptimset('UseParallel','always',...
'CompletePoll','on');Set the ga or simulannealbnd options to use patternsearch as a hybrid function:
options = gaoptimset('UseParallel','always'); % for ga
options = gaoptimset(options,...
'HybridFcn',{@patternsearch,hybridopts});
% or, for simulannealbnd:
options = saoptimset('HybridFcn',{@patternsearch,hybridopts});Or use the Optimization Tool.

For more information on parallel patternsearch, see Pattern Search.
If your hybrid function is fmincon:
Create a fmincon options structure:
hybridopts = optimset('UseParallel','always',...
'Algorithm','interior-point');
% You can use any Algorithm except trust-region-reflectiveSet the ga or simulannealbnd options to use fmincon as a hybrid function:
options = gaoptimset('UseParallel','always');
options = gaoptimset(options,'HybridFcn',{@fmincon,hybridopts});
% or, for simulannealbnd:
options = saoptimset('HybridFcn',{@fmincon,hybridopts});Or use the Optimization Tool.

For more information on parallel fmincon, see Parallel Computing for Optimization in the Optimization Toolbox documentation.
![]() | Background | Options Reference | ![]() |

Learn how to use optimization to solve systems of equations, fit models to data, or optimize system performance.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |