Calling sets of INPUTS in a FUNCTION in a PARFOR loop

1 visualización (últimos 30 días)
Habib
Habib el 15 de Mayo de 2019
Comentada: Habib el 16 de Mayo de 2019
Hu guys!
I have here a function that runs for 40 mins and I would like to run it for 3 different sets of inputs, or a 2 hours waiting time...
output1 = function(graph1, Matrix11, Matrix12) %40 mins
output2 = function(graph2, Matrix21, Matrix22) %40 mins
output3 = function(graph3, Matrix31, Matrix32) %40 mins
I know that I can divide this time if I use multiple cores, one for each function.
So, my initial idea was to creat a variable that stores the 3 sets of inputs and to call them in a parfor loop (the output is a vector):
input(1) = graph1, Matrix11, Matrix12
input(2) = graph2, Matrix21, Matrix22
input(3) = graph3, Matrix31, Matrix32
parfor 1 = 1:3
output(:,i) = function(input(i))
end
But I don't really know how to do that. Moreover, storing graphs and matrices in a same variable isn't possible (I think).
Can someone help me please? :)
  1 comentario
Jan
Jan el 16 de Mayo de 2019
The trick is to use arrays instead of hiding the indices in the names of the variables. See TUTORIAL: Why and how to avoid Eval

Iniciar sesión para comentar.

Respuesta aceptada

Edric Ellis
Edric Ellis el 16 de Mayo de 2019
Did you try something like this:
graphs = {graph1, graph2, graph3};
Matrix1s = {Matrix11, Matrix21, Matrix31};
Matrix2s = {Matrix12, Matrix22, Matrix32};
parfor i = 1:3
output{i} = function(graphs{i}, Matrix1s{i}, Matrix2s{i});
end

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by