Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling a mex-function

I have just rewritten a Matlab program in c++ as a mex-function to speed things up, with fantastic results. This optimization decision was a very very good idea, with up to a factor 20 speed up without threading. It still left me curious about what the mex-function was spending time on and wanting to identify possible bottlenecks.

I'm looking for a way to profile mex-functions. The matlab profiler is not much use, and the other profilers I've downloaded (both free and trial) all want an executable to run. I'm no mex-guru, but as far as I've understood the only way to run a mex is from within Matlab. The mex-function is compiled into a dll, but is called .mex64. So this problem should be similar to profiling a dll. To write the c++ mex-function I used a single-user VS2005 (i.e., not the team version), and am running on a x64-platform.

Does anyone know of a good way to profile a mex-function? What tool should I use and how do I use it when I start from within Matlab? Or is there any other way to profile the c++-code?

like image 674
AnnaR Avatar asked Aug 14 '09 09:08

AnnaR


People also ask

How do you use the MEX function?

To call a MEX function, use the name of the MEX file, without the file extension. The MEX file contains only one function or subroutine. The calling syntax depends on the input and output arguments defined by the MEX function. The MEX file must be on your MATLAB path.

What is profiling in MATLAB?

Profiling is a way to measure the time it takes to run your code and identify where MATLAB® spends the most time. After you identify which functions are consuming the most time, you can evaluate them for possible performance improvements. You also can profile your code to determine which lines of code do not run.

What does the Profiler track MATLAB?

Description. Use the Profiler to track execution time. Knowing the execution time of your MATLAB® code helps you to debug and optimize it.

What does MEX do in MATLAB?

mex filenames compiles and links one or more C++ source files written with the MATLAB Data API for C++ into a binary MEX file in the current folder.


1 Answers

the only way i've managed to do this is to separate out the function doing the work and writing a separate wrapper (instead of mexFunction) that loads .mat files with test data and runs as a standalone executable. this can then be profiled using e.g. gprof

like image 51
second Avatar answered Oct 11 '22 12:10

second