Parallel Computing with patternsearch
R2026bEnabling 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:
UseParallelis"auto"or"on".UseVectorizedisfalse(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
UseCompleteSearchtotrue.Do not set the search method to
@searchneldermeadorcustom.Set the search method to a
patternsearchpoll method or Latin hypercube search, and setUseParallelto"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.
patternsearchoverrides the setting of theCacheoption to"off"when running in parallel. This is becausepatternsearchimplementsCacheas a persistent variable, andparfordoes not handle persistent variables across different processors.UseCompleteSearch must be true. When searching in parallel,
parforschedules all evaluations simultaneously, andpatternsearchcontinues after all evaluations complete.UseVectorized must be false. When
UseVectorizedistrue,patternsearchevaluates 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,
patternsearchoccasionally 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.