Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D cheb2leg (or more generally, support "region") #76

Open
dlfivefifty opened this issue Mar 14, 2023 · 2 comments
Open

2D cheb2leg (or more generally, support "region") #76

dlfivefifty opened this issue Mar 14, 2023 · 2 comments

Comments

@dlfivefifty
Copy link
Contributor

dlfivefifty commented Mar 14, 2023

FFTW allows specifying "regions", for multidimensional FFTs:

julia> X = randn(5,5,5);

julia> F = fft(X,(1,3));

julia> F[:,1,:]  fft(X[:,1,:]) # 2D FFT acting on 1st and 3rd dimension
true

It turns out I need this feature for Legendre transforms.... at the moment it just does 1D transforms:

julia> X = randn(5,5);

julia> cheb2leg(X)[:,1] == cheb2leg(X[:,1])
true

I can add it to FastTransforms.jl, e.g., if I need a 2D Legendre I can do

cheb2leg(cheb2leg(X')')

but I'm curious if this could be SIMD-optimised (or multithreaded) in C to make it faster?

@MikaelSlevinsky
Copy link
Owner

This would certainly be helpful to include in the interface, but I'm not sure that execution would end up being any faster than cheb2leg(cheb2leg(X')') apart from using plans and a temp array for the transpose.

The current plans are already OpenMP parallelized, so that explains why multi-column execution is maybe faster than expected (this is slightly less than half the 2D transform):

julia> n = 10_000; x = randn(n); p = plan_leg2cheb(Float64, n); lmul!(p, ldiv!(p, x)); @time lmul!(p, x);
  0.007975 seconds

julia> X = randn(n, n);

julia> lmul!(p, ldiv!(p, X)); @time lmul!(p, X);
  5.521245 seconds

julia> n*0.007975/5.52 # close to 18 -- my core count
14.447463768115943

@MikaelSlevinsky
Copy link
Owner

Ideally, we'd want a "cache-oblivious transpose." On a single machine, is this how FFTW does it? https://github.com/FFTW/fftw3/blob/e9c510bf92a4fa848982310d2ecc8c5701aa3f6a/kernel/transpose.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants