Nested loops within PARFOR loop
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having issues using parfor. Getting the following error: The PARFOR loop cannot run due to the way variable 'ed' is used.
ed is some nm by 6 matrix that I am trying to fill in with certain values. BIN is a vector used to convert from binary to decimal.
If anyone has used PARFOR for parallel computing and could help it would be greatly appreciated (trying to reduce the run time which is currently at ~4 hrs).
Thanks,
-Jeremy
parfor i=1:popSize
O=0;
for j=1:nm
for k=1:ng
if edi(j,4)==k && pop(i,(k*7-6):(k*7))*BIN<=nsd && pop(i,(k*7-6):(k*7))*BIN~=0
ed(j,4:6)=sd(pop(i,(k*7-6):k*7)*BIN,2:4);
elseif pop(i,(k*7-6):(k*7))*BIN>nsd || pop(i,(k*7-6):(k*7))*BIN==0
O=1;
break
end
end
end
end
1 Kommentar
Jan
am 9 Nov. 2012
"O=0" is really confusing. Please do not use an uppercase "oh" as name of a variable.
Antworten (1)
Jan
am 10 Nov. 2012
Please use the profiler to find the bottlenecks. What is sd and pop?
Avoid calculating pop(i,(k*7-6):k*7)*BIN 4 times: Store the value in a temporary variable instead:
for i=1:popSize
P = 0;
for j=1:nm
c1 = edi(j, 4);
for k=1:ng
c2 = pop(i,(k*7-6):(k*7))*BIN;
if c1 == k && c2 <=nsd && c2 ~= 0
ed(j, 4:6) = sd(c2, 2:4);
elseif c2 > nsd || c2 == 0
P = 1;
break
end
end
end
end
Do you need "P" anywhere?!
1 Kommentar
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!