The variable x in a parfor cannot be classified

조회 수: 5 (최근 30일)
Priyabrata Senapati
Priyabrata Senapati 2019년 1월 10일
댓글: Priyabrata Senapati 2019년 1월 10일
When I run this code, I get an error "The variable x in a parfor cannot be classified" that points to x(j,:) in the line sum = sum + A(i,j)*x(j,:);. Can you please suggest what should I do?
parfor i = 2:n
while (j < i)
if (A(i,j) ~= 0)
sum = sum + A(i,j)*x(j,:);
end
j = j+1;
end
end
  댓글 수: 1
KSSV
KSSV 2019년 1월 10일
YOu need not to use a parfor for this. YOu can achieve it stright away by vectorization which would be very fast.

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

답변 (1개)

Edric Ellis
Edric Ellis 2019년 1월 10일
Hm, I didn't see that precise error. I modified your example just a little so that it was actually executable, like so:
n = 4;
A = rand(n);
x = rand(n);
sum = 0; % note 1
parfor i = 2:n
j = 1; % note 2
while (j < i)
if (A(i,j) ~= 0)
sum = sum + A(i,j)*x(j,:);
end
j = j+1;
end
end
A couple of changes:
  1. I set an initial value for sum
  2. You must reset j each time around the parfor loop so that the parfor machinery can tell that you intend j to be a temporary variable (and that you aren't doing anything order-dependent).
  댓글 수: 1
Priyabrata Senapati
Priyabrata Senapati 2019년 1월 10일
Hi, I implemented the changes that you mentioned and I get the same error. The error says that the way I have implemeted x in the sum variable is wrong for parfor. Can you please suggest?

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by