Why am I unable to assign values to matrix blocks like A(10:20,i) inside my PARFOR loop in Parallel Computing Toolbox 4.1 (R2009a) ?

2 views (last 30 days)
I am attempting to modify a block of elements in my matrix within a PARFOR loop using the code below
a = rand(10);
parfor i = 1:4
a(2:4,i) = ones(3,1);
end
However, when I execute the code above, I get the following error
??? Error: The variable A in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
Why do I get this error message?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This error message obtained is the expected behavior when using PARFOR loops in Parallel Computing Toolbox 4.1 (R2009a).
PARFOR loops enforce stringent conditions on variables and expressions that appear in the loop body. As per the documentation of PARFOR, the variable A will be treated as a sliced variable as its value can be broken up into segments, each of which can be operated on separately by different workers.
The rules for indexing a sliced variable clearly state that within the list of indices for a sliced variable, one of these indices is of the form i, i+k, i-k, k+i, or k-i, where i is the loop variable and k is a constant or a simple (nonindexed) variable; and every other index is a constant, a simple variable, colon, or end.
Hence using an index of the form
A(2:4, i)
is not permitted.
If the indices to be extracted are known apriori, the following workaround can be used
A = rand(10, 10);
b = (2:4);
parfor i = 1:4
A(b, i) = ones(3, 1);
end
The above code snippet adheres to the conditions imposed on sliced variables.

More Answers (0)

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!