From 60e5169152ea4a899f19afa094950411c8644acb Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 25 Feb 2020 20:17:01 -0500 Subject: [PATCH] nthreads check should be outside of static if (#138) --- src/FFTW.jl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/FFTW.jl b/src/FFTW.jl index 900e85f..db1a16e 100644 --- a/src/FFTW.jl +++ b/src/FFTW.jl @@ -50,13 +50,15 @@ function __init__() if stat == 0 || statf == 0 error("could not initialize FFTW threads") end - @static if fftw_vendor == :fftw && nthreads() > 1 - ccall((:fftw_make_planner_thread_safe, libfftw3), Cvoid, ()) - ccall((:fftwf_make_planner_thread_safe, libfftw3f), Cvoid, ()) - cspawnloop = @cfunction(spawnloop, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, Cint, Ptr{Cvoid})) - ccall((:fftw_threads_set_callback, libfftw3), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), cspawnloop, C_NULL) - ccall((:fftwf_threads_set_callback, libfftw3f), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), cspawnloop, C_NULL) - set_num_threads(nthreads() * 4) # spawn more tasks than threads to help load-balancing + @static if fftw_vendor == :fftw + if nthreads() > 1 + ccall((:fftw_make_planner_thread_safe, libfftw3), Cvoid, ()) + ccall((:fftwf_make_planner_thread_safe, libfftw3f), Cvoid, ()) + cspawnloop = @cfunction(spawnloop, Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, Cint, Ptr{Cvoid})) + ccall((:fftw_threads_set_callback, libfftw3), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), cspawnloop, C_NULL) + ccall((:fftwf_threads_set_callback, libfftw3f), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), cspawnloop, C_NULL) + set_num_threads(nthreads() * 4) # spawn more tasks than threads to help load-balancing + end end end