Thread Subject:
Compiling Matlab for speed optimization

Subject: Compiling Matlab for speed optimization

From: Pat Finder

Date: 1 Aug, 2013 01:43:07

Message: 1 of 4

I have three matlab files that run, and test all possible combinations of several parameters.
(Yes, I need to test all combinations to validate my thesis work.)

I am running 2011b on MacOSX/64 bit.

I know that there are several compilation options: mex files, generating C code, deploying applications, and probably others.

I am considering something along the lines of:
1. Converting the *.m file into *.cc files. (Two are Matlab classes, one is the main.)
2. Compiling them for optimization.
3. Linking the mess together.

I've heard that this might not actually make the code run any faster because if you aren't careful you generate the byte codes that are interpreted by the Matlab runtime.

Questions:
1. Can I save time or not by converting the Matlab objects to C++?
2. Does anyone have any recommendations for paths through mcc to do this on Mac OSX/64 bit?

Subject: Compiling Matlab for speed optimization

From: dpb

Date: 1 Aug, 2013 02:25:48

Message: 2 of 4

On 7/31/2013 8:43 PM, Pat Finder wrote:
> I have three matlab files that run, and test all possible combinations
> of several parameters.
> (Yes, I need to test all combinations to validate my thesis work.)
>
> I am running 2011b on MacOSX/64 bit.
>
> I know that there are several compilation options: mex files, generating
> C code, deploying applications, and probably others.
>
> I am considering something along the lines of:
> 1. Converting the *.m file into *.cc files. (Two are Matlab classes, one
> is the main.)
> 2. Compiling them for optimization.
> 3. Linking the mess together.
>
> I've heard that this might not actually make the code run any faster
> because if you aren't careful you generate the byte codes that are
> interpreted by the Matlab runtime.
>
> Questions:
> 1. Can I save time or not by converting the Matlab objects to C++?
> 2. Does anyone have any recommendations for paths through mcc to do this
> on Mac OSX/64 bit?

1) Who knows...only after you've tried it will you be able to tell...

2) Not I; never run Mac

But, methinks you're putting the cart before the horse here--first
profile what you've got to see where the bottleneck is. There's no
point in worrying about optimizing what isn't the primary slowdown.

I'd suspect that the better chance of getting some speedup relatively
easily would be to take the results of the above and then

a) look at those sections for improvement in implementation, and
b) mex those functions that are the largest culprits and see how well
that addresses the problem.

The kicker in time-saving is almost always in figuring out better
algorithms, however, altho depending on what the cause of the time-use
is in Matlab it's certainly possible that simply mex-ing a portion can
have large benefits.

--

Subject: Compiling Matlab for speed optimization

From: Steven_Lord

Date: 1 Aug, 2013 14:00:49

Message: 3 of 4



"Pat Finder" <thomas@netacc.net> wrote in message
news:ktcefb$2e3$1@newscl01ah.mathworks.com...
> I have three matlab files that run, and test all possible combinations of
> several parameters.
> (Yes, I need to test all combinations to validate my thesis work.)
>
> I am running 2011b on MacOSX/64 bit.
>
> I know that there are several compilation options: mex files, generating C
> code, deploying applications, and probably others.
>
> I am considering something along the lines of:
> 1. Converting the *.m file into *.cc files. (Two are Matlab classes, one
> is the main.)
> 2. Compiling them for optimization.
> 3. Linking the mess together.
>
> I've heard that this might not actually make the code run any faster
> because if you aren't careful you generate the byte codes that are
> interpreted by the Matlab runtime.

MATLAB Compiler generates applications that use the MATLAB Common Runtime
(MCR) to execute code "as though" you were running it in MATLAB.

MATLAB Coder can generate standalone C or C++ code from a subset of the
MATLAB language. Neither MATLAB Compiler nor MATLAB Coder support all of the
MATLAB language and all the toolboxes, but MATLAB Compiler supports more
than MATLAB Coder does.

> Questions:
> 1. Can I save time or not by converting the Matlab objects to C++?

It depends on what you're doing. If you're using something that's not
supported by either MATLAB Compiler or MATLAB Coder (like symbolic
calculations using Symbolic Math Toolbox) then probably not. [Symbolic Math
Toolbox DOES have a function to convert individual symbolic expressions into
C code, CCODE, but you couldn't just throw a MATLAB program file into CCODE
and say "Generate this." It's more 'targeted' in a sense.]

> 2. Does anyone have any recommendations for paths through mcc to do this
> on Mac OSX/64 bit?

Before trying this, I recommend:

1) Using MATLAB Profiler to determine where the bottlenecks in your code
(for a smaller subset of your parameter sweep) are located and see if you
can optimize those bottlenecks.
2) Once you've identified the bottlenecks, if you can't figure out how to
improve their performance, describe what you're doing and show the group
some code. There are a lot of people here who enjoy "MATLAB golf" and
"MATLAB code racing" (making MATLAB code short and fast respectively.)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Compiling Matlab for speed optimization

From: Pat Finder

Date: 1 Aug, 2013 22:33:10

Message: 4 of 4

Thank you both for your replies. I'm running the profiler now.

The gist of what I'm trying to do is combinatorial selection. Given 40 things, which three are the best ones to combine? I have an algorithm that works well, but in order to compare my algorithm to "exhaustive search" I actually have to compare all possible combinations of 3 things, drawn from 40.

For example, of 40 genes which 3 genes best indicate the condition...

Thank you again.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mcc compiler optim... Pat Finder 1 Aug, 2013 01:44:10
rssFeed for this Thread

Contact us