Calling sets of INPUTS in a FUNCTION in a PARFOR loop
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 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
Akzeptierte Antwort
Edric Ellis
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!