Proper classification of variables in parfor loop

조회 수: 1 (최근 30일)
Henrik
Henrik 2014년 8월 5일
댓글: Henrik 2014년 8월 6일
Hi there I have a loop that I would like to run with parfor. A simplified version of the code is
parfor qx_index=1:Nsx*Nx
for qy_index=1:Nsx*Nx
chi(qx_index,qy_index,:)=function(other_variables,qx_index,qy_index)
end
end
When I run the code I get the following error:
Error: The variable chi in a parfor cannot be classified.
I cannot figure out why this doesn't work - help?

답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 8월 5일
편집: Sean de Wolski 2014년 8월 5일
What you have above works fine for me (filling in a few of the blanks)...
chi = zeros(2,3);
parfor qx_index=1:2
for qy_index=1:3
chi(qx_index,qy_index,:)=afunction(qx_index,qy_index)
end
end
And
function z = afunction(y,x)
z = y*x;
  댓글 수: 3
Adam
Adam 2014년 8월 5일
There are a number of rules surrounding the functions you can use in a parfor loop. For example you cannot use nested functions or non-transparent functions like eval. Maybe your function does not meet these criteria?
Henrik
Henrik 2014년 8월 6일
Uhuh, it is a rather complicated function, so that might be the issue. On the other hand, it works if I do
for qx_index=1:Nsx*Nx
parfor qy_index=1:Nsx*Nx
chi(qx_index,qy_index,:)=function(other_variables,qx_index,qy_index)
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by