From: Joseph Cohen on 28 Jun 2010 19:19 I have an m-file function that uses a for-loop that repeats many times. Unfortunately, it runs rather slowly. I heard that transforming it into a MEX file could possibly speed it up. I tried doing this automatically using the mcc -x command, but got this message: rror using ==> mcc Error: -x is no longer supported. The MATLAB Compiler no longer generates MEX files because there is no longer any performance advantage to doing so: the MATLAB JIT accelerates M-files by default. To hide proprietary algorithms, use the PCODE functi Is the fact that "there is no longer any performance advantage to doing so" correct? Or should I go ahead and manually create a MEX file anyway?
From: Matt Fig on 28 Jun 2010 19:36 There are performance advantages to MEX files, with the caveat that the magnitude of the advantage will depend on the skills of the MATLAB programmer, the C programmer, and the compiler used. Like vectorization vs. FOR loops, the matter is not so simple.
From: James Tursa on 28 Jun 2010 19:44 "Joseph Cohen" <hypergrapes(a)hotmail.com> wrote in message <i0balq$1bs$1(a)fred.mathworks.com>... > I have an m-file function that uses a for-loop that repeats many times. Unfortunately, it runs rather slowly. I heard that transforming it into a MEX file could possibly speed it up. I tried doing this automatically using the mcc -x command, but got this message: > > rror using ==> mcc > Error: -x is no longer supported. The MATLAB Compiler no > longer generates > MEX files because there is no longer any performance > advantage to doing so: the > MATLAB JIT accelerates M-files by default. > To hide proprietary algorithms, use the PCODE functi > > Is the fact that "there is no longer any performance advantage to doing so" correct? Or should I go ahead and manually create a MEX file anyway? See my reply to this same question on the following thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/285498#757669 James Tursa
From: Max on 29 Jun 2010 04:59 > Is the fact that "there is no longer any performance advantage to doing so" correct? Or should I go ahead and manually create a MEX file anyway? I tried to raise the same question here and asked people to run simple test to maybe shade some light on this issue (no responses so far) http://www.mathworks.com/matlabcentral/newsreader/view_thread/285498#757701 I guess the easiest way to find the answer to this question is find somebody with an older version of Matlab and ask him to run "mcc -x" on your source code. Then you can easily transfer compiled mex files to the latest version of matlab and compare performance.
From: Jan Simon on 29 Jun 2010 05:25
Dear Joseph, > Is the fact that "there is no longer any performance advantage to doing so" correct? Or should I go ahead and manually create a MEX file anyway? Before creating a C/C++/Fortran-Mex file, try to optimize your Matlab code. Preallocation, vectorization, move as much work outside the loop as possible, prefer cloumnwise processing instead of rowwise data access, use temporary variables instead of accessing deeply nested cells or structs, etc... If this does not help any longer and you carefully observed the output of the profiler, than creating a Mex manually (not with mcc) can help. Sometimes this help dramatically. e.g. creating all combinations with 4 elements from a set of 10 elements: Here a Mex (FEX->VChooseK) is 400 times faster than Matlab's NCHOOSEK. Other tasks cannot be accelerated, e.g. the addition of two scalars or the multiplication of two matrices. In the first case the overhead of calling the Mex is too large, in the 2nd case Matlab calls the very fast ATLAS already. You could show us the source of your loop and hope to get some tips for accelration. KInd regards, Jan |