Help with PARFOR in a very simple LOOP
Afficher commentaires plus anciens
parfor k = 1:n
mpc = loadcase(filename); % Loads file case into varaible mpc
mpc.gen(:,2) = ProbMatrix.Prob(:,k);
PercentageOfLoadDistAndPF(:,3)=A(k).*PercentageOfLoadDistAndPF(:,1);
PercentageOfLoadDistAndPF(:,4) = PercentageOfLoadDistAndPF(:,3)./PercentageOfLoadDistAndPF(:,2);
PercentageOfLoadDistAndPF(:,5)=sqrt((PercentageOfLoadDistAndPF(:,4).^2)-(PercentageOfLoadDistAndPF(:,3).^2));
mpc.bus(:,3) = PercentageOfLoadDistAndPF(:,3);
mpc.bus(:,4) = PercentageOfLoadDistAndPF(:,5);
results = runpf(mpc, mpopt);
PFResults(k).Results = results;
end
Doing a probabilistic load flow problem, in where each load flow had a different generator dispatch and load demand. With parfor, I get the following error:
The variable PercentageOfLoadDistAndPF in a parfor cannot be classified.
Quick explanation:
- n equals usually to 2000+, taking 100+ seconds.
- mpc changes every loop from the same file (file NEVER changes).
- mpc.gen(:,2) is loaded with whatever is in ProbMatrix.Prob(:,k) (ProbMatrix.Prob(:,k) NEVER changes)
- PercentageOfLoadDistAndPF is originally a (167,2) matrix (this part never changes) and this loop adds 3 additional columns next to the original 2 with data that depends on the first 2 columns + a A(k) vector (this changes every iteration)
- mpc.bus(:,3) is then loaded with whatever came up in newly made column in PercentageOfLoadDistAndPF(:,3)
- same goes for mpc.bus(:,4) except it uses PercentageOfLoadDistAndPF(:,4) instead of the (:,3)
- mpc then goes into PF program (runpf) and whatever it spits out, it is saved within a struct.Final return is the 1x2000+ struct.
Every iteration of the loop seems to me to be independent of each other...
I apologize in advance for my archaic and non-efficient coding.
3 commentaires
Adam
le 16 Oct 2015
It's a while since I have done analysis of parfor loops and the various errors they give, but I'm pretty sure that having a variable that changes size in the parfor loop is not going to work (or even if it does it is not a good idea).
Try writing the extra columns to a new variable and then concatenate them back into the original after the loop.
Edric Ellis or some other expert on parallel computing can probably give a better answer for you though, that is just a quick observation for a start.
Adam
le 16 Oct 2015
I think also parfor needs the first index of an array to be the one varying in the loop, but I may be wrong on that.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Controller Creation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!