Parpool threads killed when scaling up
9 views (last 30 days)
Show older comments
Chern Hui Lee
on 29 Oct 2021
Commented: Chern Hui Lee
on 31 Oct 2021
In my script, I have a big custom function in a loop, in each loop this function is called with different parameters. So I try to use parpool('threads') and parfeval to calculate the result ahead of time, and then just retrieve the result in each loop to speed up the total calculation. This is all good, until I increase the size of the matrix in my custom function.
I run Matlab using "matlab -nodisplay". When I increase the size of the matrix slowly, beyond a certain point, I would just see the following:
Killed
and Matlab is quit. How do I know what went wrong? Is the matrix too big and I run out of memory? I verified that the custom function itself runs fine with the big size of matrix.
My computer has 8 cores, when I run parpool('threads'), it gives me a pool of 8 workers. If it's a memory issue, can I reduce the number of workers? Because I do not think I need that many workers to achieve the speed, but I can't find a way to reduce the number of workers when using parpool('thread'). Or should I move to process-based parallel computing, instead of thread-based?
Thanks.
0 Comments
Accepted Answer
Steven Lord
on 29 Oct 2021
What operating system? If you're running on Linux, check if MATLAB got killed by the out of memory killer.
More Answers (1)
Walter Roberson
on 29 Oct 2021
Unfortunately, R2020a's parpool('threads') and R2021b's backgroundPool() do not permit you to configure the number of threads to use, so running out of memory is a possibility.
4 Comments
Raymond Norris
on 30 Oct 2021
Notice the following:
>> nt = maxNumCompThreads(2)
nt =
4
>> parpool("threads");
Starting parallel pool (parpool) ...
Connected to the parallel pool (number of workers: 2).
This shows I have 4 cores and that by calling maxNumCompThreads with2, parpool starts a thread-based pool of 2 workers. They caviat -- until you set maxNumCompThreads back to 4, all other code will also only use 2 threads. Then again, you could make the argument that's idea (if not actually setting it to 1), since the parallel pool may now be running on 2 cores. I wonder if a better internal algorhim would be something like
>> new = 3;
>> old = maxNumCompThreads(new);
>> pool = parpool("threads");
Starting parallel pool (parpool) ...
Connected to the parallel pool (number of workers: 3).
>> maxNumCompThreads(max(old-new,1))
This way MATLAB has at least 1 comp thread, but otherwise, the comp threads and the parpool theads equal the total number of cores seen.
Going back to the OP, a local process-based pool won't perform better than a thread-based pool. I emphasize local because certainly you could span a process-based pool across multiple nodes with MATLAB Parallel Server that has access to more memory, etc., whereas a thread-based pool is bound to a single node.
Secondly, I don't see how reducing the number of threads/processes will help. You're justing giving more work/memory to each process. As was seen, the best option is to get onto a machine with more memory.
See Also
Categories
Find more on Parallel Computing Fundamentals 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!