Sliced variable issue - variable cannot be classified
이전 댓글 표시
Dear All,
I'm trying to use parallel workers in an optimization problem but I cannot define X and Y as sliced variables. X contains the population, Y contains the fitness values. As the error message says: variable X & Y in a parfor cannot be classified.
First I define X, (it has to be outside the parfor loop otherwise I get new X-es in every single loop); than parfor follows:
parfor t=1:T
TmpZ=Func(Z(1,:));TmpX=Func(X(t,:));
if TmpZ < TmpX
X(t,:)=Z(1,:); Y(t,1)=TmpZ;
else
X(t,:)=X(t,:); Y(t,1)=TmpX;
end
end
Thanks
채택된 답변
추가 답변 (1개)
Axel Groniewsky
2019년 5월 7일
댓글 수: 2
Edric Ellis
2019년 5월 7일
This code is not order-independent, and cannot run inside parfor. Basically, the problem is that you're accessing elements of X that might or might not yet have been updated.
Axel Groniewsky
2019년 5월 8일
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!