How Statistical Functions Use parfor

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) in
the Parallel Computing Toolbox documentation.

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
in jackknife. Only jackknife runs
in parallel.

The outermost parfor loop is
in userfcn. userfcn uses parfor in
parallel.