【问题标题】:Mathematica & J/Link: Memory Constraints?Mathematica & J/Link:内存限制?
【发布时间】:2009-06-14 14:26:02
【问题描述】:

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

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

Mathematica 函数ReinstallJava 采用命令行参数。我试着做

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

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

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

【问题讨论】:

  • 你的机器有多少物理内存?
  • 32 GB - 肯定超过 320 MB

标签: java wolfram-mathematica jlink


【解决方案1】:

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\Kernel 中的代码绝望地发现了这一点。注意到它在Options[ReinstallJava] 中列出后,这似乎很明显......)

【讨论】:

    【解决方案2】:

    对于 Mac OS X 用户,替换

    ReinstallJava[JVMArguments -> "-Xmx64g"];
    

    通过

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-28
      • 2011-10-10
      • 2022-06-13
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      相关资源
      最近更新 更多