matlab unable to classify variable in parfor loop

1 visualización (últimos 30 días)
Jacob Thompson
Jacob Thompson el 19 de Abr. de 2021
Comentada: Jacob Thompson el 19 de Abr. de 2021
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Abr. de 2021
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 comentario
Jacob Thompson
Jacob Thompson el 19 de Abr. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by