Parallel Code

3 ビュー (過去 30 日間)
Shani Gal
Shani Gal 2012 年 4 月 16 日
コメント済み: hamid 2014 年 9 月 16 日
Hi
Can I run this code in parallel?
A1=F(A1,B1)
A2=F(A2,B2)
F is a function, A1 B1 are unrelated to A2 B2
How can I do this ? ( now it runs one after the other)
Thanks
Shani

回答 (1 件)

Edric Ellis
Edric Ellis 2012 年 4 月 17 日
If you have Parallel Computing Toolbox, you could do this:
% first start up 2 local workers
matlabpool open local 2
% Make cell arrays of inputs
Ain = {A1, A2}; Bin = {B1, B2};
parfor ii=1:2
% Return outputs as a cell array
Aout{ii} = F(Ain{ii}, Bin{ii});
end
  5 件のコメント
Edric Ellis
Edric Ellis 2014 年 9 月 15 日
You should not open and close the pool each time - you should open the pool once and leave it open. Each time the pool opens, you are creating new workers with a fresh random number generator state.
hamid
hamid 2014 年 9 月 16 日
oh yes. thank you. now i can do my work
god bless you

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

カテゴリ

Help Center および File ExchangeParallel Computing Fundamentals についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by