About memory manipulation/speed up program

3 visualizaciones (últimos 30 días)
C Zeng
C Zeng el 13 de Jun. de 2013
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 comentario
C Zeng
C Zeng el 14 de Jun. de 2013
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.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Jun. de 2013
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 comentarios
Walter Roberson
Walter Roberson el 15 de Jun. de 2013
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 el 17 de Jun. de 2013
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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by