How to control number of threads in FFT ?

Hello,
I want to vary the number of threads active in fft/fftn. I test on R2011b:
A = randn([2048 2048]);
maxNumCompThreads(N)
for a=1:100
A = fftn(A);
end
with different N. However, when varying N, nothing change in the core CPU monitoring: all the cores stay active.
It seems that the fftw library does not take into account the number of cores. Is there a way to specify this parameter in fftw ? Is there another way to define the number of active cores ?
Thank you.

Answers (2)

Don't know if this is any help, but:
maxNumCompThreads will be removed in a future release. Please remove
any instances of this function from your code.
Function was removed in 2012a:
It's possible that it was being systematically removed from functions such as fftn() prior to that release (?)

5 Comments

It is still there (just checked), but with a warning about being deprecated.
Oh, sorry, I didn't realise that the fftw library is not actually MatLab. It says that it can be compiled with a number of different multi-threading schemes, but MatLab won't have control over these.
So, Nicolas... I reckon if you're really desperate to do this, you're gonna have to MEX your own interface to FFTW, as well as mess with the FFTW code. First, get hold of the FFTW source code, modify it to allow the setting of a max thread-count (http://openmp.org/pipermail/omp/2007/000882.html) and compile (with OpenMP support). Then make your own fftn MEX function that takes a thread count parameter and sets it accordingly on your modified FFTW lib. Hopefully you have a _really_ good reason to warrant this effort.
Thanks Geoff. I also found: http://www.mathworks.com/matlabcentral/fileexchange/16314 which might be helpful in interfacing the fftw. I am not ready to go into it yet. I still think there might a way to specify the number of cores somewhere in Matlab (at least switching between single to all). In other way, what does the command -singleCompThread that enforce single thread at matlab launch ?
I add: fft can run either multi or single thread in single core or multi core on worker and matlab session respectively. That means to me that the fftw read somewhere which configuration it has to use to process (is it define in the wisdom?). Then what variable control this setting ?

Sign in to comment.

I just tried it out on my Windows install (R2011b). No matter what you set maxNumCompThreads to, fftn only ever uses one thread. It's simply not multithreaded.
edit: Something funky was happening with my system when I tested this -- it is multithreaded.

5 Comments

I disagree. I tested on R2011b and R2011a on windows and mac. Both use multithread when running in local. But my issue is actually that, when I run my code on the cluster, the workers are by default setup to work with one single thread and I can't take advantage of the 'implicit' fft multithreading despite that each worker has a whole quad-core CPU to work with.
That is interesting. On my system, Sandy Bridge core i5, win 7 64bit fftn only uses one core - you can watch as only one core activates in the performance manager. In contrast you can clearly see the multithreading from the likes of SVD
I just tried it on my own i5-2500 win7 64-bit, and all four cores are maxed-out. Have you been fluffing about with your system settings somewhere?
Well, after a reboot, it is multithreading properly. Something must have been amiss. It simply IS multithreaded
I think it also depends on the vector sizes.

Sign in to comment.

Categories

Asked:

on 10 Apr 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!