Calling sets of INPUTS in a FUNCTION in a PARFOR loop

1 回表示 (過去 30 日間)
Habib
Habib 2019 年 5 月 15 日
コメント済み: Habib 2019 年 5 月 16 日
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 件のコメント
Jan
Jan 2019 年 5 月 16 日
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

サインインしてコメントする。

採用された回答

Edric Ellis
Edric Ellis 2019 年 5 月 16 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by