Deployed Matlab application using significantly more memory than Matlab scripts
Asked Answered
A

1

8

I was testing a stand-alone application we developed in Matlab when I noticed that its memory usage, according to Windows Task Manager, was peaking several times above 16gb. I decided to run Matlab's profiler with profile -memory on on the scripts behind the compiled version to see where the memory peaks were occurring, using the exact same input. However, the highest peak memory it found was 2400860.00 Kb, or about 1/4 as much, for the function that essentially acts as the program's main().

Thus, I was wondering if people have noticed huge memory usage differences between running a compiled Matlab program and running the original scripts in Matlab. I noticed it took a lot longer running in Matlab, but I figured that was due to the profiler keeping track of all of the memory allocations and deallocations, rather than reading and writing to a swap space on disk.

Aesculapian answered 30/1, 2013 at 20:24 Comment(3)
Just to confirm: did you use the same computer for both runs? I did not encounter this before but perhaps something was optimized during compilation letting several things happen at once (thus requiring more memory). It may also be caused by the memory limit imposed on matlab in console mode. Last question: What peak do you reach when you already occupy 5~10 gig ram with another process before you run it?Duprey
what version of matlab?Whistling
You measured memory in two different ways. What does the Task Manager report for memory usage when you run profile -memory on?Rove
D
7

To make a real quick answer to this question. Yes, MATLAB compiled applications run with more overhead than MATLAB scripts.

This is because MATLAB deployed applications open up a version of MATLAB which is stored in the memory called the MCR. The MCR runs with more overhead than MATLAB.

One thing that I have found useful in situations like this is to recompile and see if that helps at all. If it doesn't, you could try to lower the memory usage by running calculations in segments.

This might be helpful for better memory usage: http://www.mathworks.com/help/matlab/matlab_prog/strategies-for-efficient-use-of-memory.html

Source:

Comment if you have questions.

Dunne answered 27/6, 2013 at 16:3 Comment(7)
-1: will give +1 if you add links to documentation or benchmarks showing that the MCR indeed runs with more overhead than in MATLAB.Interrogative
Added links and a help for memory usage.Dunne
MCR is just a stripped down version of MATLAB interpreter and necessary libraries. When you use MATLAB Compiler to generate a standalone application, at runtime it will still interpret and run the M-files that constitute the original program (those files are actually encoded and included in the exe file). So in terms of speed, it should be the same (it will take longer on first run to extract the CTF archive and startup the MCR runtime, just like the delay you see when you start the MATLAB IDE): undocumentedmatlab.com/blog/speeding-up-compiled-apps-startup.Spadework
..(continue long comment).. I see no reason why there should be a difference in memory usage either (though I havent done any tests to confirm that). I could be wrong though :) Consider contacting technical support to get a definitive answer.Spadework
I agree with contacting support. Their support is actually decent. But no matter what you think, the MCR is slower than actually running in MATLAB. My recommendation would be to switch to a different language. Once you begin to compile applications you are outside of MATLAB's intended use and will gain benefits from other languages.Dunne
@screenmutt: there is always the MATLAB Coder product which generates straight C/C++ code for you to compile. The code is portable and readable, and doesnt have any external dependencies (although not all functions/toolboxes are supported)Spadework
@Spadework Yeah, but that scares me. I have never had good luck with it. I always recommend moving away from MATLAB as soon as you are done with concepts.Dunne

© 2022 - 2024 — McMap. All rights reserved.