fetchNext idx always returning 1

2 ビュー (過去 30 日間)
Kazi Siddiqui
Kazi Siddiqui 2020 年 7 月 6 日
回答済み: Edric Ellis 2020 年 7 月 6 日
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?

採用された回答

Edric Ellis
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by