フィルターのクリア

About memory manipulation/speed up program

6 ビュー (過去 30 日間)
C Zeng
C Zeng 2013 年 6 月 13 日
Hi, All,
I am doing a large scale computation problem, and I have several variables, which is large scale (>100MB). I was told that MATLAB will not automatically remove the not used memory in running, is that right?
If so, can I put into the code that "clear -var" to remove it, so that speedup the program? Is there some one who has done this before? What is the effect then?
Thanks.
  1 件のコメント
C Zeng
C Zeng 2013 年 6 月 14 日
Sorry, I may not be very clear on this question. I am doing large scale optimization computation. I am wondering if I remove some unused large variable to make memory efficient, will there a chance to speedup the computing a lot?
Or does someone have done this before? Thanks.

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 14 日
There are some situations in which removing unused large variables could speed up calculations a lot, but if the variables are just sitting in memory without being touched then probably it is not significantly affecting the speed of your calculations.
What hammers speed the most in MATLAB tends to be failing to pre-allocate arrays to reasonable sizes, and then to increase the size of the array on (most or every) iteration.
  6 件のコメント
Walter Roberson
Walter Roberson 2013 年 6 月 15 日
C++ is compiled to machine language. MATLAB is an interpreter. MATLAB Compiler, despite its name, produces an intermediate form that is interpreted. MATLAB Coder processed code is compiled, but MATLAB Coder can only handle a fraction of MATLAB and libraries.
Loops have gotten much better in time in MATLAB.
MATLAB knows how to interface to numeric routines such as BLAS that are highly optimized and potentially multiprocessor (even without the Parallel Computing Toolkit); MATLAB also has some heuristics to decide when it would be faster not to use those numeric libraries. MATLAB is thus potentially quite efficient, depending on what is to be done.
You could write calls to those routines in C++, but it would probably take more work and be less clear. You get a trade-off of development time versus execution time. With fast systems these days, development time is often (but not always) the more expensive over the life-cycle of the program
C Zeng
C Zeng 2013 年 6 月 17 日
Dear Walter, thanks for your comments, I did not mean to hurt Matlab, in stead I like it. I was told that C++ is more faster for large scale problem than MATLAB, and it may be so however the advantage may not be too much.
And yes you are right, the development time is much less in Matlab than C++ and that is why I prefer Matlab.
For the loop, I recently found vectorize the code can largely increase the speed in Matlab. I have not tried parallel toolkit but will do it later. Thanks for your answers!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by