Can I avoid matlab to allocate too much memory?
2 次查看(过去 30 天)
显示 更早的评论
I'm using Matlab R2014b Version 8.3.0.532 on a Linux server and on a Windows desktop. The server is a very resourceful server (24 core, lots of GB of memory,...). The problem is that the same matlab code needs almost 4GB of memory in my 2core Windows-based desktop and more than 20GB of memory in the server. Since the server is shared with other people and I need to run several simulations in parallel, I would like to know why does Matlab ask for more memory in the server and how can I reduce the allocated memory?
At the beginning I thought that the problem was something related with parfor cicles. I did an attempt substituting all the parfor cicles into for circles in the server but the allocated memory is still almost the same value, maybe 2 or 3 GB less, but still too much compared with the Windows case. I also tried to use the same number of workers in both the computers but the problem still remains.
Where do you think is the problem and how I can solve it? Why does Matlab allocate more memory in the server? Thanks
0 个评论
回答(3 个)
Jan
2015-6-4
If a lot of large variables are created, Matlab requests memory from the operating system. When a variable is deleted, the used memory is not free'd immediately, but the operating system can decide, when this happens. Freeing memory causes the clearing of the contents (at least this happens under Windows), such that this needs processing time. Therefore the OS will offer new memory instead of recycling free'd memory, when there is enough free memory available. In consequence the memory usage of Matlab depends on the other applications also and cannot be measured directly.
A strategy to reduce the memory footprint of the code is to avoid the creation of new large variables. See http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/
Med Aymane Ahajjam
2019-10-23
Personnaly, when using app designer, i do not use variables to hold big chunks of data, instead I put the functions that would result in these values directly as inputs to the next functions.. It saves LOTS of time!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!