Prev: spm_select
Next: MATLAB code speed
From: Jan Simon on 12 Mar 2010 05:28 Dear Oliver! > > You can distribute the calculations for the different columns to different threads, if your computer has multiple cores. E.g.: > > http://www.mathworks.com/matlabcentral/fileexchange/21233 > > shows how this can be programmed. > > For this simple iteration over each column, with no dependencies between each one, the easiest way (IMHO) to parallelize this is with an OpenMP pragma before the first (outer) for loop. And it's completely platform independent. You need a compiler with OpenMP support. E.g. the Express version of MSVC allows this after some cumbersome extra downloads only (my trials to follow the instructions from the net have not been successful). Kind regards, Jan
From: Oliver Woodford on 12 Mar 2010 06:22 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hnd4vl$83t$1(a)fred.mathworks.com>... > Dear Oliver! > > > > You can distribute the calculations for the different columns to different threads, if your computer has multiple cores. E.g.: > > > http://www.mathworks.com/matlabcentral/fileexchange/21233 > > > shows how this can be programmed. > > > > For this simple iteration over each column, with no dependencies between each one, the easiest way (IMHO) to parallelize this is with an OpenMP pragma before the first (outer) for loop. And it's completely platform independent. > > You need a compiler with OpenMP support. E.g. the Express version of MSVC allows this after some cumbersome extra downloads only (my trials to follow the instructions from the net have not been successful). > > Kind regards, Jan Shame. I was able to get the Express version of MSVC working admirably with OpenMP. If I recall correctly, there were two issues: Firstly downloading the extra libraries, which are in the Windows SDK. This went straighfowardly for me. I installed MSVC first, then the SDK. Secondly you need to set the OpenMP flag in the mexopts.bat file. Add the extra line: set COMPFLAGS=%COMPFLAGS% /openmp On linux, gcc has support for OpenMP built in, but you again need to add the flag in the mexopts.sh file. The extra line in this case is: CFLAGS="$CFLAGS -fopenmp" HTH, Oliver
From: Jan Simon on 12 Mar 2010 06:57 Dear Oliver! > > plhs[0] = mxCreateDoubleMatrix(1, n, mxREAL); > James, I'm surprised a speed demon like you is using mxCreateDoubleMatrix like that. Since it sets the matrix to zero first it drags the whole matrix through the cache once, before you even write to it. Since you then set every entry later you don't need to do that. See a discussion on the subject, and solution, here: > http://wwwuser.gwdg.de/~mleuten/MATLABToolbox/CmexWrapper.html Although your arguments are convincing and I've expected a remarkable acceleration also, I cannot reproduce advantages for your method for Matlab 6.5, 7.7 and 7.8 using different compilers, e.g. OpenWatcom 1.8 and MSVC 2008 Express. Is it necessary to start Matlab with a specific memory manager? Kind regards, Jan
From: Jan Simon on 12 Mar 2010 07:08 Dear Oliver! > > You need a compiler with OpenMP support. E.g. the Express version of MSVC allows this after some cumbersome extra downloads only (my trials to follow the instructions from the net have not been successful). > > > > Kind regards, Jan > > Shame. I was able to get the Express version of MSVC working admirably with OpenMP. If I recall correctly, there were two issues: Firstly downloading the extra libraries, which are in the Windows SDK. This went straighfowardly for me. I installed MSVC first, then the SDK. Secondly you need to set the OpenMP flag in the mexopts.bat file. Add the extra line: > set COMPFLAGS=%COMPFLAGS% /openmp Shame - on the compiler or the user? I'll try it again. I assume you are using MSVC 2008? Do you have experiences with the GCC on Windows+MinGW or Cygwin and Mex compilations? Kind regards, Jan
From: Oliver Woodford on 12 Mar 2010 07:31
"Jan Simon" wrote > Shame - on the compiler or the user? Shame on no one. A shame for you, as OpenMP is great, once you are able to compile it. > I'll try it again. I assume you are using MSVC 2008? Yes (Express edition). > Do you have experiences with the GCC on Windows+MinGW or Cygwin and Mex compilations? No. Oliver |