필터 지우기
필터 지우기

How to change for loop to parfor loop?

조회 수: 1 (최근 30일)
Ali Baig
Ali Baig 2018년 4월 20일
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?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by