数学与数学 J/Link:内存限制?

发布于 2024-07-24 01:14:07 字数 465 浏览 5 评论 0原文

我正在使用 Mathematica 及其 J/Link Java 接口进行计算密集型基准测试。

如果内存占用达到约 320 MB,基准测试就会停止,因为这似乎是极限,垃圾收集器需要越来越多的时间,最终会失败。

Mathematica 函数 ReinstallJava 采用参数命令行。 我尝试这样做

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

,但 Mathematica 似乎完全忽略了 -Xmx 选项。

如何为我的 java 程序设置 -Xmx 内存选项? 320MB的限制从何而来? 任何帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2024-07-31 01:14:07

ReinstallJava 采用 JVMArguments 选项。 您可以使用它来传递堆大小,如下所示:(

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

我曾经在绝望中通过阅读 C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\Links\JLink\KernelOptions[ReinstallJava] 中后,这似乎很明显......)

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…)

弱骨蛰伏 2024-07-31 01:14:07

对于 Mac OS X 用户,替换

ReinstallJava[JVMArguments -> "-Xmx64g"];

ReinstallJava[CommandLine -> "java", JVMArguments -> "-Xmx64g"];

For Mac OS X users, replace

ReinstallJava[JVMArguments -> "-Xmx64g"];

by

ReinstallJava[CommandLine -> "java", JVMArguments -> "-Xmx64g"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文