Error: Unable to classify a variable in the body of the parfor-loop

2 visualizaciones (últimos 30 días)
An Engineer
An Engineer el 26 de Mayo de 2022
Comentada: An Engineer el 27 de Mayo de 2022
Hi
I get the following error when I run the following parallel loop :
1 out(1:numFutureSamples,1:numPaths,1:kh)=0;
2 parfor i=1:kh
3 estModel(i)=estimate(model(i),DATA);
4 res(:,i)=infer(estModel(i),DATA);
5 initial_vector(:,:,i)=repmat(DATA,1,numPaths);
6 for futureSamples=1:numFutureSamples
7 out(futureSamples,:,i)=simulate(estModel(i),1,'Y0',initial_vector(:,:,i),'NumPaths',numPaths,'E0',res(:,i));
8 initial_vector(:,:,i)=[repmat(DATA(futureSamples+1:end,1),1,numPaths);out(1:futureSamples,:,i)];
9 end
10 end
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?

Respuestas (1)

Edric Ellis
Edric Ellis el 27 de Mayo de 2022
Editada: Edric Ellis el 27 de Mayo de 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
% stuff...
% create a temporary matrix that will fill out(:,:,i)
tempOut = zeros(numFutureSamples, numPaths);
for futureSamples=1:numFutureSamples
tempOut(futureSamples,:) = simulate(..);
intial_vector(:,:,i) = [..; tempOut(1:futureSamples,:)];
end
out(:,:,i) = tempOut;
end

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by