Skip to content

Commit aa2a362

Browse files
committed
makeplan nthr logic so always caps nthr at get_omp; adjust Libin warning
1 parent 6f7c9c1 commit aa2a362

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/finufft.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +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)
597-
#ifndef _OPENMP
598-
if(nthr != 1) {
599-
nthr = 1;
600-
fprintf(stderr,"%s warning: Running finufft single threaded lib with nthreads != 1, enforcing nthreads = 1 ! \n",__func__);
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);
601600
}
602-
#endif
603601
p->opts.nthreads = nthr; // store actual # thr planned for
604-
602+
// (this sets all downstream spread/interp, 1dkernel, and FFT thread counts)
603+
605604
// choose batchSize for types 1,2 or 3... (uses int ceil(b/a)=1+(b-1)/a trick)
606605
if (p->opts.maxbatchsize==0) { // logic to auto-set best batchsize
607606
p->nbatch = 1+(ntrans-1)/nthr; // min # batches poss

0 commit comments

Comments
 (0)