Ok I solved my problem now with semaphores, using http://www.mathworks.com/matlabcentral/fileexchange/45504-semaphore-posix-and-windows
How to identify a dedicated (unique) worker in parfor?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a very long running parfor, that regularly should respond to a status request (a marker file exists). I do not want all workers to respond, so I need a way for the workers to decide which one should respond. My idea was to use the Task.ID field and check for the unique smallest currently running ID:
parfor ...
vMyTaskID = GetCurrentTaskID();
[vPendingTasks vRunningTasks vCompletedTasks] = findTask(getCurrentJob());
vMinTaskID = Inf;
for vTaskIdx = 1:length(vRunningTasks)
vMinTaskID = min(vMinTaskID, vRunningTasks(vTaskIdx).ID);
end
if (vMyTaskID == vMinTaskID)
% uniquely respond to the request
else
% print my worker task ID, but do not respond to request
end
end
However it seems sometimes in the parfor, not all tasks that are returned by 'findTask(getCurrentJob())' in vRunningTasks are actually running? At least I see sometimes only task 6 print its ID, but also prints that vRunningTasks would be 1 - 6, so 6 is not the smallest running. But thats not true, 1 - 5 do not print anything, I guess they are not running anymore, maybe they completed the parfor already?
Is there a way to actually find which tasks are really still executing the loop? Or to identify uniquely the task that is currently executing?
Respuestas (0)
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!