How to reduce the number of workers in the backgroundPool?
7 次查看(过去 30 天)
显示 更早的评论
I would like to limit the backgroundPool to 2 workers. But when I restart my computer, then open MATLAB, then run the following code I get 10 workers. Is there anyway to reduce the number of backgroundPool workers? Thanks in advance!
Input:
maxNumCompThreads(1)
backgroundPool
Output:
>> maxNumCompThreads(1)
ans =
6
>> backgroundPool
ans =
BackgroundPool with properties:
NumWorkers: 10
Busy: false
3 个评论
Walter Roberson
2024-3-1
If you parfeval() exactly two functions, then the memory will not build up.
回答(1 个)
Monisha
2024-3-2
delete(gcp('nocreate')); % Delete any existing parallel pool parpool(2); % Create a new parallel pool with 2 workers
This code will delete any existing parallel pool and create a new one with only 2 workers. Place this code at the beginning of your script or function to ensure that it's executed whenever MATLAB starts. This should help you maintain the desired number of workers even after restarting your computer and reopening MATLAB.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programming Utilities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!