matlab unable to classify variable in parfor loop

조회 수: 1 (최근 30일)
Jacob Thompson
Jacob Thompson 2021년 4월 19일
댓글: Jacob Thompson 2021년 4월 19일
function [a_t,b_t,R_t] = beliefs_updating(a_t1,b_t1,R_t1,x_t,y_t,gain)
a_t = zeros(30,1);
b_t = zeros(30,30);
R_t = zeros(2,2,30);
parfor i = 1:30
a_tt1 = a_t1(i);
b_tt1 = b_t1(i,i);
y_tt = y_t(i);
x_tt = [1 x_t(i)]';
phi_t = [a_tt1 b_tt1]';
R_tt = R_t1(:,:,i);
R_tt = R_tt + gain*(x_tt*x_tt' - R_tt);
phi_t = phi_t + gain*inv(R_tt)*x_tt*(y_tt-phi_t'*x_tt)';
R_t(:,:,i) = R_tt;
a_t(i) = phi_t(1);
b_t(i,i) = phi_t(2);
end
Hi all,
I am trying to parallize the above function. The function above takes a 30x1 vectors a_t1,b_t1,x_t,y_t, a 30x30 matrix b_t, a 2x2x30 array R_t to write a new 30x1 vector a_t, 30x30 matrix b_t, and 2x2x30 array R_t.
I want to save time computing running the matrix inversions in parallel, but I get the error message
Error: File: beliefs_updating.m Line: 16 Column: 5
Unable to classify the variable 'b_t' in the body of the parfor-loop.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 4월 19일
b_t(i,i) = phi_t(2);
The parfor loop control variable can only occur in one index location. Store the contents into a vector and store the vector into the diagonal after the parfor.
b_ti(i) = phi_t(2);
...
end %parfor
b_t = diag(b_ti);
  댓글 수: 1
Jacob Thompson
Jacob Thompson 2021년 4월 19일
I just tried that. The parfor loop works now but now instead of the larger function taking .3 seconds to evaluate it now takes a full 6 seconds. It would appear that this operation cannot be efficiently parallelized.
Bummer

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by