フィルターのクリア

How to fully use the CPU of my PC?

162 ビュー (過去 30 日間)
Jianwei Guo
Jianwei Guo 2011 年 11 月 24 日
回答済み: Delprat Sebastien 2024 年 6 月 24 日 13:33
When matlab R2011b is running a program, it only use about 20% CPU. So I'm wondering how could I make it fully use the CPU and thus takes less time to finish the program. Is there an easy way to make this?
  1 件のコメント
Daniel Shub
Daniel Shub 2011 年 11 月 24 日
It really depends on your problem.

サインインしてコメントする。

採用された回答

Daniel Shub
Daniel Shub 2011 年 11 月 24 日
This really depends on what you are doing. For some code MATLAB can only utilize a single core of a single processor, for other code, MATLAB will automatically utilize all available cores (and maybe processors). It really depends on the underlying functions. Some things cannot be easily parallelized. Sometimes you can help MATLAB with things like parfor loops. Other times you might need something like MPI. Still other times there really is nothing you can do.

その他の回答 (3 件)

Jan
Jan 2011 年 11 月 24 日
You do not have any influence on the usage. E.g. if Matlab waits for values from the RAM or the slow harddisk, the processor is on idle. If you have several processor cores, but your program works sequentially, only a few Matlab commands can use more than one core, e.g. FILTER (can somebody confirm this rumor?), MIN, MAX, SUM etc.
The best method to improve the speed is the optimization of the program. A missing pre-allocation can slow down a program tremendously and cause a partial idle of the processor, for example. You can use the profiler to find the bottlenecks and post them here.
  5 件のコメント
Daniel Shub
Daniel Shub 2011 年 11 月 25 日
I think to test this you probably want to start MATLAB with and without the singleCompThread flag.
Jan
Jan 2011 年 12 月 5 日
@Daniel: How could a FILTER operation for a single vector be multi-threaded? The values of each output frame depend on the complete history of the former filtered signal. Therefore I cannot imagine, how this can be distributed to multiple threads.
I expect, that the filtering of a [n x 2] signal needs approximately the same time as filtering two [n x 1] signals on a dual core machine.

サインインしてコメントする。


Michael
Michael 2011 年 11 月 25 日
100% CPU load is not a test that your code is optimised! It is just a sign that the hardware bottleneck may be in your processor.

Delprat Sebastien
Delprat Sebastien 2024 年 6 月 24 日 13:33
There are several answer to optimize code:
  • Always prealocate vectors (do not let an array increase within a loop, prealocate the array before the loop)
  • Vectorize expression as much as possible (i.e. avoid loops and "." operator to perform element-wise operation). Note that conditional logic can be efficiently implemented using logical indexes)
  • Use parallel toolbox to take benefits for all the CPU core. Note that not all the algorithm can be paralelized. Basically, an algorithmn or part of it, can be parallelized if loops iterations can be run in any order.
  • Finally, an "hardcore" optimization consists in assignin matlab to a single core and affecting all the other softwares to other core. This not easy and should only be used for some very specific application. The ratio benefits/trouble is usualy not in favor of this option
Using the profiler is a very good way to find code lines that take most time (and so that should be optimized in priority)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by