필터 지우기
필터 지우기

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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by