using parallel computing outside a loop

1 visualización (últimos 30 días)
Aref Kalantari
Aref Kalantari el 28 de Sept. de 2020
Comentada: Aref Kalantari el 29 de Sept. de 2020
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 comentario
Aref Kalantari
Aref Kalantari el 28 de Sept. de 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

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by