You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rework nthr logic replacing #431: no cap on user o.nthreads override; ifndef _OPENMP hard nthr=1 override; warnings at the finufft level only; binsort controlled by spopts.sort_threads matching docs
Copy file name to clipboardExpand all lines: src/finufft.cpp
+13-6Lines changed: 13 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -591,15 +591,22 @@ int FINUFFT_MAKEPLAN(int type, int dim, BIGINT* n_modes, int iflag,
591
591
p->fftSign = (iflag>=0) ? 1 : -1; // clean up flag input
592
592
593
593
// choose overall # threads...
594
-
int maxnthr = MY_OMP_GET_MAX_THREADS();
595
-
int nthr = maxnthr; // use as many as OMP gives us
594
+
#ifdef _OPENMP
595
+
int ompmaxnthr = MY_OMP_GET_MAX_THREADS();
596
+
int nthr = ompmaxnthr; // default: use as many as OMP gives us
597
+
// (the above could be set, or suggested set, to 1 for small enough problems...)
596
598
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);
599
+
nthr = p->opts.nthreads; // user override, now without limit
600
+
if (p->opts.showwarn && (nthr > ompmaxnthr))
601
+
fprintf(stderr,"%s warning: using opts.nthreads=%d, more than the %d OpenMP claims available; note large nthreads can be slower.\n",__func__,nthr,ompmaxnthr);
600
602
}
603
+
#else
604
+
int nthr = 1; // always 1 thread (avoid segfault)
605
+
if (p->opts.nthreads>1)
606
+
fprintf(stderr,"%s warning: opts.nthreads=%d but library is single-threaded; ignoring!\n",__func__,p->opts.nthreads);
607
+
#endif
601
608
p->opts.nthreads = nthr; // store actual # thr planned for
602
-
// (this sets all downstream spread/interp, 1dkernel, and FFT thread counts)
609
+
// (this sets/limits all downstream spread/interp, 1dkernel, and FFT thread counts...)
603
610
604
611
// choose batchSize for types 1,2 or 3... (uses int ceil(b/a)=1+(b-1)/a trick)
605
612
if (p->opts.maxbatchsize==0) { // logic to auto-set best batchsize
0 commit comments