| Optimization Toolbox™ | ![]() |
| On this page… |
|---|
Using Parallel Computing with Multicore Processors |
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 = optimset('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 = optimset('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
To test see if a problem runs correctly in parallel,
Try your problem without parallel computation to ensure that it runs properly serially. Make sure this is successful (gives correct results) before going to the next test.
Set UseParallel to 'always', and ensure matlabpool is closed. Your problem runs parfor serially, with loop iterations in reverse order from a for loop. Make sure this is successful (gives correct results) before going to the next test.
Set UseParallel to 'always', and open matlabpool. Unless you have a multicore processor or a network set up, you won't see any speedup. This testing is simply to verify the correctness of the computations.
Remember to call your solver using an options structure to test or use parallel functionality.
![]() | Parallel Computing in Optimization Toolbox Functions | Improving Performance with Parallel Computing | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |