get_threads
C++ Function Reference
1 Signature
unsigned int BigDataStatMeth::get_threads(bool bparal, Rcpp::Nullable< int > threads=R_NilValue)2 Description
Determines number of threads for parallel operations.
3 Parameters
bparal(bool): Whether to use parallel processingthreads(Rcpp::Nullable< int >): Optional number of threads to use
4 Returns
unsigned int Number of threads to use
5 Details
bparalWhether to use parallel processing threadsOptional number of threads to use unsigned int Number of threads to use Thread determination:Respects OMP_THREAD_LIMIT and OMP_NUM_THREADS (CRAN compliance)Respects user-specified thread count, capped at system limitFalls back to single thread if parallel disabled
6 Call Graph
7 Source Code
NoteImplementation
File: inst/include/Utilities/Utilities.hpp • Lines 541-563
inline unsigned int get_threads(bool bparal, Rcpp::Nullable<int> threads = R_NilValue)
{
//.. 20260304 ..// unsigned int ithreads = std::thread::hardware_concurrency();
// getDTthreads(INT_MAX, false) honours OMP_THREAD_LIMIT / OMP_NUM_THREADS
unsigned int ithreads = static_cast<unsigned int>(getDTthreads(INT_MAX, false));
if(bparal == false) {
ithreads = 1;
} else {
if(threads.isNotNull()) {
//.. 20260304 ..// if ((unsigned)Rcpp::as<int>(threads) <= ithreads) {
//.. 20260304 ..// ithreads = Rcpp::as<int>(threads);
//.. 20260304 ..// }
// Cap user request against system limit (respects OMP_THREAD_LIMIT)
unsigned int req = static_cast<unsigned int>(Rcpp::as<int>(threads));
ithreads = std::min(req, ithreads);
}
//.. 20260304 ..// else { ithreads = getDTthreads(ithreads, false); }
// ithreads already holds the correct auto value from getDTthreads()
}
return(ithreads);
}8 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = get_threads(...);