Skip to content

Commit 0fd60a0

Browse files
authored
Merge pull request #431 from lu1and10/omp-warning
Enforce nthreads = 1 for single threaded lib
2 parents 9744d14 + aa2a362 commit 0fd60a0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/finufft.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,16 @@ int FINUFFT_MAKEPLAN(int type, int dim, BIGINT* n_modes, int iflag,
591591
p->fftSign = (iflag>=0) ? 1 : -1; // clean up flag input
592592

593593
// choose overall # threads...
594-
int nthr = MY_OMP_GET_MAX_THREADS(); // use as many as OMP gives us
595-
if (p->opts.nthreads>0)
596-
nthr = p->opts.nthreads; // user override (no limit or check)
594+
int maxnthr = MY_OMP_GET_MAX_THREADS();
595+
int nthr = maxnthr; // use as many as OMP gives us
596+
if (p->opts.nthreads>0) {
597+
nthr = min(maxnthr,p->opts.nthreads); // user override up to max avail
598+
if (p->opts.nthreads > maxnthr) // if no OMP, maxnthr=1
599+
fprintf(stderr,"%s warning: user requested %d threads, but only %d threads available; enforcing nthreads=%d.\n",__func__,p->opts.nthreads,maxnthr,nthr);
600+
}
597601
p->opts.nthreads = nthr; // store actual # thr planned for
598-
602+
// (this sets all downstream spread/interp, 1dkernel, and FFT thread counts)
603+
599604
// choose batchSize for types 1,2 or 3... (uses int ceil(b/a)=1+(b-1)/a trick)
600605
if (p->opts.maxbatchsize==0) { // logic to auto-set best batchsize
601606
p->nbatch = 1+(ntrans-1)/nthr; // min # batches poss

0 commit comments

Comments
 (0)