how to ask for a pool size when using parpool with threads

조회 수: 24 (최근 30일)
Arabarra
Arabarra 2020년 11월 19일
댓글: Rick Amos 2023년 10월 2일
Dear all,
using R2020b, looks like the flag "threads" when using a parpool excludes providing a pool size... is there a reason for that? How can provide an explicite number of workers?
thanks,
Daniel

채택된 답변

Raymond Norris
Raymond Norris 2020년 11월 19일
편집: Raymond Norris 2020년 11월 19일
There isn't from within parpool. When you create a Threads pool, the size of the pool is identical to maxNumCompThreads, which by default is the number of physical cores on the machine.
One workaround is as follows. Assume you have 4 cores and you want a thread pool of 2.
old_thread_count = maxNumCompThreads(2);
p = parpool("threads");
Keep in mind, adjusting maxNumCompThreads could have an impact on other MATLAB functions (though perhaps not since you're now running a pool), so I'd suggest setting it back once you're done with the pool.
p.delete
maxNumCompThreads(old_thread_count);
Is there a particular reason you want to adjust the size?
  댓글 수: 4
Arabarra
Arabarra 2020년 12월 1일
also, sometimes I need to adjust the size for different operations. I can use all my 28threads for a CPU-based job, but immediately after that I need to use a smaller pool to control my 8 GPUS.
Rick Amos
Rick Amos 2023년 10월 2일
As an update to Raymond's answer, we added this capability to thread-based pools in R2022b. For R2022b or later, you can control thread-based pool size directly via parpool:
parpool("threads", 2);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by