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 次查看(过去 30 天)
显示 更早的评论
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!