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

Planer: non-mutable reference enables threading #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miili
Copy link

@miili miili commented Oct 24, 2021

The plan is not modified by ..._execute_dft and alike (see https://www.fftw.org/fftw3_doc/Thread-safety.html)
Thus we can pass the plan &self by constant reference.

This enables multiple threaded ffts from the same plan.

    let mut fft2_r2c = R2CPlan32::aligned(&[window_size, window_size], Flag::ESTIMATE).unwrap();
    let mut fft2_c2r = C2RPlan32::aligned(&[window_size, window_size], Flag::ESTIMATE).unwrap();
    frames
        .par_iter_mut()
        .for_each(|(_frame, window_data)| unsafe {
            let frame_shape = [window_data.shape()[0], window_data.shape()[1]];
            let mut window_data_fft = AlignedVec::new((window_size / 2 + 1) * window_size);
            let mut window_data_slice = window_data.as_slice_mut().unwrap();
            fft2_r2c
                .r2c(&mut window_data_slice, &mut window_data_fft)
                .unwrap();
    });

@miili miili changed the title Planer: non-mutable reference to plan Planer: non-mutable reference enables threading Oct 24, 2021
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

Successfully merging this pull request may close these issues.

1 participant