Skip to content

Commit 10374e3

Browse files
committed
merge CHANGELOG
2 parents 5188ada + 79de084 commit 10374e3

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

.github/workflows/cmake_ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ jobs:
3838
steps:
3939
- uses: actions/checkout@v4
4040

41+
- name: Unlink gcc
42+
if: runner.os == 'macOS'
43+
run: |
44+
brew unlink gcc
45+
4146
- name: Setup Cpp
4247
uses: aminya/setup-cpp@v1
4348
with:

.github/workflows/python_wheel.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ jobs:
4646

4747
- name: Install gcc and fftw
4848
run: |
49-
brew install gcc fftw
49+
brew unlink gcc
50+
brew install gcc@13 fftw
5051
cp make.inc.macosx_gcc-12 make.inc
5152
echo "FC=gfortran-13" >> make.inc
5253
echo "CC=gcc-13" >> make.inc

CHANGELOG

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ If not stated, FINUFFT is assumed (cuFINUFFT <=1.3 is listed separately).
33

44
* cufinufft now supports modeord(type 1,2 only): 0 CMCL-style increasing mode
55
order, 1 FFT-style mode order.
6-
* CPU plan stage prevents now caps # threads at omp_get_max_threads (being 1
7-
for single-thread build); warns if this cap was activated (PR 431)
6+
* CPU plan stage allows any # threads, warns if > omp_get_max_threads(); or
7+
if single-threaded fixes nthr=1 and warns opts.nthreads>1 attempt.
8+
Sort now respects spread_opts.sort_threads not nthreads. Supercedes PR 431.
89
* new docs troubleshooting accuracy limitations due to condition number of the
910
NUFFT problem.
1011
* new sanity check on nj and nk (<0 or too big); new err code, tester, doc.

docs/opts.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ Diagnostic options
128128
Algorithm performance options
129129
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130130

131-
**nthreads**: Number of threads to use. This is capped at the number of available threads (eg, to prevent misuse of a single-threaded code). It then sets the number of threads FINUFFT will use in FFTW, bin-sorting, and spreading/interpolation steps. This number of threads also controls the batch size for vectorized transforms (ie ``ntr>1`` :ref:`here <c>`). Setting ``nthreads=0`` uses all threads available, usually recommended. However, for repeated small problems it can be advantageous to use a small number, even as small as 1.
131+
**nthreads**: (Ignored in single-threaded library builds.) If positive, sets the number of threads to use throughout (multi-threaded build of) library, or if ``0`` uses the maximum number of threads available according to OpenMP. In the positive case, no cap is placed on this number. This number of threads is passed to bin-sorting (which may choose to use less threads), but is adhered to in FFTW and spreading/interpolation steps. This number of threads (or 1 for single-threaded builds) also controls the batch size for vectorized transforms (ie ``ntr>1`` :ref:`here <c>`).
132+
For medium-to-large transforms, ``0`` is usually recommended.
133+
However, for (repeated) small transforms it can be advantageous to use a small number, even as small as ``1``.
132134

133135
**fftw**: FFTW planner flags. This number is simply passed to FFTW's planner;
134136
the flags are documented `here <http://www.fftw.org/fftw3_doc/Planner-Flags.html#Planner-Flags>`_.

src/finufft.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,22 @@ 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 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...)
596598
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);
600602
}
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
601608
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...)
603610

