Under a 32-bit operating system, where maximum memory allocated to any one program is limited, Mathematica gracefully terminates the kernel and returns a max memory allocation error.
On a 64-bit OS however, Mathematica will freely use all the memory available and grind the system to a halt. Therefore, what is the correct way to cap memory usage? One could use MemoryConstrained
combined with $Pre
or CellEvaluationFunction
but I would rather not tie up either of those for this purpose, or have to modify existing uses to incorporate this function.
Is there another way to globally restrict memory usage, such as a kernel flag, or system $Option?
MemoryConstrained
, but I am looking for a different way to apply it. If you are saying that the operating system should not set a hard limit on a program, I don't understand; I would rather the OS said "MathKernel has used too much RAM and has been terminated. Goodbye" than to lock up the whole system. I realize that true RAM use is not going to be the same as calculated RAM use in many cases, but I can accept that. – Colliery$Pre
approach. – HyadesNETLink
. – UmetotalMemoryConstrained
) here: #6405804 . I have an impression though that this does not always solve the problem. See if this can work for you. – TollefsonJob
functions. But I can refer you to a basicNETLink
Documentation page: "Setting the Kernel Process Priority." You will see that it is really simple to manipulate the kernel process priority. And it is also easy to get information on the kernel current memory usage. In this way, one can write a simple monitoring program which will check how many memory this process currently uses. But probably the idea withJob
objects is much better. – UmeFreeMemoryConstrained
functionality. But it is really very complex and currently works completely correctly only with version 7. I cannot publish it as an answer because it is huge. But I can give some code snippets which demonstrate basic ideas. Please note that it requires running two MathKernel processes: (1) "master" which monitors the current memory usage of (2) "slave" process in which all the target computations are performed. – UmeRunScheduledTask
– Oilcloth