@@ -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,23 +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.sort_threads >0 ) // user override, now without limit
271- maxnthr = opts.sort_threads ; // maxnthr = the max threads sorting could use
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
272275 // (we don't print warning here, since: no showwarn in spread_opts, and finufft
273276 // already warned about it. spreadinterp-only advanced users will miss a warning)
274277 if (opts.sort ==1 || (opts.sort ==2 && better_to_sort)) {
275278 // store a good permutation ordering of all NU pts (dim=1,2 or 3)
276279 int sort_debug = (opts.debug >=2 ); // show timing output?
277- int sort_nthr = opts.sort_threads ; // 0, or proposed max # threads for sorting
280+ int sort_nthr = opts.sort_threads ; // 0, or user max # threads for sort
278281#ifndef _OPENMP
279- sort_nthr = 1 ; // if single-threaded lib, override user
282+ sort_nthr = 1 ; // if single-threaded lib, override user
280283#endif
281284 if (sort_nthr==0 ) // multithreaded auto choice: when N>>M, one thread is better!
282- sort_nthr = (10 *M>N) ? maxnthr : 1 ; // heuristic
285+ sort_nthr = (10 *M>N) ? maxnthr : 1 ; // heuristic
283286 if (sort_nthr==1 )
284287 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);
285- else // sort_nthr>1, sets # threads
288+ else // sort_nthr>1, user fixes # threads (>=2)
286289 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);
287290 if (opts.debug )
288291 printf (" \t sorted (%d threads):\t %.3g s\n " ,sort_nthr,timer.elapsedsec ());
@@ -331,7 +334,7 @@ int spreadSorted(BIGINT* sort_indices,BIGINT N1, BIGINT N2, BIGINT N3,
331334 if (opts.nthreads >0 )
332335 nthr = opts.nthreads ; // user override, now without limit
333336#ifndef _OPENMP
334- nthr = 1 ; // if single-threaded lib, override user
337+ nthr = 1 ; // single-threaded lib must override user
335338#endif
336339 if (opts.debug )
337340 printf (" \t spread %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);
@@ -456,7 +459,7 @@ int interpSorted(BIGINT* sort_indices,BIGINT N1, BIGINT N2, BIGINT N3,
456459 if (opts.nthreads >0 )
457460 nthr = opts.nthreads ; // user override, now without limit
458461#ifndef _OPENMP
459- nthr = 1 ; // if single-threaded lib, override user
462+ nthr = 1 ; // single-threaded lib must override user
460463#endif
461464 if (opts.debug )
462465 printf (" \t interp %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);
0 commit comments