Parallel loop variable query

5 ビュー (過去 30 日間)
jnaumann
jnaumann 2013 年 11 月 14 日
コメント済み: jnaumann 2013 年 11 月 14 日
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

採用された回答

Edric Ellis
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
  1 件のコメント
jnaumann
jnaumann 2013 年 11 月 14 日
Thanks. I had preallocated the array but had daftly put it before the PARFOR.
Thanks again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by