- open the parpool explicitly instead of waiting for it to be open automatically
- write your code so that it does not pass any variables into or out of the parfor loop, so that no memory needs to be transfered between processes
- write your parfor code so that it does not do any file I/O or interaction with any device
how I can run my CPU at 100% usage with parfor loop?
14 views (last 30 days)
Show older comments
K. Taieb
on 13 Jul 2020
Commented: Walter Roberson
on 13 Jul 2020
Hello,
I have a Matlab program where I use a parallel for-Loops (6 workers). The Computation time is fast compared to using for loop, but during the calculation, when I verify the performance I found that the program only uses about 60% -70 % of CPU. How to fully use the CPU of my PC?
Thank you
0 Comments
Accepted Answer
Walter Roberson
on 13 Jul 2020
To fully use the CPUs with parfor
In other words, to get 100% CPU, it will be necessary for you to write code that does nothing useful, wasting its time doing calculations that it never reports the results of in any way.
If you want to get results back from the parfor workers, then you cannot get 100% CPU.
The less data that you transfer, for the longer computation per iteration, the closer you can get to 100% CPU.
3 Comments
Walter Roberson
on 13 Jul 2020
At the very least, send as little to disk as you can. That can include using compression methods in memory and writing out the compressed version. The data you write out in the parfor loop does not need to be in image format: you can run a cleanup loop afterwards.
Oh yes: for maximum efficiency, have each worker output to a different disk controller (not just a different disk for the same controller -- that that is better than using the same disk for all output files.) Disk I/O is relatively slow, and you are going to encounter disk contention.
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) 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!