working with parfor -凯发k8网页登录

main content

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:

  1. the outermost loop is parfor. only that loop runs in parallel.

  2. the outermost parfor loop is in jackknife. only jackknife runs in parallel.

  3. the outermost parfor loop is in userfcn. userfcn uses parfor 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™.

网站地图