JuliaMath / JuliaMath/FFTW.jl

Slowdown and allocations in inverse 2D threaded FFTs

Open
#167 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
300
Forks
61
PR merge metrics
No merged PRs in 30d

Description

Certain inverse FFTs of multidimensional arrays run very slowly, and allocate considerably, when run with at least 4 threads.

The following snippet reproduces the issue, with `JULIA_NUM_THREADS=4`:

```julia
using Base.Threads
using BenchmarkTools
using FFTW
using LinearAlgebra

FFTW.set_num_threads(nthreads()) # nthreads() = 4

N = 2048
x = rand(N, N)
plan = plan_rfft(x)
y = plan * x

@btime mul!($y, $plan, $x) # 9.580 ms (80 allocations: 7.25 KiB)
@btime ldiv!($x, $plan, $y) # 119.497 ms (51862 allocations: 4.06 MiB)

```

This was tested on Julia 1.5.2 and FFTW.jl 1.2.4 (FFTW 3.3.9), on two different machines. With `N = 1024` and 4 threads the issue disappears, apparently because the planner chooses different parameters. With more threads, the issue is reproduced with lower values of `N` (e.g. `N = 512` and 8 threads reproduces the issue).

Apparently, a workaround is to set the `FFTW.MEASURE` flag when creating the forward plan. In fact it seems to be a problem of the FFTW planner, so maybe this issue rather belongs to the main FFTW3 repo?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Julia benchmark with four threads and the shown array sizes, comparing mul! and ldiv! allocations and timings. Read the FFTW.jl planning and threaded transform entry points, then determine whether the behavior is in the Julia bindings or FFTW itself. Done means identifying a reproducible cause and adding a regression test or documenting that the fix belongs upstream.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.