using parallel computing outside a loop

1 visualizzazione (ultimi 30 giorni)
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 Commento
Aref Kalantari
Aref Kalantari il 28 Set 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

Accedi per commentare.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by