Reduction Assignments in parfor-Loops

What are Reduction Assignments?

Reduction assignments, or reductions, are an exception to the rule that loop iterations must be independent. A reduction variable accumulates a value that depends on all the loop iterations together, but is independent of the iteration order. For a list of supported reduction variables see Reduction Variables.

Multiple Reductions in a parfor-Loop

You can perform the same reduction assignment multiple times within a parfor-loop provided that you use the same data type each time.

For example, in the following parfor-loop, u(i) and v(i) must be the same type.

parfor i = 1:10;
  X = X + u(i);
  X = X + v(i);

Similarly, the following example is valid provided that u(i) and v(i) are the same type.

parfor i=1:10
  r = foo(r,u(i));
  r = foo(r,v(i));