Clear Filters
Clear Filters

Running parallel pools more than CPU physical cores

6 views (last 30 days)
Hussein Ammar
Hussein Ammar on 17 Jun 2020
Answered: Swastik on 23 Aug 2024 at 5:46
Dear all,
I was wondering if running parallel pools more than the number of dedicated physical cores can make a simulation faster or slower. I'm talking about simulations that work on very large data, which I believe requires Matlab to slice the global variables each time before handling them to the parallel workers.
Is there a general rule to follow, and should I always run a number of parallel workers that is equal to the number of physical cores?
Note: usually my computer can run 10 parallel pools, but I can use the following code to run more (it allocates huge amount of RAM, but this is not a problem for me):
c = parcluster('local');
c.NumWorkers = 30;
parpool(c, c.NumWorkers);
Details of machine: CPU: intel core i9-7900X, 330 GHz, RAM size: 64 GB
Best Regards,

Answers (1)

Swastik
Swastik on 23 Aug 2024 at 5:46
The number of workers being used in MATLAB can significantly affect your simulation time, especially in parallel computing tasks. Using more or fewer workers than the number of physical cores can impact performance. Each worker adds memory overhead, which can become a bottleneck based on the memory usage of individual tasks.
For instance, the "parfor" function spawns one MATLAB process per worker in the cluster in "no-display" mode. Although the startup time of these processes adds to the execution time, it only occurs once.
Typically, Operating system assigns each worker to a CPU core. However, if a core is heavily loaded, two workers might compete for scheduling on a single core, leading to context switches between worker processes. While context switching is not inherently detrimental to execution time, problems arise when the time spent switching is significant compared to the actual process execution time.
Therefore, a general rule is to set the number of workers equal to the number of physical cores. Using fewer workers underutilizes the CPU, while using more may increase context switches, depending on the CPU load.
It is possible that for certain tasks and CPU conditions, assigning more workers than physical cores could enhance performance. Ultimately, it depends on the specific task at hand.
I have developed a MATLAB script (attached) that performs a computationally intensive, parallelizable task. The script measures execution time for varying numbers of workers and plots the results to visualize how execution time changes with respect to the number of workers. Below image shows one run of the attached MATLAB script, the blue circle is the point that shows the lowest execution time.
In my tests, the optimal number of workers for this task was between 10-15, which exceeds my physical core count of 10. This suggests that, depending on the task, using more workers than physical cores can enhance performance.
For more details on recommended number of workers in MATLAB, you can refer to this answer too:

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!