- Launch the pool using the full number of workers
- Divide your code into multiple parfor loops
- Have each parfor loop specify a number of workers to use using the "M" parameter.
Is there a way to change number of worker in a created parpool?
31 次查看(过去 30 天)
显示 更早的评论
Hi,
I have launch a very long simulation wih parfor loop inside. To keep working on my PC, I let one core free. Now that I'm leaving my office, I would like to add a worker on my parallel pool so that all the cores will be used during the night.
Does anyone know if there is a way to change the number of worker in a running parrallel pool?
Can I pause my simulation and enter a command line to change it?
Thanks!
GL.
0 个评论
回答(1 个)
Edric Ellis
2018-12-19
Unfortunately, there is currently no way to increase the number of workers in a parallel pool. One approach that might possibly work for you is to do the following:
For example, you might do something a bit like this:
p = parpool('local');
nw = p.NumWorkers;
for outerLoop = 1:1000
% Simple time-based schedule for how many workers to use
currentHour = hour(datetime);
if currentHour < 8 || currentHour >= 18
% Out of work hours, use all workers
M = nw;
else
% Work hours, don't use all workers
M = nw - 1;
end
parfor (innerLoop = 1:1000, M)
... % do stuff
end
end
2 个评论
Edric Ellis
2018-12-19
Unfortunately, I think my code example is the best that can be achieved for now.
Your other option is to use OS facilities to set the process priority of the workers to be extremely low, and simply use all the workers all the time.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!