diff --git a/src/Luna.jl b/src/Luna.jl index e1cafe10..18d194f3 100644 --- a/src/Luna.jl +++ b/src/Luna.jl @@ -36,7 +36,8 @@ end Dictionary of global settings for `Luna`. """ -settings = Dict{String, Any}("fftw_flag" => FFTW.PATIENT) +settings = Dict{String, Any}("fftw_flag" => FFTW.PATIENT, + "fftw_threads" => 0) """ set_fftw_mode(mode) @@ -58,6 +59,21 @@ function set_fftw_mode(mode) settings["fftw_flag"] = flag end +""" + set_fftw_threads(nthr) + +Set number of threads to be used by FFTW. If set to `0`, the number of threads used by +FFTW is determined automatically (see [`Utils.FFTWthreads()`](@ref)) +""" +function set_fftw_threads(nthr=0) + settings["fftw_threads"] = nthr + FFTW.set_num_threads(Utils.FFTWthreads()) +end + +function __init__() + set_fftw_threads() +end + include("Utils.jl") include("Scans.jl") include("Output.jl") diff --git a/src/Utils.jl b/src/Utils.jl index 374d3171..dad9fc76 100644 --- a/src/Utils.jl +++ b/src/Utils.jl @@ -5,7 +5,7 @@ import Logging import LibGit2 import Pidfile: mkpidlock import HDF5 -import Luna: @hlock +import Luna: @hlock, settings function git_commit() try @@ -60,8 +60,17 @@ function sourcecode() return out end +function FFTWthreads() + if Threads.nthreads() == 1 + 1 + else + settings["fftw_threads"] == 0 ? 4*Threads.nthreads() : settings["fftw_threads"] + end +end + function loadFFTwisdom() - fpath = joinpath(cachedir(), "FFTWcache") + FFTW.set_num_threads(FFTWthreads()) + fpath = joinpath(cachedir(), "FFTWcache_$(FFTWthreads())threads") lockpath = joinpath(cachedir(), "FFTWlock") isdir(cachedir()) || mkpath(cachedir()) if isfile(fpath) @@ -69,17 +78,13 @@ function loadFFTwisdom() pidlock = mkpidlock(lockpath) ret = FFTW.import_wisdom(fpath) close(pidlock) - success = (ret != 0) - Logging.@info(success ? "FFTW wisdom loaded" : "Loading FFTW wisdom failed") - return success else Logging.@info("No FFTW wisdom found") - return false end end function saveFFTwisdom() - fpath = joinpath(cachedir(), "FFTWcache") + fpath = joinpath(cachedir(), "FFTWcache_$(FFTWthreads())threads") lockpath = joinpath(cachedir(), "FFTWlock") pidlock = mkpidlock(lockpath) isfile(fpath) && rm(fpath)