Created
December 1, 2019 17:15
-
-
Save antoine-levitt/88086895dd98f746d6c795c99a10fd9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FFTW | |
const MAX_THREADS = Threads.nthreads() | |
println("$(MAX_THREADS) threads") | |
N = 128 | |
M = 40 | |
println("N=$N, M=$M") | |
xsingle = randn(ComplexF64, N, N, N) | |
ysingle = copy(xsingle) | |
xmulti = randn(ComplexF64, N, N, N, M) | |
ymulti = copy(xmulti) | |
FFTW.set_num_threads(1) | |
Pmulti_nothread = plan_fft(xmulti, (1, 2, 3), flags=FFTW.MEASURE) | |
Psingle_nothread = plan_fft(xsingle, flags=FFTW.MEASURE) | |
FFTW.set_num_threads(MAX_THREADS) | |
Pmulti_thread = plan_fft(xmulti, (1, 2, 3), flags=FFTW.MEASURE) | |
Psingle_thread = plan_fft(xsingle, flags=FFTW.MEASURE) | |
function FFTs_auto(y, x, Pmulti) | |
mul!(y, Pmulti, x) | |
end | |
function FFTs_manual(y, x, Psingle) | |
for m = 1:size(x, 4) | |
@views mul!(y[:, :, :, m], Psingle, x[:, :, :, m]) | |
end | |
end | |
function FFTs_manual_threaded(y, x, Psingle) | |
Threads.@threads for m = 1:size(x, 4) | |
@views mul!(y[:, :, :, m], Psingle, x[:, :, :, m]) | |
end | |
end | |
println("Single FFT: no threads") | |
@btime mul!($ysingle, $Psingle_nothread, $xsingle) | |
println("Single FFT: threads") | |
@btime mul!($ysingle, $Psingle_thread, $xsingle) | |
println("Multiple FFTs: manual, no threads") | |
@btime FFTs_manual($ymulti, $xmulti, $Psingle_nothread) | |
println("Multiple FFTs: manual_threaded, no threads") | |
@btime FFTs_manual_threaded($ymulti, $xmulti, $Psingle_nothread) | |
println("Multiple FFTs: auto, no threads") | |
@btime FFTs_auto($ymulti, $xmulti, $Pmulti_nothread) | |
println("Multiple FFTs: manual, threads") | |
@btime FFTs_manual($ymulti, $xmulti, $Psingle_thread) | |
println("Multiple FFTs: manual_threaded, threads") | |
@btime FFTs_manual_threaded($ymulti, $xmulti, $Psingle_thread) | |
println("Multiple FFTs: auto, threads") | |
@btime FFTs_auto($ymulti, $xmulti, $Pmulti_thread) | |
nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment