fetchNext idx always returning 1
조회 수: 3 (최근 30일)
이전 댓글 표시
The documentation says that fetchNext "returns the linear index of that future in array F as idx". Here is my code:
Script experiment.m:
parpool('threads');
f(1:3)=parallel.FevalFuture;
for i=1:3
f(i)=parfeval(@worker, 1, i);
end
for i=1:3
[idx, x]=fetchNext(f(i));
disp(""+idx+" "+x);
end
Function worker.m:
function x = worker(x)
x=x+1;
end
Output:
1 2
1 3
1 4
Why is idx always 1? What am I doing wrong?
댓글 수: 0
채택된 답변
Edric Ellis
2020년 7월 6일
The first output of fetchNext tells you which of the futures you passed in as an input has just completed. In your case, you are calling fetchNext(f(i)) - so you are always calling fetchNext with a single future, therefore the index is always 1.
You should pass all the futures into fetchNext, like this:
for i=1:3
[idx, x]=fetchNext(f);
disp(""+idx+" "+x);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!