- Replace the "for" with "parfor"
- "matlabpool open" before starting
- "matlabpool close" when you're all done
Parfor to speed up loops
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, i have a dual core processor, i wish to make use of parfor to speed up my for loop processing how do i do that? Basically i understand the i have to initialise matlabpool(2) and parfor i=1:NPARTICLES and also matlabpool close.
How do i implement it in my coding? Thanks
if CDiff < ODiff
dt = CDiff;
% Predict step
for i=1:NPARTICLES
particles(i)= predict (particles(i), V,G,Qe, WHEELBASE,dt, SWITCH_PREDICT_NOISE);
end
cIndex = cIndex + 1;
else
dt = ODiff;
z1 = Ob(:,OIndex);
z = cell2mat (z1);
z(1) = z(1)/100;
% Predict step
for i=1:NPARTICLES
particles(i)= predict (particles(i), V,G,Qe, WHEELBASE,dt, SWITCH_PREDICT_NOISE);
end
% Perform update
for i=1:NPARTICLES
[zf,idf,zn]= data_associate(particles(i),z,R);
if ~isempty(zf) % observe map features
w= compute_weight(particles(i), zf,idf, R); % w = p(z_k | x_k)
if w <= 1e-5
w = 1e-5;
end
particles(i).w= particles(i).w * w;
particles(i)= feature_update(particles(i), zf, idf, R);
end
if ~isempty(zn) % observe new features, augment map
particles(i)= add_feature(particles(i), zn,R);
end
end
particles= resample_particles(particles, NEFFECTIVE, SWITCH_RESAMPLE);
dt2 = timestamp(cIndex+1)-Obser_time(OIndex);
for i=1:NPARTICLES
particles(i)= predict (particles(i), V,G,Qe, WHEELBASE,dt2, SWITCH_PREDICT_NOISE);
end
0 件のコメント
回答 (1 件)
Ken Atwell
2012 年 2 月 10 日
You code looks good to go.
But, before you do any of that, in deference to Amdahl's Law, I would be tempted to run this code through the profiler first to be certain that the bits to be parallelized make up a meaningful percentage of the program.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!