How can I be sure 'parfor' loop iterations are completely independent of each other

1 view (last 30 days)
I am a newbie to parallel computing, however I want to speed up my code using 'parfor' in Matlab's parallel computing. I have nested 'for' loops and want to be sure of a correct result. How can I be sure the inner 'parfor' loop iterations is completely independent of each other loops.
for j = 1:length(w)
j
Kp2 = zeros(length(Kp1),1);
for n = 1:length(Kp1)
Kf2 = zeros(length(Kf1),1);
eta = zeros(length(Kf1),1);
parfor m = 1:length(Kf1)
Kp2(m) = Kp1(n);
Kf2(m) = Kf1(m);
Z_Imp = double(subs(Z,[s Kp Kf Td], [s1(j) Kp2(m) Kf2(m) 0.2]));
eta(m) = -real(Z_Imp(1,2)*Z_Imp(2,1))/abs(Z_Imp(1,2)*Z_Imp(2,1)) + 2*(real(Z_Imp(1,1))*real(Z_Imp(2,2)))/abs(Z_Imp(1,2)*Z_Imp(2,1));
end
Kp_Kf_eta(:,:,n) = [Kp2 Kf2 eta];
end
%%reshape data from [40,3,40] to [1600,3] by stacking [40,3] pages upon each other
temp1 = permute(Kp_Kf_eta, [1,3,2]);
Kp_Kf_eta_w(:,:,j) = reshape(temp1,1600,3);
end

Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!