Extract variable from function after using parfeval

조회 수: 9 (최근 30일)
Koren Murphy
Koren Murphy 2022년 8월 12일
댓글: Raymond Norris 2022년 8월 16일
I am running the following:
fcn=@(i) run("test"+i);
for K=1:4
F(K)=parfeval(fcn,0,K);
end;
where "test"+i is a script solving to pricude results in matrix format.
I would like to be able to see this matrix after the worker has finished.
I have tried setting the cript as a fucntion and having an outout:
function [Result1]= test1
however I still get no data out of this after using fetchOutputs.
How can i get the variable I require after parfeval has finished?
  댓글 수: 2
Abderrahim. B
Abderrahim. B 2022년 8월 12일
Did you check if the worker has finished the processing?
Koren Murphy
Koren Murphy 2022년 8월 12일
Yes it has

댓글을 달려면 로그인하십시오.

답변 (1개)

Raymond Norris
Raymond Norris 2022년 8월 12일
@Koren Murphy the issue is that you've told MATLAB there are no output arguments (even if there are)
F(K)=parfeval(fcn,0,K);
The "0" is the number of output arguments. Change this appropriately. For instance
for idx = 1:10
f(idx) = parfeval(@rand,1,idx);
end
% Now fetch the results
for idx = 1:10
[idx, value] = fetchNext(f);
R{idx} = value;
end
  댓글 수: 2
Koren Murphy
Koren Murphy 2022년 8월 16일
fcn=@(i) run("test_"+i);
for idx = 1:4
f(idx) = parfeval(fcn,1,idx);
end
% Now fetch the results
for idx = 1:4
[idx, value] = fetchNext(f);
R{idx} = value;
end
I know have this with fucntions defiend as
function [testRes1]= test_1
However, i now get this error....
Error using parallel.FevalFuture/fetchNext
The function evaluation completed with an error.
Error in EFM_MILP_Parallel_DataSetUp (line 43)
[idx, value] = fetchNext(f);
Caused by:
Error using EFM_MILP_Parallel_DataSetUp>@(i)run("EFMLoop_"+i)
Too many output arguments.
Raymond Norris
Raymond Norris 2022년 8월 16일
The run command doesn't return any outputs. Presumable this is a test example. Replace it with the function you're going to actually run.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by