diff --git a/include/finufft/fftw_defs.h b/include/finufft/fftw_defs.h index 1771ff259..c5a28aeb8 100644 --- a/include/finufft/fftw_defs.h +++ b/include/finufft/fftw_defs.h @@ -38,11 +38,15 @@ #define FFTW_INIT FFTWIFY(init_threads) #define FFTW_PLAN_TH FFTWIFY(plan_with_nthreads) #define FFTW_CLEANUP_THREADS FFTWIFY(cleanup_threads) +#define FFTW_GET_NTHREADS FFTWIFY(planner_nthreads) +#define FFTW_PLAN_SF FFTWIFY(make_planner_thread_safe) #else // no OMP (no fftw{f}_threads or _omp), need dummy fftw threads calls... #define FFTW_INIT() #define FFTW_PLAN_TH(x) #define FFTW_CLEANUP_THREADS() +#define FFTW_GET_NTHREADS() +#define FFTW_PLAN_SF() #endif #endif // FFTW_DEFS_H diff --git a/src/finufft.cpp b/src/finufft.cpp index b71acce87..48d4a7a73 100644 --- a/src/finufft.cpp +++ b/src/finufft.cpp @@ -664,6 +664,7 @@ int FINUFFT_MAKEPLAN(int type, int dim, BIGINT *n_modes, int iflag, int ntrans, std::lock_guard lock(fftw_lock); if (!did_fftw_init) { FFTW_INIT(); // setup FFTW global state; should only do once + FFTW_PLAN_SF(); did_fftw_init = true; // ensure other FINUFFT threads don't clash } } @@ -760,10 +761,12 @@ int FINUFFT_MAKEPLAN(int type, int dim, BIGINT *n_modes, int iflag, int ntrans, // set it just for our one plan and then revert to the user value. // Unfortunately fftw_planner_nthreads wasn't introduced until fftw 3.3.9, and // there isn't a convenient mechanism to probe the version + int prev_nthr_fft = FFTW_GET_NTHREADS(); FFTW_PLAN_TH(nthr_fft); p->fftwPlan = FFTW_PLAN_MANY_DFT(dim, ns, p->batchSize, (FFTW_CPX *)p->fwBatch, NULL, 1, p->nf, (FFTW_CPX *)p->fwBatch, NULL, 1, p->nf, p->fftSign, p->opts.fftw); + FFTW_PLAN_TH(prev_nthr_fft); } if (p->opts.debug) printf("[%s] FFTW plan (mode %d, nthr=%d):\t%.3g s\n", __func__, p->opts.fftw,