quick start parallel computing for statistics and machine learning toolbox
note
to use parallel computing, you must have a parallel computing toolbox™ license.
parallel statistics and machine learning toolbox functionality
you can use any of the statistics and machine learning toolbox™ functions with parallel computing toolbox constructs such as parfor
(parallel computing toolbox) and (parallel computing toolbox). however, some functions,
such as those with interactive displays, can lose functionality in parallel. in
particular, displays and interactive usage are not effective on workers (see vocabulary for parallel computation).
additionally, some statistics and machine learning toolbox functions are enhanced to use parallel computing internally. for example, some model fitting functions perform hyperparameter optimization in parallel. for a complete list of statistics and machine learning toolbox functions that support parallel computing, see function list (automatic parallel support). for the usage notes and limitations of each function, see the automatic parallel support section on the function reference page.
how to compute in parallel
this section gives the simplest way to use the enhanced functions in parallel. for
more advanced topics, including the issues of reproducibility and nested
parfor
loops, see the other topics in speed up statistical computations.
for information on parallel statistical computing at the command line, enter
help parallelstats
to have a function compute in parallel:
set up a parallel environment
to run a statistical computation in parallel, first set up a parallel environment.
note
setting up a parallel environment can take several seconds.
for a multicore machine, enter the following at the matlab® command line:
parpool(n)
n
is the number of workers you want to use.
you can also run parallel code in matlab online™. for details, see (parallel computing toolbox).
set the useparallel
option to true
create an options structure with the function. to run in
parallel, set the useparallel
option to
true
:
paroptions = statset('useparallel',true);
call the function using the options structure
call your function with syntax that uses the options structure. for example:
% run crossval in parallel cvmse = crossval('mse',x,y,'predfun',regf,'options',paroptions); % run bootstrp in parallel sts = bootstrp(100,@(x)[mean(x) std(x)],y,'options',paroptions); % run treebagger in parallel b = treebagger(50,meas,spec,'oobpred','on','options',paroptions);
for more complete examples of parallel statistical functions, see , implement jackknife using parallel computing, implement cross-validation using parallel computing, and implement bootstrap using parallel computing.
after you have finished computing in parallel, close the parallel environment:
delete mypool
tip
to save time, keep the pool open if you expect to compute in parallel again soon.