# \`plan\_fft\` fails when Julia is built with Intel MKL?

**URL:** <https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284>\
**Category:** Internals & Design\
**Tags:** fftw\
**Created:** [June 15, 2017, 2:58am UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284 "2017-06-15T02:58:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 15, 2017, 2:58am UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/1 "2017-06-15T02:58:35Z")

</div>

I built Julia 0.5.2 with Intel MKL on macOS (with [some effort](https://github.com/JuliaLang/julia/issues/18167#issuecomment-308606070)) and am enjoying some nice speedups in 3D FFTs.

However, it appears that [`plan_fft`](https://docs.julialang.org/en/stable/stdlib/math/?highlight=plan_fft#Base.plan_fft) doesn’t work with MKL:

```julia
julia> Base.libfftw_name
"libmkl_rt"

julia> x = reshape(1:128 * 128 * 128, 128, 128, 128);

julia> @elapsed y = fft(x)
0.027606419

julia> p = plan_fft(x)
FFTW forward plan for 128×128×128 array of Complex{Float64}Error showing value of type Base.DFT.FFTW.cFFTWPlan{Complex{Float64},-1,false,3}:
ERROR: ccall: could not find function fftw_sprint_plan in library libmkl_rt
 in sprint_plan at ./fft/FFTW.jl:301 [inlined]
<snip>

```

From the FFTW [release notes](http://www.fftw.org/release-notes.html) appears `fftw_sprint_plan` is a function to “output a description of plan to a string” and isn’t (yet) available in MKL—it’s not listed in this [MKL manual](https://software.intel.com/en-us/mkl-developer-reference-fortran-2018-beta-one-dimensional-complex-to-complex-ffts).

I guess I’d like to know if anyone has gotten `plan_fft` function to work with MKL. If this is a bug in Base.DFT, I’ll dig into the source and see if I can suggest a fix.

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [June 15, 2017, 3:03pm UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/2 "2017-06-15T15:03:41Z")

</div>

I belive `fft` calls `plan_fft` in its internal. So that is strange…  
Why don’t you check the source code to see what `fft` is doing? I think you can easily find the function definition by doing `@edit fft(x)` or `@which fft(x)`.

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 15, 2017, 3:06pm UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/3 "2017-06-15T15:06:26Z")

</div>

> [@favba](#):
>
> I belive fft calls plan\_fft in its internal. So that is strange…

You are absolutely right. This is happening only because I left out the semicolon at the end—`plan_fft` ccalls `fftw_sprint_plan` only when `show`ing the result ([source](https://github.com/JuliaLang/julia/blob/a593118addf4a23957827fc3a450838469e01109/base/fft/FFTW.jl#L289-L299))!

```julia
julia> p = plan_fft(x);
# happy 😁

```

So it’s not `plan_fft`, but rather `show`ing a `FFTWPlan`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 15, 2017, 4:21pm UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/4 "2017-06-15T16:21:43Z")

</div>

Should be fixed in 0.6 ([https://github.com/JuliaLang/julia/pull/21546](https://github.com/JuliaLang/julia/pull/21546)) assuming that MKL does not claim to be FFTW 3.3.4+?

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 15, 2017, 4:26pm UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/5 "2017-06-15T16:26:50Z")

</div>

Argh! My search-engine-game was weak, sorry, and thank you 🙇‍♂️!

At an [MKL–FFTW](https://software.intel.com/en-us/articles/the-intel-math-kernel-library-and-its-fast-fourier-transform-routines/) overview, there’s a section, “Relationship between FFTW 3.3.4 API and Intel MKL provided DFTI (FORTRAN interfaces)” which makes me think MKL will be \<=3.3.4. But who knows 🤣

---

<div class="post-metadata">

**Author:** ![EthanAnderes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethananderes/32/2028_2.png) [@EthanAnderes](https://discourse.julialang.org/u/EthanAnderes)\
**Post date:** [September 28, 2017, 11:08pm UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/6 "2017-09-28T23:08:15Z")

</div>

I just got the latest MKL compiled with Julia v0.6.1-pre.3 and I seem to be getting the same errors (it appears MKL _is_ claiming to have FFTW 3.3.4). Any idea what/if I’m doing wrong?

BTW: sorry to be adding user questions to the development section but this seemed like the relevant place for it given the original question.

```julia
julia> m = rand(Float32,16384,16384);

julia> p = plan_rfft(m)
FFTW real-to-complex plan for 16384×16384 array of Float32Error showing value of type Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}:
ERROR: ccall: could not find function fftwf_sprint_plan in library libmkl_rt
Stacktrace:
 [1] sprint_plan(::Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}) at ./fft/FFTW.jl:295
 [2] show(::IOContext{Base.Terminals.TTYTerminal}, ::Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}) at ./fft/FFTW.jl:313
 [3] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}) at /Users/ethananderes/.julia/v0.6/OhMyREPL/src/output_prompt_overwrite.jl:8
 [4] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}) at ./REPL.jl:125
 [5] display(::Base.DFT.FFTW.rFFTWPlan{Float32,-1,false,2}) at ./multimedia.jl:194

```

```julia
julia> FFTW.version
v"3.3.4"

julia> Base.libfftw_name
"libmkl_rt"

julia> versioninfo()
Julia Version 0.6.1-pre.3
Commit 4aa661a0c1* (2017-09-14 17:43 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin17.0.0)
  CPU: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  WORD_SIZE: 64
  BLAS: libmkl_rt
  LAPACK: libmkl_rt
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

```

---

<div class="post-metadata">

**Author:** ![mfsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfsch/32/7242_2.png) [@mfsch](https://discourse.julialang.org/u/mfsch)\
**Post date:** [October 1, 2017, 12:30am UTC](https://discourse.julialang.org/t/plan-fft-fails-when-julia-is-built-with-intel-mkl/4284/7 "2017-10-01T00:30:49Z")

</div>

I also still see the same issue with Julia v0.6 + MKL, as well as another issue when 3D arrays are passed to the MKL FFT. I have opened a new [issue](https://github.com/JuliaLang/julia/issues/23945) for these problems.
