Fast Fourier Transforms (FFTs) in Numpy/SciPy are not threaded. Enthought Python is shipped with the Intel MKL numerical library, which is capable of threaded FFTs. How does one
The following code works for me with Enthought 7.3-1 (64-bit) on Windows 7 Ultimate 64-bit. I haven't benchmarked it but it certainly uses all cores at once rather than just one.
from ctypes import *
class Mkl_Fft:
c_double_p = POINTER(c_double)
def __init__(self,num_threads=8):
self.dfti = cdll.LoadLibrary("mk2_rt.dll")
self.dfti.MKL_Set_Num_Threads(num_threads)
self.Create = self.dfti.DftiCreateDescriptor_d_md
self.Commit = self.dfti.DftiCommitDescriptor
self.ComputeForward = self.dfti.DftiComputeForward
def fft(self,a):
Desc_Handle = c_void_p(0)
dims = (c_int*2)(*a.shape)
DFTI_COMPLEX = c_int(32)
rank = 2
self.Create(byref(Desc_Handle), DFTI_COMPLEX, rank, dims )
self.Commit(Desc_Handle)
self.ComputeForward(Desc_Handle, a.ctypes.data_as(self.c_double_p) )
Usage:
import numpy as np
a = np.ones( (32,32), dtype = complex128 )
fft = Mkl_Fft()
fft.fft(a)