Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

improve startup times of matlab executable

I have compiled a matlab standalone exe which I can run on any computer that has the MATLAB Compiler Runtime installed.

However starting the exe takes 20-30 seconds !

How can I measure the time accuratly and most important - how can I decrease it down to 1-2 seconds.

like image 517
Matthias Pospiech Avatar asked Oct 19 '12 11:10

Matthias Pospiech


People also ask

How do you make MATLAB open faster?

You probably need to adjust one of the license environment variables (LM_LICENSE_FILE or MLM_LICENSE_FILE) used by MATLAB, or else bypass them all together. There are also some instances in which your MATLAB preferences or Anti-Virus program may negatively impact startup times.

How long should MATLAB take to open?

Matlab requires 15 minutes to start up - MATLAB Answers - MATLAB Central.

Why is MATLAB running so slow?

Answers (1) MATLAB may be running slowly because you have a limited amount of RAM (i.e. under 128MB). The RAM used by MATLAB at runtime is between 40MB-60MB. The HELP browser can take up another 12MB. If you have limited memory (RAM), your processor may start using virtual memory (from your hard drive).

What is MATLAB Startup Accelerator?

When you install MathWorks® products on your computer, the installation includes a utility program that can speed up MATLAB® startup, called the MATLAB Startup Accelerator. By default, the installer configures this utility as a scheduled task on your computer that runs several times each day.


1 Answers

This is taken out of Yair Altman's blog:

A splash wrapper application can alleviates much of the pain of the slow startup of deployed (compiled) Matlab applications. A Splash window solution can be found here. While such a splash wrapper is indeed useful, it may also be possible to achieve an actual speedup of the compiled app’s startup using the MCR_CACHE_ROOT environment variable.

Normally, the MCR and the stand-alone executable is unpacked upon every startup in the user’s temp dir, and deleted when the user logs out. Apparently, when the MCR_CACHE_ROOT environment variable is set, these files are only unpacked once and kept for later reuse. If this report is indeed true, this could significantly speed up the startup time of a compiled application in subsequent invocations.

On Linux:

export MCR_CACHE_ROOT=/tmp/mcr_cache_root_$USER   # local to host
mkdir -p @MCR_CACHE_ROOT
./myExecutable

On Windows:

REM set MCR_CACHE_ROOT=%TEMP%
set MCR_CACHE_ROOT="C:\Documents and Settings\Yair\Matlab Cache\"
myExecutable.exe

There are also ways to set this env variable permanently on Windows if needed...

Setting MCR_CACHE_ROOT is especially important when running the executable from a network (NFS) location, since unpacking onto a network location could be quite slow. If the executable is run in parallel on different machines (for example, a computer cluster running a parallel program), then this might even cause lock-outs when different clusters try to access the same network location. In both cases, the solution is to set MCR_CACHE_ROOT to a local folder (e.g., /tmp or %TEMP%). If you plan to reuse the extracted files again, then perhaps you should not delete the extracted files but reuse them. Otherwise, simply delete the temporary folder after the executable ends. In the following example, $RANDOM is a bash function that returns a random number:

export MCR_CACHE_ROOT=/tmp/mcr$RANDOM
./matlab_executable
rm -rf $MCR_CACHE_ROOT

Setting MCR_CACHE_ROOT can also be used to solve other performance bottlenecks in deployed applications, as explained in a MathWorks technical solution and a related article here.

In a related matter, compiled Matlab executable may fail with a Could not access the MCR component cache error, when Matlab cannot write in the MCR cache directory due to missing permission rights. This can be avoided by setting MCR_CACHE_ROOT to a non-existent directory, or to a folder in which there is global access permissions (/tmp or %TEMP% are usually such writable folders) – see related posts here and here.

like image 73
bla Avatar answered Dec 02 '22 19:12

bla