| Genetic Algorithm and Direct Search Toolbox™ | ![]() |
| On this page… |
|---|
Parallel Evaluation of Populations How to Use Parallel Computing with ga |
Parallel computing is the technique of using multiple processors on a single problem. The reason to use parallel computing is to speed computations.
The Genetic Algorithm and Direct Search Toolbox™ solver ga can automatically distribute the evaluation of objective and nonlinear constraint functions associated with a population to multiple processors. ga uses parallel computing under the following conditions:
You have a license for Parallel Computing Toolbox™ software.
Parallel computing is enabled with matlabpool, a Parallel Computing Toolbox function.
The following options are set using gaoptimset:
Vectorized is 'off' (default)
UseParallel is 'always'
When these conditions hold, the solver computes the objective function and nonlinear constraint values of the individuals in a population in parallel.
Currently, UseParallel cannot be accessed using the Optimization Tool GUI.
If you have a multicore processor, you might see speedup using parallel processing. You can establish a matlabpool of up to 4 parallel workers with a basic Parallel Computing Toolbox license.
Suppose you have a dual-core processor, and wish to use parallel computing:
Enter
matlabpool open 2
at the command line. The 2 specifies the number of processors to use.
Enter
options = gaoptimset('UseParallel','always');When you run an applicable solver with options, applicable solvers automatically use parallel computing.
To stop computing optimizations in parallel, set UseParallel to 'never'. 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:
Obtain a license for Parallel Computing Toolbox functions and MATLAB Distributed Computing Server software.
Configure your system for parallel processing. See the Parallel Computing Toolbox documentation, or MATLAB® Distributed Computing Server™ System Administrator's Guide.
In particular, 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 M-files.
Check whether an M-file is on the path of every worker by entering
pctRunOnAll('which filename')If any worker does not have a path to the M-file, it reports
filename not found.
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 wish to use.
Enter
options = gaoptimset('UseParallel','always');Once your parallel computing environment is established, applicable solvers automatically use parallel computing whenever called with options.
To stop computing optimizations in parallel, set UseParallel to 'never'. To halt all parallel computation, enter
matlabpool close
Population generation is implemented in the ga solver by using the Parallel Computing Toolbox™ function parfor. parfor distributes the evaluation of objective and constraint functions among multiple processes or processors.
The limitations on options, listed in Parallel Evaluation of Populations, arise partly from limitations of parfor, and partly from the nature of parallel processing:
Vectorized determines whether an entire population is evaluated with one function call, instead of having each member of a population evaluated in a loop. If Vectorized is 'on', it is not possible to distribute the evaluation of the function using parfor, since the evaluation is not done in a loop.
More caveats related to parfor are listed in the Limitations section of the Parallel Computing Toolbox documentation.
The Improving Performance with Parallel Computing section of the Optimization Toolbox™ documentation contains information on factors that affect the speed of parallel computations, factors that affect the results of parallel computations, and searching for global optima. Those considerations also apply to parallel computing with pattern search.
Additionally, there are considerations having to do with random numbers that apply to Genetic Algorithm and Direct Search Toolbox functions. Random number sequences in MATLAB® are pseudorandom, determined from a "seed," an initial setting. Parallel computations use seeds that are not necessarily controllable or reproducible. For example, there is a default global setting on each instance of MATLAB that determines the current seed for random sequences.
Parallel population generation gives nonreproducible results. The pseudorandom sequences cannot be guaranteed to be the same on different runs for many reasons:
Other functions running on a processor may use random numbers, changing the generated sequences for ga.
Different processors have different conditions, so they may have different sequences.
The mapping of processor to generated or evaluated individuals may change from run to run.
A hybrid function run after ga may have a different initial condition.
ga may have a hybrid function that runs after it finishes; see Using a Hybrid Function. If you want the hybrid function to take advantage of parallel computation, you must set its options separately so that UseParallel is 'always'. If the hybrid function is patternsearch, there are two other options that must be set so that patternsearch runs in parallel:
Cache must be set to 'off' (default).
CompletePoll must be set to 'on'.
If the hybrid function is fmincon, the following options must be set in order to take advantage of parallel gradient estimation:
The option GradObj must not be set to 'on' — it can be 'off' or [].
Or, if there is a nonlinear constraint function, the option GradConstr must not be set to 'on'— it can be 'off' or [].
To find out how to write options for the hybrid function, see Using a Hybrid Function or Hybrid Function Options.
![]() | Genetic Algorithm Examples | Using the Simulated Annealing and Threshold Acceptance Algorithms | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |