Skip to content

Commit 453aa11

Browse files
committed
Check which FFTW libraries are available
1 parent ef8fc5b commit 453aa11

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FFTW"
22
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
3-
version = "1.7.1"
3+
version = "1.7.2"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/FFTW.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import AbstractFFTs: Plan, ScaledPlan,
1111
fftshift, ifftshift,
1212
rfft_output_size, brfft_output_size,
1313
plan_inv, normalization
14+
import FFTW_jll
15+
import MKL_jll
1416

1517
export dct, idct, dct!, idct!, plan_dct, plan_idct, plan_dct!, plan_idct!
1618

src/providers.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
const valid_fftw_providers = if FFTW_jll.is_available() && MKL_jll.is_available()
2+
("fftw", "mkl")
3+
elseif FFTW_jll.is_available()
4+
("fftw",)
5+
elseif MKL_jll.is_available()
6+
("mkl",)
7+
else
8+
error("no valid FFTW library available")
9+
end
110

211
function get_provider()
312
# Note: we CANNOT do something like have the `default` value be `get(ENV, "JULIA_FFTW_PROVIDER", "fftw")` here.
413
# This is because the only way the Julia knows that a default has changed is if the values on-disk change; so
514
# if your "default" value can be changed from the outside, you quickly run into cache invalidation issues.
615
# So the default here _must_ be a constant.
7-
default_provider = "fftw"
16+
default_provider = first(valid_fftw_providers)
817

918
# Load the preference
1019
provider = @load_preference("provider", default_provider)
1120

1221
# Ensure the provider matches one of the ones we support
13-
if provider ("fftw", "mkl")
14-
@error("Invalid provider setting \"$(provider)\"; valid settings include [\"fftw\", \"mkl\"], defaulting to \"fftw\"")
22+
if provider valid_fftw_providers
23+
@error("Invalid provider setting \"$(provider)\"; valid settings include [$(join(map(x -> '"' * x * '"', valid_fftw_providers), ", "))]")
1524
provider = default_provider
1625
end
1726
return provider
@@ -34,8 +43,8 @@ Also supports `Preferences` sentinel values `nothing` and `missing`; see the doc
3443
`Preferences.set_preferences!()` for more information on what these values mean.
3544
"""
3645
function set_provider!(provider; export_prefs::Bool = false)
37-
if provider !== nothing && provider !== missing && provider ("fftw", "mkl")
38-
throw(ArgumentError("Invalid provider value '$(provider)'"))
46+
if provider !== nothing && provider !== missing && provider valid_fftw_providers
47+
throw(ArgumentError("Invalid provider value \"$(provider)\"; valid settings include [$(join(map(x -> '"' * x * '"', valid_fftw_providers), ", "))]"))
3948
end
4049
set_preferences!(@__MODULE__, "provider" => provider; export_prefs, force = true)
4150
if provider != fftw_provider
@@ -47,7 +56,6 @@ end
4756

4857
# If we're using fftw_jll, load it in
4958
@static if fftw_provider == "fftw"
50-
import FFTW_jll
5159
libfftw3[] = FFTW_jll.libfftw3_path
5260
libfftw3f[] = FFTW_jll.libfftw3f_path
5361

@@ -82,7 +90,6 @@ end
8290

8391
# If we're using MKL, load it in and set library paths appropriately.
8492
@static if fftw_provider == "mkl"
85-
import MKL_jll
8693
libfftw3[] = MKL_jll.libmkl_rt_path
8794
libfftw3f[] = MKL_jll.libmkl_rt_path
8895
const _last_num_threads = Ref(Cint(1))

0 commit comments

Comments
 (0)