Nested loops within PARFOR loop

5 vues (au cours des 30 derniers jours)
Jeremy
Jeremy le 9 Nov 2012
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 commentaire
Jan
Jan le 9 Nov 2012
"O=0" is really confusing. Please do not use an uppercase "oh" as name of a variable.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 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 commentaire
Jeremy
Jeremy le 12 Nov 2012
Modifié(e) : Jeremy le 12 Nov 2012
This is part of a genetic algorithm to optimize a certain structural analysis problem where pop is the binary population matrix, where I am attempting to retrieve different index values for sd. sd is a definition of different section values (area, moment of inertia, weight) and contributes to the definition of an element. Each index value for sd is defined by a 7 bit byte, of which there are several bytes in each row of pop.
P is used to ensure that the value gotten in c2 is within the dimensions of sd. As any byte could lead to a value greater than the number of rows in sd, I do not want it to try and access a non-existent point in sd.
Thank you for the advice on c1 and c2, I will definitely implement that. Any ideas as to why the parfor loop isn't working?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by