out of memory error

Hi,
I ran a large Monte-Carlo simulation using a loop on a script (not function). After several iterations I got a Out Of Memory error message. I saved the workspace, restarted MATLAB, loaded the saved workspace and modified the loop variable to complete remaining iterations and got the result.
How MATLAB handled this kind of scenario? Why didn't I get any error message when the simulated the remaining segments as I loaded same variables into the RAM?
I need to understand the process badly as I have several other similar simulations to run. Is there any simpler way to get rid of the problem?

5 commentaires

Walter Roberson
Walter Roberson le 31 Août 2013
Were any graphics being constructed?
oblivious
oblivious le 1 Sep 2013
No... no graphics was called. It mostly performed interpolation on a large set of data using interp1
Walter Roberson
Walter Roberson le 1 Sep 2013
Consider using the profiler to see where memory is disappearing. Or if you are on MS Windows, consider displaying the output of "feature memory" (or is it "feature memstats" ?) at chosen locations.
It is possible that you have encountered a bug, but it is also possible that you are encountering fragmented memory, where there is enough total memory but it is in pieces that are individually too small to use.
oblivious
oblivious le 1 Sep 2013
Thanks Mr. Roberson. After analyzing for whole day it appears to me that it is due to fragmented memory. Is there any possible solution to this problem apart from significantly changing my algorithm (i.e. without breaking my variables into smaller pieces)?
Walter Roberson
Walter Roberson le 1 Sep 2013
Memory fragmentation can often be considerably reduced by pre-allocation. If you currently expand any matrix (or vector) within a loop, change that to pre-allocate if you can (and otherwise switch to algorithms that allocate in chunks instead of one row at a time.)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange

Produits

Question posée :

le 31 Août 2013

Community Treasure Hunt

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

Start Hunting!

Translated by