Parallel loop variable query
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Edric Ellis
2013-11-14
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 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!