using parallel computing outside a loop

1 view (last 30 days)
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 Comment
Aref Kalantari
Aref Kalantari on 28 Sep 2020
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

Sign in to comment.

Accepted Answer

Raymond Norris
Raymond Norris on 28 Sep 2020
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 Comment
Aref Kalantari
Aref Kalantari on 29 Sep 2020
Thanks Raymond, I have corrected my question. And your answer helped me too with my problem. Thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!