-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fftw_lock: add test for new fftw_lock
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <complex> | ||
#include <mutex> | ||
#include <vector> | ||
|
||
#include <fftw3.h> | ||
#include <finufft.h> | ||
#include <omp.h> | ||
|
||
constexpr int N = 65384; | ||
|
||
void locker(void *lck) { reinterpret_cast<std::mutex *>(lck)->lock(); } | ||
void unlocker(void *lck) { reinterpret_cast<std::mutex *>(lck)->unlock(); } | ||
|
||
int main() { | ||
int64_t Ns[3]; // guru describes mode array by vector [N1,N2..] | ||
Ns[0] = N; | ||
std::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)... | ||
std::vector<std::complex<double>> c(N); | ||
|
||
omp_set_num_threads(8); | ||
|
||
// 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... | ||
std::vector<std::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; | ||
} |