CC='xcrun -sdk macosx10.7 clang'
to
CC='llvm-gcc'
and make a likewise changes for CXX, using llvm-g++. The other neccessary change is to ensure the lines
CFLAGS="$CFLAGS -fopenmp" CXXFLAGS="$CXXFLAGS -fopenmp" LDFLAGS="$LDFLAGS -fopenmp"
are present.
Once that's taken care of, you should be able to compile a mex file that include OpenMP directives without any additional work; for straightforward C code that doesn't use any external libraries
mex your_omp_code.c -I${MATLABPATH}/extern/include
should be sufficient. As an example, consider the following code, that also makes use of GSL Library.
This code can then be compiled as:
mex omp_reduction_mex.c -I${GSLPATH}/include -I${MATLABPATH}/extern/include -L${GSLPATH}/lib -lgsl
The only subtlety I've found in this is that to set the number of threads, you need to open a shell, run
export OMP_NUM_THREADS=2 (or 4 or 8, etc.)
and then from within the same terminal, launch MATLAB. If you just launch MATLAB, it seems to grab the maximum number of possible threads. On my machine, which is dual core with hyperthreading, it gets 4.
NOTE: I was having some weird lock ups with my code. I found that switching from the llvm compliers with gcc frontend to just the MacPorts installed gcc (I have 4.7.3 on my machine) seemed to clear things up.