Parallel loop variable query
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Good morning,
I am trying to run a genetic algorithm to find the best parameters for a denoising a signal using ALE. I have the code running fine but takes a long time so I am trying to run a part of it using parallel loops this is my code currently.
parfor i=1:pop_size
child=gen(i,:);
for m=1:9
ch3=ch_all(m,:);
ntr = child(3)*floor((length(ch3)-child(1))/child(3));
x = ch3(1:ntr);
d = ch3(1+child(1):ntr+child(1));
leak = 1; % No leakage
h = adaptfilt.blms(child(2),child(4),leak,child(3));
[y,e] = filter(h,x,d);
[ps p f]=best_processing(e, Fs, 14.9,child(5));
percent_inc(m)=ps;
end
percent_ave=median(percent_inc);
percent_diff(i)=sum(percent_ave)
end
I get the following warning - Parfor will not run due to the way the variable 'percent_inc' is used. Can anyone tell me why this is or what must be done to amend the code? As far as I can see the code isn't dependent on anything outside the loop and i have preallocated the variable before the loop. Any help will be greatly appreciated,
Thanks
Jack
0 commentaires
Réponse acceptée
Edric Ellis
le 14 Nov 2013
PARFOR currently thinks you're re-using values in percent_inc from one iteration of the PARFOR loop to the next. You can fix this simply be pre-allocating percent_inc (a good idea anyway) like so:
parfor i=1:pop_size
...
percent_inc = zeros(1, 9);
for m = 1:9
...
percent_inc(m) = ...;
end
...
end
Plus de réponses (0)
Voir également
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!