MCR invocation

I understand that MCR is invoked by Java if I call my compiled code via .NET and Java. If I call compiled code through c/c++ shared libraries, or COM libraries, or standalone applications, would MCR still be invoked by Java?
I'm getting the error 'Unable to start the JVM' when calling my compiled Matlab code from .NET. And I'm thinking to switch to other interfaces to avoid the error. Would it be possible?
Can anyone else who encountered the JVM error suggest a solution?
Thanks,

Answers (1)

Kaustubha Govind
Kaustubha Govind on 9 May 2011

1 vote

MATLAB and the MCR use JVM for some functionality. If the code that you'd like to compile does not use JVM functionality (you can verify this by starting MATLAB using "matlab -nojvm" from the system prompt and then running your code), you can compile your code using the mcc "-R -nojvm" option when compiling shared libraries or standalone applications.
With regards to why you see the "Unable to start the JVM" - I would recommend contacting MathWorks Tech Support so they can debug and diagnose the issue.

7 Comments

Shichang
Shichang on 9 May 2011
Thanks a lot for the information.
How can I specify the "-R -nojvm" option in the deploytool to my project? Or set it as the default mcc option?
Thanks,
Apologies - it looks like "-R" option is only available for standalone applications (see note on http://www.mathworks.com/help/toolbox/compiler/mcc.html). It also says "To override MCR options in the other MATLAB Compiler targets, use the mclInitializeApplication and mclTerminateApplication functions. For more information on these functions, see Calling a Shared Library (http://www.mathworks.com/help/toolbox/compiler/f2-972343.html#f2-999458)."
So it looks like you need to pass the "-nojvm" option into mclInitializeApplication (http://www.mathworks.com/help/toolbox/compiler/mclinitializeapplication.html).
Shichang
Shichang on 9 May 2011
I guess I won't be able to use this feature in the .NET Assembly project as it seems the option is only relevant to c/c++ API calls.
Is it possible to call the mclInitializeApplication in my C# code first with the -nojvm flag and then call the Matlab compiled .NET assembly?
Thanks again,
Sorry about that - mclInitializeApplication is indeed meant to be called from C/C++ applications. For a .NET assembly, it seems that you can do it by specify NOJVM as an assembly-wide attribute. See: http://www.mathworks.com/help/toolbox/dotnetbuilder/ug/bso89j3.html#bso89ma-1
Shichang
Shichang on 9 May 2011
By following the instruction from the URL link, I put the following line in my C# project (I assume anywhere in my project should be fine).
[assembly: MathWorks.MATLAB.NET.Utility.NOJVM(true), MathWorks.MATLAB.NET.Utility.LOGFILE("c:\temp\ngAnalytics.txt")]
When debugging, in the first place that I'm making a call to my Matlab function, I try to query MWMCR about the JVM. Apparently, JVM is enabled already by the true value of the following statement.
bool isMCRJVMEnabled = MathWorks.MATLAB.NET.Utility.MWMCR.IsMCRJVMEnabled();
Anything I'm doing wrong here? Or am I completely missing something?
If there's no way I can start MCR in .NET without JVM, I'd like to be able to adjust the runtime VM heap size. Any suggestions on doing that?
Thanks,
I'm sorry - I have little to no experience with Builder NE - have you tried contacting Tech Support about why using the NOJVM attribute doesn't work?
To increase Java heap space for the MCR, I believe you need to create a java.opts file just like for MATLAB (http://www.mathworks.com/support/solutions/en/data/1-18I2C/index.html) and place it in the $MCRROOT/bin/$ARCH directory. $MCRROOT is the MCR root directory (eg. C:\Program Files\MATLAB\MATLAB Compiler Runtime\) and $ARCH is your system
architecture, which you find by typing at the MATLAB Command Prompt: computer('arch')
Shichang
Shichang on 9 May 2011
I'm still waiting for Tech Support to write back to me. But of course they're much slower than your response.
Thanks a lot for your help anyways!

Sign in to comment.

Asked:

on 9 May 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!