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

2 ビュー (過去 30 日間)
An Engineer
An Engineer 2022 年 5 月 26 日
コメント済み: An Engineer 2022 年 5 月 27 日
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?

回答 (1 件)

Edric Ellis
Edric Ellis 2022 年 5 月 27 日
編集済み: Edric Ellis 2022 年 5 月 27 日
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
  1 件のコメント
An Engineer
An Engineer 2022 年 5 月 27 日
Hello, thank you for your answer, the error was fixed

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by