Nested loops within PARFOR loop
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 9 Nov 2012
"O=0" is really confusing. Please do not use an uppercase "oh" as name of a variable.
Answers (1)
Jan
on 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?!
See Also
Categories
Find more on Loops and Conditional Statements 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!