Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mathematica & J/Link: Memory Constraints?

I am doing a computing-intensive benchmark using Mathematica and its J/Link Java interface.

The benchmark grinds to a halt if a memory footprint of about 320 MB is reached, since this seems to be the limit and the garbage collector needs more and more time and will eventually fail.

The Mathematica function ReinstallJava takes the argument command line. I tried to do

ReinstallJava[CommandLine -> "java -Xmx2000m ..."]

but Mathematica seems to ignore the -Xmx option completely.

How can I set the -Xmx memory option for my java program? Where does the limit of 320 MB come from? Any help would be greatly appreciated.

like image 965
D-Bug Avatar asked Jun 14 '09 14:06

D-Bug


People also ask

What is Mathematica used for?

Mathematica is a mathematical computation program used in many scientific, engineering, mathematical, and computing fields. Unlike other systems, Mathematica applies intelligent automation in every part of the system, from algorithm selection to plot layout and user interface design.

Is Mathematica for free?

Free online access to The Mathematica Journal is available through Wolfram Premier Support.

What is Mathematica vs MATLAB?

Mathematica is developed to write mathematical functions in simple and convenient syntax. Matlab is designed to do parallel computation to do operations in vectored form. Mathematica uses a computer algebra system. Matlab uses two-dimensional array systems.

Which is best Mathematica or MATLAB?

Development in Mathematica is fast compared to MATLAB. Syntax is initially required to learn to perform calculations in MATLAB. Calculations are done by using simple mathematics. MATLAB documentation is very understandable.


1 Answers

ReinstallJava takes a JVMArguments option. You can use it to pass heap size like so:

In[1]:= Needs["JLink`"]

In[2]:= Options[ReinstallJava]

Out[2]= {ClassPath -> Automatic, CommandLine -> Automatic, 
 JVMArguments -> None, ForceLaunch -> False, Default -> Automatic, 
 CreateExtraLinks -> Automatic, "Asynchronous" -> Automatic}

In[3]:= ?JVMArguments

JVMArguments is an option to InstallJava that
allows you to specify additional command-line
arguments passed to the Java virtual machine at
startup. The string you specify is added to the
command line used to launch Java. You can use this
option to specify properties with the standard -D
syntax, such as "-Dsome.property=true". This
option is not supported on Mac OSX. >>

In[4]:= LoadJavaClass["java.lang.Runtime"];

In[5]:= java`lang`Runtime`getRuntime[]@maxMemory[]

Out[5]= 238616576

In[6]:= ReinstallJava[JVMArguments -> "-Xmx64g"];

In[7]:= LoadJavaClass["java.lang.Runtime"];

In[8]:= java`lang`Runtime`getRuntime[]@maxMemory[]

Out[8]= 61084008448

(I once figured this out in desperation by reading through the code in C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\Links\JLink\Kernel. After noticing it was listed in Options[ReinstallJava] it seemed kind of obvious…)

like image 150
andrewdotn Avatar answered Sep 21 '22 00:09

andrewdotn