Calling sets of INPUTS in a FUNCTION in a PARFOR loop

1 vue (au cours des 30 derniers jours)
Habib
Habib le 15 Mai 2019
Commenté : Habib le 16 Mai 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 commentaire
Jan
Jan le 16 Mai 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

Connectez-vous pour commenter.

Réponse acceptée

Edric Ellis
Edric Ellis le 16 Mai 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by