Parallel loop variable query

조회 수: 1 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by