using parallel computing outside a loop

1 回表示 (過去 30 日間)
Aref Kalantari
Aref Kalantari 2020 年 9 月 28 日
コメント済み: Aref Kalantari 2020 年 9 月 29 日
Hi to everyone!
I have to calculate multiple similar inputs with a function that I have written myself and I wondered how i can use parallel computing in this case. I have used parfor in older and other problems already, but i dont know if there are other options to use paralel computing outside loops.
How can I use parallel computing to compute all these simultaneously?
my code is in the comments.
Thanks in advance
  1 件のコメント
Aref Kalantari
Aref Kalantari 2020 年 9 月 28 日
tic
loop_new1 = ImRegbVal(Data_reg,bVec1(segment),0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc
tic
loop_new2 = ImRegbVal(Data_parts2,bVec2,0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc
tic
loop_new3 = ImRegbVal(Data_parts3,bVec3,0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc
tic
loop_new4 = ImRegbVal(Data_parts4,bVec4,0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc
tic
loop_new5 = ImRegbVal(Data_parts4,bVec4,0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc
tic
loop_new6 = ImRegbVal(Data_parts4,bVec4,0); %Plot GUI=1 , No plot GUI = 0 %128*128*2*36
toc

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

採用された回答

Raymond Norris
Raymond Norris 2020 年 9 月 28 日
Hi Aref,
You don't explain how you're already using parfor -- that could negate what else you can do.
Here's a crude example, there's a little cleanup/verifying to do, but it'll get you started in the right direction. Read more about parfeval to see how it can be used.
p = parpool();
dp = {Data_reg,Data_parts2,Data_parts3,Data_parts4,Data_parts4,Data_parts4};
bv = {bVec1(segment),bVec2,bVec3,bVec4,bVec4,bVec4};
% Submit jobs
for idx = 1:length(dp)
f(idx) = parfeval(@ImRegbVal,dp{idx},bv{idx},0);
end
% Fetch results
for idx = 1:length(dp)
[idx, val] = f.fetchNext;
% Do something with loop # 'idx' and loop value 'val'
% ...
end
Raymond
  1 件のコメント
Aref Kalantari
Aref Kalantari 2020 年 9 月 29 日
Thanks Raymond, I have corrected my question. And your answer helped me too with my problem. Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by