Contenu principal

Parallel Computing with patternsearch

R2026b

Enabling Parallel Computing

patternsearch can automatically distribute the evaluation of objective and constraint functions associated with the points in a pattern to multiple processors. To enable parallel computing:

options = optimoptions("patternsearch",UseParallel="auto",...
    UseVectorized=false);

The requirements are:

  • UseParallel is "auto" or "on".

  • UseVectorized is false (default).

Beginning in R2019a, when you set the UseParallel option to "auto" or "on", patternsearch internally overrides the UseCompletePoll setting to true so that the function polls in parallel. The "nups" algorithms do not use the UseCompletePoll option.

When these conditions hold, the solver computes the objective function and constraint values of the pattern search in parallel during a poll.

Parallel Search Functions

patternsearch can optionally call a search function at each iteration. The search is parallel when you:

  • Set UseCompleteSearch to true.

  • Do not set the search method to @searchneldermead or custom.

  • Set the search method to a patternsearch poll method or Latin hypercube search, and set UseParallel to "auto" or "on".

Example with a poll-based search function:

options = optimoptions("patternsearch",UseParallel="auto",...
    UseCompleteSearch=true,SearchFcn=@GPSPositiveBasis2N);

If the search method is ga, the search method option must have UseParallel set to "auto" or "on":

iterlim = 1; % iteration limit, specifies # ga runs
gaopt = optimoptions("ga",UseParallel="auto");
options = optimoptions("patternsearch",...
    SearchFcn={@searchga,iterlim,gaopt});

For more information about search options, see Search Options. For an example, see Search and Poll.

Parallel Hybrid Function

If you use patternsearch as a hybrid function for ga, particleswarm, or simulannealbnd, set its options for parallel computing:

hybridopts = optimoptions("patternsearch",UseParallel="auto",...
    UseCompletePoll=true);
options = optimoptions("ga",UseParallel="auto",...
    HybridFcn={@patternsearch,hybridopts});

Limitations

  • Cache is overridden. patternsearch overrides the setting of the Cache option to "off" when running in parallel. This is because patternsearch implements Cache as a persistent variable, and parfor does not handle persistent variables across different processors.

  • UseCompleteSearch must be true. When searching in parallel, parfor schedules all evaluations simultaneously, and patternsearch continues after all evaluations complete.

  • UseVectorized must be false. When UseVectorized is true, patternsearch evaluates all points in a pattern with one function call rather than distributing evaluations, so does not use parallel computing.

  • Occasional serial evaluation. Even when running in parallel, patternsearch occasionally calls the objective and nonlinear constraint functions serially on the host machine. Ensure that your functions have no assumptions about whether they are evaluated in serial or parallel.

For information on factors that affect the speed and results of parallel computations, see Improving Performance with Parallel Computing.

See Also

Topics