getDTthreads
C++ Function Reference
1 Signature
int getDTthreads(const int64_t n, const bool throttle)2 Description
Determines number of threads for parallel operations.
3 Parameters
n(const int64_t): Number of iterations/items to processthrottle(const bool): Whether to apply thread throttling
4 Returns
int Number of threads to use
5 Details
nNumber of iterations/items to process throttleWhether to apply thread throttling int Number of threads to use Thread allocation strategy:With throttling: Incremental thread activation based on workloadWithout throttling: Direct allocation based on available threadsRespects global thread limits
6 Call Graph
7 Source Code
NoteImplementation
File: inst/include/Utilities/openme-utils.hpp • Lines 173-183
inline int getDTthreads(const int64_t n, const bool throttle) {
initDTthreads();
// throttle==true : a number of iterations per thread (DTthrottle) is applied before a second thread is utilized
// throttle==false : parallel region is already pre-chunked such as in fread; e.g. two batches intended for two threads
if (n<1) return 1; // 0 or negative could be deliberate in calling code for edge cases where loop is not intended to run at all
int64_t ans = throttle ? 1+(n-1)/DTthrottle : // 1 thread for n<=1024, 2 thread for n<=2048, etc
n; // don't use 20 threads for just one or two batches
return ans>=DTthreads ? DTthreads : (int)ans; // apply limit in static local DTthreads saved there by initDTthreads() and setDTthreads()
}8 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = getDTthreads(...);