What to do if you want to speed up Matlab code where a mex file is called inside for-loops? For example, you would like to simulate impulse responses for spherical microphone arrays using the SMIR Generator over a set of Monte Carlo experiments.
If your for-loops can be parallelized and you are working on a Linux machine, enabling compilation with OpenMP may be the answer. Make sure OpenMP is installed on your machine and you are compiling with a Matlab compatible version of gcc. Then compile your mex file in Matlab using the following command instead:
mex smir_generator_loop.cpp CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"