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

Provide a user level locking mechanism for FFTW #548

Merged
merged 11 commits into from
Sep 18, 2024

Commits on Sep 10, 2024

  1. Provide a user level locking mechanism for FFTW

    This commit provides a basic interface for the user to provide a lock around `fftw` calls. This
    is because any plan manipulation functions in `fftw` (make, destroy) are not thread-safe. See
    example code here:
    
    ```c++
     #include <vector>
     #include <mutex>
    
     #include <fftw3.h>
     #include <finufft.h>
     #include <omp.h>
    
    using namespace std;
    
     #define N 65384
    
    void locker(void *lck) { reinterpret_cast<recursive_mutex *>(lck)->lock(); }
    void unlocker(void *lck) { reinterpret_cast<recursive_mutex *>(lck)->unlock(); }
    
    int main() {
        int64_t Ns[3]; // guru describes mode array by vector [N1,N2..]
        Ns[0] = N;
        recursive_mutex lck;
    
        finufft_opts opts;
        finufft_default_opts(&opts);
        opts.nthreads = 1;
        opts.debug = 0;
        opts.fftw_lock_fun = locker;
        opts.fftw_unlock_fun = unlocker;
        opts.fftw_lock_data = reinterpret_cast<void *>(&lck);
    
        // random nonuniform points (x) and complex strengths (c)...
        vector<complex<double>> c(N);
    
        // init FFTW threads
        fftw_init_threads();
    
        // FFTW and FINUFFT execution using OpenMP parallelization
        #pragma omp parallel for
        for (int j = 0; j < 100; ++j) {
    
            // allocate output array for FFTW...
            vector<complex<double>> F1(N);
    
            // FFTW plan
            lck.lock();
            fftw_plan_with_nthreads(1);
            fftw_plan plan = fftw_plan_dft_1d(N, reinterpret_cast<fftw_complex*>(c.data()), reinterpret_cast<fftw_complex*>(F1.data()), FFTW_FORWARD, FFTW_ESTIMATE);
            fftw_destroy_plan(plan);
            lck.unlock();
    
            // FINUFFT plan
            finufft_plan nufftplan;
            finufft_makeplan(1, 1, Ns, 1, 1, 1e-6, &nufftplan, &opts);
            finufft_destroy(nufftplan);
        }
        return 0;
    }
    ```
    blackwer committed Sep 10, 2024
    Configuration menu
    Copy the full SHA
    1d9fb8e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    904baf3 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f129880 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    49675c0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    024bfa8 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    1e2c047 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    8594b65 View commit details
    Browse the repository at this point in the history

Commits on Sep 17, 2024

  1. Configuration menu
    Copy the full SHA
    3de4ed5 View commit details
    Browse the repository at this point in the history
  2. Revert "fftw_lock: share lock and init between float/double"

    This reverts commit 8594b65.
    blackwer committed Sep 17, 2024
    Configuration menu
    Copy the full SHA
    4dd9ad7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0dd134c View commit details
    Browse the repository at this point in the history

Commits on Sep 18, 2024

  1. Configuration menu
    Copy the full SHA
    5101cef View commit details
    Browse the repository at this point in the history