User`s guide

Sliced Variables
2-27
Sliced Variables
A sliced variable is one whose value can be broken up into segments, or slices, which
are then operated on separately by different workers. Each iteration of the loop works
on a different slice of the array. Using sliced variables is important because this type of
variable can reduce communication between the client and workers. Only those slices
needed by a worker are sent to it, and only when it starts working on a particular range
of indices.
In the this example, a slice of A consists of a single element of that array:
parfor i = 1:length(A)
B(i) = f(A(i));
end
Characteristics of a Sliced Variable
A variable in a parfor-loop is sliced if it has all of the following characteristics. A
description of each characteristic follows the list:
Type of First-Level Indexing — The first level of indexing is either parentheses, (), or
braces, {}.
Fixed Index Listing — Within the first-level parenthesis or braces, the list of indices
is the same for all occurrences of a given variable.
Form of Indexing — Within the list of indices for the variable, exactly one index
involves the loop variable.
Shape of Array — The array maintains a constant shape. In assigning to a sliced
variable, the right-hand side of the assignment cannot be [] or '', because these
operators attempt to delete elements.
Type of First-Level Indexing. For a sliced variable, the first level of indexing is enclosed in
either parentheses, (), or braces, {}.
This table lists the forms for the first level of indexing for arrays sliced and not sliced.
Reference for Variable Not Sliced Reference for Sliced Variable
A.x A(...)
A.(...) A{...}