How do I retrieve the pool worker index from an asynchronous parallel function evaluation using MATLAB's parfeval?
Mostra commenti meno recenti
I'm attempting to carry out an iterative algorithm in MATLAB using parallel processing. There exists multiple iterative series that are updated by individual, iterative workers. These workers then send their latest iteration to a DataQueue on an analytics worker. The analytics worker pulls the next update from the queue and updates the analytics accordingly. However, the analytics cannot be updated properly unless the analytics worker knows from which iterative worker the update has been passed.
The following attempt has been made to report an identifier for the worker that is carrying out the asynchronous function evaluation:
for j = 1:20
L(j) = parfeval(gcp, @() labindex, 1);
end
for j = 1:20
[~,idx] = fetchNext(L)
end
function index = labindex()
index = labindex
end
This code reports an idx value of 1 for all evaluations. Is this the correct way of getting the identifier of the worker that is handling the function evaluation? Is there another property that I should be using? Is there some way to create a unique identifier for the worker that is completing the work such that the analytics worker knows which worker computed the next iteration in the series?
Risposte (1)
Edric Ellis
il 30 Ott 2017
The function labindex indicates how many workers are running in parallel only inside an spmd block. However, with parfeval, you can access the task running on the worker by calling getCurrentTask, so you could do:
f = parfeval(@() get(getCurrentTask(), 'ID'), 1)
This will return the index of the task that executed the parfeval request.
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!