604611
// choose batchSize for types 1,2 or 3... (uses int ceil(b/a)=1+(b-1)/a trick)
605612
if (p->opts.maxbatchsize==0) { // logic to auto-set best batchsize

src/spreadinterp.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ int indexSort(BIGINT* sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M,
251251
ordering for the x-coords of NU pts, etc.
252252
returned value - whether a sort was done (1) or not (0).
253253
254-
Barnett 2017; split out by Melody Shih, Jun 2018.
254+
Barnett 2017; split out by Melody Shih, Jun 2018. Barnett nthr logic 2024.
255255
*/
256256
{
257257
CNTime timer;
@@ -266,19 +266,26 @@ int indexSort(BIGINT* sort_indices, BIGINT N1, BIGINT N2, BIGINT N3, BIGINT M,
266266

267267
timer.start(); // if needed, sort all the NU pts...
268268
int did_sort=0;
269-
int maxnthr = MY_OMP_GET_MAX_THREADS();
270-
if (opts.nthreads>0) // user override up to max avail
271-
maxnthr = min(maxnthr,opts.nthreads);
272-
269+
int maxnthr = MY_OMP_GET_MAX_THREADS(); // used if both below opts default
270+
if (opts.nthreads>0)
271+
maxnthr = opts.nthreads; // user nthreads overrides, without limit
272+
if (opts.sort_threads>0)
273+
maxnthr = opts.sort_threads; // high-priority override, also no limit
274+
// At this point: maxnthr = the max threads sorting could use
275+
// (we don't print warning here, since: no showwarn in spread_opts, and finufft
276+
// already warned about it. spreadinterp-only advanced users will miss a warning)
273277
if (opts.sort==1 || (opts.sort==2 && better_to_sort)) {
274278
// store a good permutation ordering of all NU pts (dim=1,2 or 3)
275279
int sort_debug = (opts.debug>=2); // show timing output?
276-
int sort_nthr = opts.sort_threads; // choose # threads for sorting
277-
if (sort_nthr==0) // use auto choice: when N>>M, one thread is better!
278-
sort_nthr = (10*M>N) ? maxnthr : 1; // heuristic
280+
int sort_nthr = opts.sort_threads; // 0, or user max # threads for sort
281+
#ifndef _OPENMP
282+
sort_nthr = 1; // if single-threaded lib, override user
283+
#endif
284+
if (sort_nthr==0) // multithreaded auto choice: when N>>M, one thread is better!
285+
sort_nthr = (10*M>N) ? maxnthr : 1; // heuristic
279286
if (sort_nthr==1)
280287
bin_sort_singlethread(sort_indices,M,kx,ky,kz,N1,N2,N3,opts.pirange,bin_size_x,bin_size_y,bin_size_z,sort_debug);
281-
else // sort_nthr>1, sets # threads
288+
else // sort_nthr>1, user fixes # threads (>=2)
282289
bin_sort_multithread(sort_indices,M,kx,ky,kz,N1,N2,N3,opts.pirange,bin_size_x,bin_size_y,bin_size_z,sort_debug,sort_nthr);
283290
if (opts.debug)
284291
printf("\tsorted (%d threads):\t%.3g s\n",sort_nthr,timer.elapsedsec());
@@ -323,9 +330,12 @@ int spreadSorted(BIGINT* sort_indices,BIGINT N1, BIGINT N2, BIGINT N3,
323330
int ndims = ndims_from_Ns(N1,N2,N3);
324331
BIGINT N=N1*N2*N3; // output array size
325332
int ns=opts.nspread; // abbrev. for w, kernel width
326-
int nthr = MY_OMP_GET_MAX_THREADS(); // # threads to use to spread
333+
int nthr = MY_OMP_GET_MAX_THREADS(); // guess # threads to use to spread
327334
if (opts.nthreads>0)
328-
nthr = min(nthr,opts.nthreads); // user override up to max avail
335+
nthr = opts.nthreads; // user override, now without limit
336+
#ifndef _OPENMP
337+
nthr = 1; // single-threaded lib must override user
338+
#endif
329339
if (opts.debug)
330340
printf("\tspread %dD (M=%lld; N1=%lld,N2=%lld,N3=%lld; pir=%d), nthr=%d\n",ndims,(long long)M,(long long)N1,(long long)N2,(long long)N3,opts.pirange,nthr);
331341

@@ -445,9 +455,12 @@ int interpSorted(BIGINT* sort_indices,BIGINT N1, BIGINT N2, BIGINT N3,
445455
int ndims = ndims_from_Ns(N1,N2,N3);
446456
int ns=opts.nspread; // abbrev. for w, kernel width
447457
FLT ns2 = (FLT)ns/2; // half spread width, used as stencil shift
448-
int nthr = MY_OMP_GET_MAX_THREADS(); // # threads to use to interp
458+
int nthr = MY_OMP_GET_MAX_THREADS(); // guess # threads to use to interp
449459
if (opts.nthreads>0)
450-
nthr = min(nthr,opts.nthreads); // user override up to max avail
460+
nthr = opts.nthreads; // user override, now without limit
461+
#ifndef _OPENMP
462+
nthr = 1; // single-threaded lib must override user
463+
#endif
451464
if (opts.debug)
452465
printf("\tinterp %dD (M=%lld; N1=%lld,N2=%lld,N3=%lld; pir=%d), nthr=%d\n",ndims,(long long)M,(long long)N1,(long long)N2,(long long)N3,opts.pirange,nthr);
453466

@@ -1292,7 +1305,7 @@ void bin_sort_multithread(BIGINT *ret, BIGINT M, FLT *kx, FLT *ky, FLT *kz,
12921305
nbins2 = isky ? N2/bin_size_y+1 : 1;
12931306
nbins3 = iskz ? N3/bin_size_z+1 : 1;
12941307
BIGINT nbins = nbins1*nbins2*nbins3;
1295-
if (nthr==0)
1308+
if (nthr==0) // should never happen in spreadinterp use
12961309
fprintf(stderr,"[%s] nthr (%d) must be positive!\n",__func__,nthr);
12971310
int nt = min(M,(BIGINT)nthr); // handle case of less points than threads
12981311
std::vector<BIGINT> brk(nt+1); // list of start NU pt indices per thread

0 commit comments

Comments
 (0)