fetchNext idx always returning 1

3 visualizaciones (últimos 30 días)
Kazi Siddiqui
Kazi Siddiqui el 6 de Jul. de 2020
Respondida: Edric Ellis el 6 de Jul. de 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?

Respuesta aceptada

Edric Ellis
Edric Ellis el 6 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by