Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

parfeval을 사용하여 백그라운드에서 함수 실행

이 예제에서는 parfeval을 사용하여 백그라운드로 함수를 실행하고 결과가 나오는 대로 수집할 수 있는 방법을 보여줍니다. 이 예제에서 for 루프 안에 여러 Future 요청으로 구성된 벡터를 제출하고 개별 Future 출력값이 나오는 대로 가져올 수 있습니다.

p = gcp();
% To request multiple evaluations, use a loop.
for idx = 1:10
  f(idx) = parfeval(p,@magic,1,idx); % Square size determined by idx
end
% Collect the results as they become available.
magicResults = cell(1,10);
for idx = 1:10
  % fetchNext blocks until next results are available.
  [completedIdx,value] = fetchNext(f);
  magicResults{completedIdx} = value;
  fprintf('Got result with index: %d.\n', completedIdx);
end
 
Got result with index: 1.
Got result with index: 2.
Got result with index: 3.
Got result with index: 4.
Got result with index: 5.
Got result with index: 6.
Got result with index: 7.
Got result with index: 8.
Got result with index: 9.
Got result with index: 10.

관련 항목