Skip to content

Commit c712a38

Browse files
committed
omp_thread_count(): use limits from OpenMP runtime
omp_get_max_threads() will consult the default number of threads for the current nested parallelism layer, which is set either by the runtime or from the OMP_NUM_THREADS environment variable. omp_get_thread_limit() will consult the separate limit on the total number of threads, set by the OMP_THREAD_LIMIT environment variable.
1 parent 695d4eb commit c712a38

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ dMappedCSC extract_mapped_csc(Rcpp::S4 input) {
8484
int omp_thread_count() {
8585
int n = 0;
8686
#ifdef _OPENMP
87-
#pragma omp parallel reduction(+ : n)
87+
int max_threads = omp_get_max_threads(), thread_limit = omp_get_thread_limit();
88+
n = max_threads < thread_limit ? max_threads : thread_limit;
8889
#endif
89-
n += 1;
9090
return n;
9191
}
9292

0 commit comments

Comments
 (0)