Nested loops within PARFOR loop
显示 更早的评论
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 个评论
Jan
2012-11-9
"O=0" is really confusing. Please do not use an uppercase "oh" as name of a variable.
回答(1 个)
Jan
2012-11-10
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?!
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!