Documentation Center

  • Trials
  • Product Updates

Using Parallel Computing in Optimization Toolbox

Using Parallel Computing with Multicore Processors

If you have a multicore processor, you might see speedup using parallel processing. You can establish a parallel pool of several workers with a Parallel Computing Toolbox™ license. For a description of Parallel Computing Toolbox software, see Getting Started with Parallel Computing Toolbox.

Suppose you have a dual-core processor, and want to use parallel computing:

  • Enter

    parpool

    at the command line. MATLAB® starts a pool of workers using the multicore processor. If you had previously set a nondefault cluster profile, you can enforce multicore (local) computing:

    parpool('local')

      Note:   Depending on your preferences, MATLAB can start a parallel pool automatically. To enable this feature, check Automatically create a parallel pool in Home > Parallel > Parallel Preferences.

    • For command-line use, enter

      options = optimoptions('solvername','UseParallel',true);
    • For Optimization app, check Options > Approximated derivatives > Evaluate in parallel.

When you run an applicable solver with options, applicable solvers automatically use parallel computing.

To stop computing optimizations in parallel, set UseParallel to false, or set the Optimization app not to compute in parallel. To halt all parallel computation, enter

delete(gcp)

Using Parallel Computing with a Multiprocessor Network

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:

  1. Make sure your system is configured properly for parallel computing. Check with your systems administrator, or refer to the Parallel Computing Toolbox documentation.

    To perform a basic check:

    1. At the command line, enter

      parpool(prof)

      where prof is your cluster profile.

    2. Workers must be able to access your objective function file and, if applicable, your nonlinear constraint function file. There are two ways of ensuring access:

      1. Distribute the files to the workers using the parpool AttachedFiles argument. For example, if objfun.m is your objective function file, and constrfun.m is your nonlinear constraint function file, enter

        parpool('AttachedFiles',{'objfun.m','constrfun.m'});

        Workers access their own copies of the files.

      2. Give a network file path to your files. If network_file_path is the network path to your objective or constraint function files, enter

        pctRunOnAll('addpath network_file_path')

        Workers access the function files over the network.

    3. 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.
    • For command-line use, enter

      options = optimoptions('solvername','UseParallel',true);
    • For Optimization app, check Options > Approximated derivatives > Evaluate in parallel.

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 false, or set the Optimization app not to compute in parallel. To halt all parallel computation, enter

delete(gcp)

Testing Parallel Computations

To test see if a problem runs correctly in parallel,

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

  2. Set UseParallel to true, and ensure that there is no parallel pool using delete(gcp). Uncheck Automatically create a parallel pool in Home > Parallel > Parallel Preferences so MATLAB does not create a parallel pool . 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.

  3. Set UseParallel to true, and create a parallel pool using parpool. 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.

Was this topic helpful?