Is there a way to limit the amount of time an evaluation is allowed to run? Or limit the amount of memory that MatLab is allowed to take up so it doesn't freeze my laptop?
-
I would have killed for the answer a few years back before I switched to Python. I don't think there is a way though if you don't wait for a few more extra hours/days. – percusse Jun 02 '15 at 17:20
-
@Andre, I'm not sure what you mean. What's swapping and why do i need to disable it? And how? – Raksha Jun 02 '15 at 17:26
1 Answers
Let's answer your questions one at a time:
Question #1 - Can I limit the amount of time MATLAB takes to execute a script?
As far as I know, this is not possible. If you want to do this, you would need a multi-threaded environment where one thread does the actual job while another thread keeps an eye on the timer... but even with that functionality, AFAIK, MATLAB does not have this supported. The only way to stop your script from running is if you punch Ctrl + C / Cmd + C. Depending on what is actually being executed... for example a MEX script or a LAPACK routine, or just a simple MATLAB script, it may work by just pushing it once... or you may have to mash the sequence like a maniac.
(Note: The above image was introduced to try and be funny. If you don't know where that image is from, it's from the movie Flashdance and one of the songs from the soundtrack is She's a maniac, where I've also provided a YouTube link to the song above.)
See this post for more details: How can I interrupt MATLAB when it gets really really busy?
Question #2 - Can we limit the amount of memory that MATLAB uses?
Yes you can. From what I have seen in your posts, you're using Windows. You can change this by changing the page size of the virtual memory that is used for your computer. Specifically, instead of allowing it to grow dynamically, you could set it to be a certain size and once MATLAB exhausts that, it'll give you an out-of-memory error rather than freezing your computer.
See this post from MathWorks forums for more insight:
http://www.mathworks.com/matlabcentral/answers/12695-put-a-limit-on-memory-matlab-uses
Also see this guide from MathWorks on how to handle out-of-memory errors:
http://www.mathworks.com/help/matlab/matlab_prog/resolving-out-of-memory-errors.html
Finally, take a look at this link on how to change / modify the page size of your computer via Windows:
http://windows.microsoft.com/en-ca/windows/change-virtual-memory-size#1TC=windows-7
-
great suggestion, thanks! :] how much memory would you recommend leaving? Right now it says "Total paging file size for all drives: Minimum: 16MB, Recommended 12115 MB, Currently Allocated: 8077MB" and "Space available: 393044MB" – Raksha Jun 02 '15 at 18:24
-
1@Solarmew - From what I have seen, usually between 1.5x to 2x your current RAM is a good rule of thumb... but it depends on a lot of factors. This article from Microsoft has some good things to know when determining the right page size: https://support.microsoft.com/en-us/kb/889654. However, what's important is that you **disable the automatic page growing**, which is the most likely culprit as to why MATLAB freezes. – rayryeng Jun 02 '15 at 18:27