Why patternsearch cost more time and CPU usage is high when I set use parallel to true?
1 view (last 30 days)
Show older comments
The patternsearch cost about 20s and the CPU usage is always less than 20% if I set the UseParallel to false, but when I set the UseParallel to true(as well as setting CompleteSearch and CompletePoll to 'on'), Matlab start parallel poor with 8 workers, the CPU usage becomes higher than 60%, and looks like all of the CPU core are working hard, but it takes more time(about 40s) for each run.
This is the result without UseParallel.
Elapsed time is 0.000044 seconds.
Elapsed time is 0.000028 seconds.
Elapsed time is 0.000083 seconds.
Elapsed time is 0.000034 seconds.
Elapsed time is 0.000431 seconds.
Elapsed time is 0.000030 seconds.
Elapsed time is 0.000007 seconds.
Elapsed time is 0.000007 seconds.
Elapsed time is 0.000004 seconds.
Elapsed time is 0.000005 seconds.
Elapsed time is 0.000005 seconds.
Elapsed time is 0.000005 seconds.
Elapsed time is 0.000010 seconds.
Elapsed time is 0.000005 seconds.
Elapsed time is 0.000005 seconds.
Elapsed time is 0.666903 seconds.
Elapsed time is 0.983121 seconds.
Elapsed time is 0.940569 seconds.
Elapsed time is 0.602256 seconds.
Elapsed time is 19.925943 seconds.
Elapsed time is 21.314532 seconds.
Elapsed time is 21.272933 seconds.
Elapsed time is 22.155922 seconds.
Elapsed time is 21.726156 seconds.
Elapsed time is 21.442130 seconds.
Elapsed time is 21.694592 seconds.
Elapsed time is 22.623227 seconds.
Elapsed time is 22.415195 seconds.
Elapsed time is 22.379827 seconds.
Elapsed time is 22.372377 seconds.
Elapsed time is 22.481904 seconds.
Elapsed time is 23.710251 seconds.
Elapsed time is 21.792068 seconds.
Elapsed time is 22.587905 seconds.
Elapsed time is 21.904669 seconds.
This is the result with UseParallel
Elapsed time is 0.000040 seconds.
Elapsed time is 0.000026 seconds.
Elapsed time is 0.000028 seconds.
Elapsed time is 0.000027 seconds.
Elapsed time is 0.000180 seconds.
Elapsed time is 0.000027 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000004 seconds.
Elapsed time is 0.000003 seconds.
Elapsed time is 0.000004 seconds.
Starting parallel pool (parpool) using the 'local' profile ...
connected to 8 workers.
Elapsed time is 78.035708 seconds.
Elapsed time is 9.433821 seconds.
Elapsed time is 5.835379 seconds.
Elapsed time is 4.940124 seconds.
Elapsed time is 75.678633 seconds.
Elapsed time is 44.992872 seconds.
Elapsed time is 37.858397 seconds.
Elapsed time is 42.223771 seconds.
Elapsed time is 41.447901 seconds.
Elapsed time is 37.771911 seconds.
Elapsed time is 39.778794 seconds.
Elapsed time is 37.504070 seconds.
Elapsed time is 36.679380 seconds.
Elapsed time is 36.572724 seconds.
Elapsed time is 42.711480 seconds.
Elapsed time is 35.923882 seconds.
Elapsed time is 34.193884 seconds.
Elapsed time is 38.180197 seconds.
Elapsed time is 36.205004 seconds.
Elapsed time is 36.022253 seconds.
Elapsed time is 32.847637 seconds.
0 Comments
Answers (1)
Yash
on 13 Nov 2023
Hi Zhou,
I understand that using parallel computing in your program is resulting in slower code execution compared to when it's turned off. This could be due to the additional time required to establish the parallel pool and divide the computations among multiple workers. Another possibility is that the problem size is not significant enough to gain advantages from parallelization.
One thing you can try is increasing the problem size to examine if parallelization becomes more beneficial. Additionally, you can experiment with modifying the number of workers to determine if this boosts performance. To determine the optimal number of workers for your problem, you can use the "parpool" function to create a parallel pool with different numbers of workers and measure the performance of your code with each configuration. You can then choose the number of workers that provides the best performance.
You can refer to this documentation to know more about the "parpool" function: https://in.mathworks.com/help/parallel-computing/parpool.html
Hope it helps!
0 Comments
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!