Calling sets of INPUTS in a FUNCTION in a PARFOR loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
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 Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!