Will leftover CPU cores (not used by parfor workers) be used for built-in multithreading?

46 visualizaciones (últimos 30 días)
I have an 8-core CPU with 16 logical cores (hyper-threading). I’m aware that MATLAB’s built-in functions (e.g., min, max, sum, large matrix operations) can use multiple threads internally.
Right now, I need to run several time-consuming tasks in parallel using parfor with the "threads" profile. Typically, I’d start a pool with 8 workers (one per physical core). However, I’m considering creating a pool with only 6 workers, leaving 2 physical cores “free.” My hope is that these 2 leftover cores would be used by each worker’s built-in multithreading, potentially speeding up those internal functions.
My questions are:
  1. If I create a 6-worker pool on an 8-core machine, will the built-in threaded functions inside each worker automatically use the remaining 2 cores?
  2. Does the operating system or MATLAB’s runtime effectively allocate these leftover cores to those functions, or is that not how it works in practice?
The job for each worker does not depend on any other thing.
I’d appreciate any insights or suggestions on finding the right balance between the number of parfor workers and MATLAB’s internal multithreading. Thank you!

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Dic. de 2024 a las 20:11
No, left-over cores will not be automatically used. They will be left for the operating system to run (whatever) on.
If you want more than one core for each worker then you need to use the Cluster Profile Manager to specify a higher "Number of computational threads to use on each worker NumThreads".
However, each worker will use the same number of cores, so the best you could do would be to allocate NumWorkers as 4 and NumThreads as 2.
  3 comentarios
Walter Roberson
Walter Roberson el 23 de Dic. de 2024 a las 20:47
Editting the cluster profile does not have any effect on Threads pool.
I am not certain but I think that Threads pool allocates one core per thread. But possibly they do not explicitly allocate cores and simply leave it up to the operating system to schedule them... constrained to one core at a time.
Lorenco Santos Vasconcelos
Lorenco Santos Vasconcelos el 23 de Dic. de 2024 a las 22:25
Editada: Lorenco Santos Vasconcelos el 23 de Dic. de 2024 a las 22:25
@Walter Roberson, I was a bit puzzled by this because when I start p = parpool("Threads",6), once the parfor starts, all 16 logical cores go to 100%, so I thought that 12 logical cores were doing the parfor iterations and the 4 remaining logical cores were serving these 12 parallel jobs doing the multi-threaded functions.
Just for clarifying: when I call p = parpool("Threads",6), what does really happen? Does 6 physical cores are allocated to perform 6 tasks in parallel and beacuse of hyper-threading, each one has 2 threads?
Or does MATLAB gets 6 physical cores (12 logical cores) and starts doing 12 tasks in parallel?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by