fetchNext idx always returning 1

3 vues (au cours des 30 derniers jours)
Kazi Siddiqui
Kazi Siddiqui le 6 Juil 2020
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?

Réponse acceptée

Edric Ellis
Edric Ellis le 6 Juil 2020
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by