How to change for loop to parfor loop?

10 visualizaciones (últimos 30 días)
Ali Baig
Ali Baig el 20 de Abr. de 2018
Is it possible to execute the following code using parfor loop?
for ii = 1 : 1 : N
x_ref = X(ii); y_ref = Y(ii);
nghlst_Local = nghlst(ii, find(nghlst(ii, :))); Nl = length(nghlst_Local);
x_Local = X(nghlst_Local, 1); y_Local = Y(nghlst_Local, 1);
Phi = ones(Nl+1, Nl+1); Phi(end, end) = 0;
Bx = zeros(Nl+1,1); By = zeros(Nl+1,1); Bxx = zeros(Nl+1,1); Byy = zeros(Nl+1,1);
for jj = 1 : 1 : Nl
for kk = 1 : 1 : Nl
rx = x_Local(jj,1) - x_Local(kk,1);
ry = y_Local(jj,1) - y_Local(kk,1);
Phi(jj, kk) = 1 / sqrt( rx^2 + ry^2 + c^2);
clear rx ry
end
rx = x_ref - x_Local(jj);
ry = y_ref - y_Local(jj);
Bx(jj, 1) = -rx/(rx^2 + ry^2 + c^2)^(3/2);
end
invPhi = inv(Phi);
CX = Bx' * invPhi; CX = CX (1, 1:end-1); Wx (ii, nghlst_Local) = CX;
end
I know nested parfor loops generally give no computational benefits. So, which for loop should I change?

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by