Error: Unable to classify a variable in the body of the parfor-loop
3 views (last 30 days)
I get the following error when I run the following parallel loop :
2 parfor i=1:kh
6 for futureSamples=1:numFutureSamples
Error: Unable to classify the variable 'out' in the body of the parfor-loop.
This error only occurs for line 8 .
Can anyone help me fix the error?
Edric Ellis on 27 May 2022
Edited: Edric Ellis on 27 May 2022
The problem here is that you've got two different accesses to the variable out. On line 7, you have the valid sliced indexing expression
out(futureSamples,:,i) = ...
The problem is the way that you're reading from out on the following line:
.. out(1:futureSamples,:,i) ...
One of the constraints of parfor is that sliced variables must use the same combination of subscripts everywhere. It's a bit annoying to work around in this case, but something like this should work:
parfor i = 1:kh
% create a temporary matrix that will fill out(:,:,i)
tempOut = zeros(numFutureSamples, numPaths);
tempOut(futureSamples,:) = simulate(..);
intial_vector(:,:,i) = [..; tempOut(1:futureSamples,:)];
out(:,:,i) = tempOut;