working with parfor
how statistical functions use parfor
parfor
is a parallel computing toolbox™ function similar to a for
loop. parallel
statistical functions call parfor
internally.
parfor
distributes computations to worker
processors.
characteristics of parfor
you might need to adjust your code to run in parallel, for example, you need
independent loops and the workers must be able to access the variables. for advice
on using parfor
, see parallel for-loops (parfor) (parallel computing toolbox).
no nested parfor
loops
parfor
does not work in parallel when called from within
another parfor
loop, or from an spmd
block. parallelization occurs only at the outermost level.
suppose, for example, you want to apply jackknife
to your
function userfcn
, which calls parfor
, and
you want to call jackknife
in a loop. the following figure
shows three cases:
the outermost loop is
parfor
. only that loop runs in parallel.the outermost
parfor
loop is injackknife
. onlyjackknife
runs in parallel.the outermost
parfor
loop is inuserfcn
.userfcn
usesparfor
in parallel.
when parfor
runs in parallel
for help converting nested loops to use parfor
, see (parallel computing toolbox).
see also quick start parallel computing for statistics and machine learning toolbox™.