How to check for number of vacant workers available in a parallel pool?

조회 수: 17 (최근 30일)
Viswanath Hariharan
Viswanath Hariharan 2017년 11월 7일
답변: tommsch 2024년 6월 26일
I have a branch and bound algorithm that needs to be executed in parallel. The main 'if' condition that I need to implement requires me to have the number of vacant workers available in the parallel pool. Numlabs returns total number of workers in the pool. But how to obtain the number of vacant workers available in the pool in both parfor and spmd blocks?
  댓글 수: 2
Edric Ellis
Edric Ellis 2017년 11월 7일
It's not clear to me quite what you're asking for here. At the MATLAB client, you can find out the total number of workers by getting the NumWorkers property of the parallel pool object returned by gcp. Both parfor and spmd execute synchronously - so from the client's perspective, either all workers are busy, or none are.
If you use instead parfeval, then the client is not blocked by the execution on the workers, and there you might want to find out how many workers are currently free. This can be inferred from the properties of the FevalQueue property of the parallel pool.
Viswanath Hariharan
Viswanath Hariharan 2017년 11월 7일
Let's say I have 100 workers to use. I send problems in batches of 4 to be solved. The condition will be that if there are at least 4 workers available, I'll send the next batch of 4. Else I'll wait. What do you think I should be using to accomplish this?

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

답변 (1개)

tommsch
tommsch 2024년 6월 26일
I wrote a quick and dirty function, which returns whether there are workers available for a parfor loop. It can not return the number of workers available, nor do I know how well it works. You can find it on the File Exchange:
https://de.mathworks.com/matlabcentral/fileexchange/168896-can_execute_parfor

카테고리

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