Skip to content

Commit

Permalink
Merge d060039 into 82c835d
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Nov 27, 2019
2 parents 82c835d + d060039 commit 76eaee1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions Project.toml
Expand Up @@ -13,6 +13,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
[compat]
AbstractFFTs = "0.5"
Conda = "1"
FFTW_jll = "3.3"
Reexport = "0.2"
julia = "1.3"

Expand Down
23 changes: 9 additions & 14 deletions src/FFTW.jl
Expand Up @@ -3,6 +3,7 @@ module FFTW
using LinearAlgebra, Reexport
import Libdl
@reexport using AbstractFFTs
using Base.Threads

import AbstractFFTs: Plan, ScaledPlan,
fft, ifft, bfft, fft!, ifft!, bfft!,
Expand All @@ -26,7 +27,7 @@ end
const fftw_vendor = occursin("libmkl_rt", libfftw3) ? :mkl : :fftw

# Use Julia partr threading backend if present
@static if fftw_vendor == :fftw && isdefined(Threads, Symbol("@spawn"))
@static if fftw_vendor == :fftw
# callback function that FFTW uses to launch `num` parallel
# tasks (FFTW/fftw3#175):
function spawnloop(f::Ptr{Cvoid}, fdata::Ptr{Cvoid}, elsize::Csize_t, num::Cint, callback_data::Ptr{Cvoid})
Expand All @@ -49,19 +50,13 @@ function __init__()
if stat == 0 || statf == 0
error("could not initialize FFTW threads")
end
@static if fftw_vendor == :fftw
if Threads.nthreads() > 1 # number of Julia threads is set when Julia is launched
ccall((:fftw_make_planner_thread_safe, libfftw3), Cvoid, ())
ccall((:fftwf_make_planner_thread_safe, libfftw3f), Cvoid, ())
end
@static if isdefined(Threads, Symbol("@spawn"))
if Threads.nthreads() > 1 # partr will give us our threads
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(Threads.nthreads() * 4) # spawn more tasks than threads to help load-balancing
end
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
end
end

Expand Down

0 comments on commit 76eaee1

Please sign in to comment.