def _init_threads(backend): # This function actually sets the backend and initializes. It returns zero on # success and 1 if given a valid backend but that cannot be loaded. It raises # an exception if called after the threading backend has already been set, or # if given an invalid backend. global _fftw_threaded_set global _fftw_threaded_lib global HAVE_FFTW_THREADED global _double_threaded_lib global _float_threaded_lib if _fftw_threaded_set: raise RuntimeError( "Threading backend for FFTW already set to {0}; cannot be changed". format(_fftw_threaded_lib)) try: double_threaded_libname = _fftw_threading_libnames[backend]['double'] float_threaded_libname = _fftw_threading_libnames[backend]['float'] except KeyError: raise ValueError( "Backend {0} for FFTW threading does not exist!".format(backend)) if double_threaded_libname is not None: try: # Note that the threaded libraries don't have their own pkg-config # files we must look for them wherever we look for double or single # FFTW itself. _double_threaded_lib = get_ctypes_library(double_threaded_libname, ['fftw3'], mode=FFTW_RTLD_MODE) _float_threaded_lib = get_ctypes_library(float_threaded_libname, ['fftw3f'], mode=FFTW_RTLD_MODE) if (_double_threaded_lib is None) or (_float_threaded_lib is None): err_str = 'Unable to load threaded libraries' err_str += f'{double_threaded_libname} or ' err_str += f'{float_threaded_libname}' raise RuntimeError(err_str) dret = _double_threaded_lib.fftw_init_threads() fret = _float_threaded_lib.fftwf_init_threads() # FFTW for some reason uses *0* to indicate failure. In C. if (dret == 0) or (fret == 0): return 1 HAVE_FFTW_THREADED = True _fftw_threaded_set = True _fftw_threaded_lib = backend return 0 except: return 1 else: # We get here when we were given the 'unthreaded' backend HAVE_FFTW_THREADED = False _fftw_threaded_set = True _fftw_threaded_lib = backend return 0
def _init_threads(backend): # This function actually sets the backend and initializes. It returns zero on # success and 1 if given a valid backend but that cannot be loaded. It raises # an exception if called after the threading backend has already been set, or # if given an invalid backend. global _fftw_threaded_set global _fftw_threaded_lib global HAVE_FFTW_THREADED global _double_threaded_lib global _float_threaded_lib if _fftw_threaded_set: raise RuntimeError( "Threading backend for FFTW already set to {0}; cannot be changed".format(_fftw_threaded_lib)) try: double_threaded_libname = _fftw_threading_libnames[backend]['double'] float_threaded_libname = _fftw_threading_libnames[backend]['float'] except KeyError: raise ValueError("Backend {0} for FFTW threading does not exist!".format(backend)) if double_threaded_libname is not None: try: # Note that the threaded libraries don't have their own pkg-config files; # we must look for them wherever we look for double or single FFTW itself _double_threaded_lib = get_ctypes_library(double_threaded_libname,['fftw3'],mode=ctypes.RTLD_GLOBAL) _float_threaded_lib = get_ctypes_library(float_threaded_libname,['fftw3f'],mode=ctypes.RTLD_GLOBAL) if (_double_threaded_lib is None) or (_float_threaded_lib is None): raise RuntimeError("Unable to load threaded libraries {0} or {1}".format(double_threaded_libname, float_threaded_libname)) dret = _double_threaded_lib.fftw_init_threads() fret = _float_threaded_lib.fftwf_init_threads() # FFTW for some reason uses *0* to indicate failure. In C. if (dret == 0) or (fret == 0): return 1 HAVE_FFTW_THREADED = True _fftw_threaded_set = True _fftw_threaded_lib = backend return 0 except: return 1 else: # We get here when we were given the 'unthreaded' backend HAVE_FFTW_THREADED = False _fftw_threaded_set = True _fftw_threaded_lib = backend return 0
FFTW_MEASURE = 0 FFTW_DESTROY_INPUT = 1 << 0 FFTW_UNALIGNED = 1 << 1 FFTW_CONSERVE_MEMORY = 1 << 2 FFTW_EXHAUSTIVE = 1 << 3 FFTW_PRESERVE_INPUT = 1 << 4 FFTW_PATIENT = 1 << 5 FFTW_ESTIMATE = 1 << 6 FFTW_WISDOM_ONLY = 1 << 21 # Load the single and double precision libraries # We need to construct them directly with CDLL so # we can give the RTLD_GLOBAL mode, which we must do # in order to use the threaded libraries as well. double_lib = get_ctypes_library('fftw3', ['fftw3'], mode=FFTW_RTLD_MODE) float_lib = get_ctypes_library('fftw3f', ['fftw3f'], mode=FFTW_RTLD_MODE) if (double_lib is None) or (float_lib is None): raise ImportError("Unable to find FFTW libraries") # Support for FFTW's two different threading backends _fftw_threaded_lib = None _fftw_threaded_set = False _double_threaded_lib = None _float_threaded_lib = None HAVE_FFTW_THREADED = False # Although we set the number of threads based on the scheme, # we need a private variable that records the last value used so # we know whether we need to call plan_with_nthreads() again.
FFTW_MEASURE = 0 FFTW_DESTROY_INPUT = 1 << 0 FFTW_UNALIGNED = 1 << 1 FFTW_CONSERVE_MEMORY = 1 << 2 FFTW_EXHAUSTIVE = 1 << 3 FFTW_PRESERVE_INPUT = 1 << 4 FFTW_PATIENT = 1 << 5 FFTW_ESTIMATE = 1 << 6 FFTW_WISDOM_ONLY = 1 << 21 # Load the single and double precision libraries # We need to construct them directly with CDLL so # we can give the RTLD_GLOBAL mode, which we must do # in order to use the threaded libraries as well. double_lib = get_ctypes_library('fftw3', ['fftw3']) float_lib = get_ctypes_library('fftw3f', ['fftw3f']) if (double_lib is None) or (float_lib is None): raise ImportError("Unable to find FFTW libraries") # Support for FFTW's two different threading backends _fftw_threaded_lib = None _fftw_threaded_set = False _double_threaded_lib = None _float_threaded_lib = None HAVE_FFTW_THREADED = False # Although we set the number of threads based on the scheme, # we need a private variable that records the last value used so # we know whether we need to call plan_with_nthreads() again.
FFTW_MEASURE = 0 FFTW_DESTROY_INPUT = 1 << 0 FFTW_UNALIGNED = 1 << 1 FFTW_CONSERVE_MEMORY = 1 << 2 FFTW_EXHAUSTIVE = 1 << 3 FFTW_PRESERVE_INPUT = 1 << 4 FFTW_PATIENT = 1 << 5 FFTW_ESTIMATE = 1 << 6 FFTW_WISDOM_ONLY = 1 << 21 # Load the single and double precision libraries # We need to construct them directly with CDLL so # we can give the RTLD_GLOBAL mode, which we must do # in order to use the threaded libraries as well. double_lib = get_ctypes_library('fftw3', ['fftw3'], mode=ctypes.RTLD_GLOBAL) float_lib = get_ctypes_library('fftw3f', ['fftw3f'], mode=ctypes.RTLD_GLOBAL) if (double_lib is None) or (float_lib is None): raise ImportError("Unable to find FFTW libraries") # Support for FFTW's two different threading backends _fftw_threaded_lib = None _fftw_threaded_set = False _double_threaded_lib = None _float_threaded_lib = None HAVE_FFTW_THREADED = False # Although we set the number of threads based on the scheme, # we need a private variable that records the last value used so # we know whether we need to call plan_with_nthreads() again.
FFTW_MEASURE = 0 FFTW_DESTROY_INPUT = 1 << 0 FFTW_UNALIGNED = 1 << 1 FFTW_CONSERVE_MEMORY = 1 << 2 FFTW_EXHAUSTIVE = 1 << 3 FFTW_PRESERVE_INPUT = 1 << 4 FFTW_PATIENT = 1 << 5 FFTW_ESTIMATE = 1 << 6 FFTW_WISDOM_ONLY = 1 << 21 # Load the single and double precision libraries # We need to construct them directly with CDLL so # we can give the RTLD_GLOBAL mode, which we must do # in order to use the threaded libraries as well. double_lib = get_ctypes_library('fftw3',['fftw3'],mode=ctypes.RTLD_GLOBAL) float_lib = get_ctypes_library('fftw3f',['fftw3f'],mode=ctypes.RTLD_GLOBAL) if (double_lib is None) or (float_lib is None): raise ImportError("Unable to find FFTW libraries") # Support for FFTW's two different threading backends _fftw_threaded_lib = None _fftw_threaded_set = False _double_threaded_lib = None _float_threaded_lib = None HAVE_FFTW_THREADED = False # Although we set the number of threads based on the scheme, # we need a private variable that records the last value used so # we know whether we need to call plan_with_nthreads() again.