using parallel computing outside a loop

1 次查看(过去 30 天)
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 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