Giving JLink Huge Memory by Default

13

4

I have noticed that Mathematica makes use of Java by way of JLink, for example, in the extensions such as DatabaseLink and (I think) RLink. It also seems like Java is a first-class citizen for writing our own extensions.

An issue that I almost always run in to is that my data sets are too large for the default Java heap size (-Xmx). Almost all of my notebooks have ReinstallJava at the top, where the maximum Java memory is set to some large fraction of the 256 gigabytes of RAM in my computer. On computers of this size, the default Java setting seems like the 640K memory limit (who could need more than that?)

Sometimes, it seems hard to figure out how to set the Java memory for certain packages (e.g. in RLink, apologies, this could be made into a separate question for that.)

My question: is there a place where I can "hard-wire" the maximum Java memory for a given computer so that I don't need the boiler plate code?

Eric Brown

Posted 2013-07-03T13:14:52.350

Reputation: 4 206

1At the time I started using Mathematica it lived happily within the 4MB constraints of my computer... – Sjoerd C. de Vries – 2013-07-03T13:25:35.710

3For Rlink, there is an option "JRELocation" for InstallR[]. You can use it not just to specify the location of your JRE, but also to enter command-line parameters, in particular those that govern the memory usage limits for JVM. – Leonid Shifrin – 2013-07-03T15:21:28.050

Answers

21

Along the lines of Yamareth's answer, but probably an even better technique, is to put the following into $UserBaseDirectory/Kernel/init.m:

Needs["JLink`"]
SetOptions[InstallJava, JVMArguments->"-Xmx32g"]
SetOptions[ReinstallJava, JVMArguments->"-Xmx32g"]
ReinstallJava[]

By setting the default options, you will get the desired heap size any time you (or any other code you run) calls ReinstallJava in your session.

Todd Gayley

Posted 2013-07-03T13:14:52.350

Reputation: 4 078

4

Place your call to ReinstallJava in init.m file found in $UserBaseDirectory/Kernel.

Ymareth

Posted 2013-07-03T13:14:52.350

Reputation: 4 581