Skip to content

Commit 21498b0

Browse files
committed
Setting number of threads in rcpp_depth2Kbb too
1 parent 74569f4 commit 21498b0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

GBS-Chip-Gmatrix.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ if(!functions.only) {
441441
# Rcpp version only works with matrix as input, so fallback to R version otherwise
442442
if (is.matrix(depthvals) & alph < Inf) {
443443
if(alph < Inf) {
444-
result <- rcpp_depth2Kbb(depthvals, alph)
444+
result <- rcpp_depth2Kbb(depthvals, nThreads, alph)
445445
} else {
446446
result <- depth2K(depthvals)
447447
}

GBS-Rcpp-functions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@ Rcpp::NumericMatrix rcpp_depth2Kmodp(const Rcpp::NumericMatrix &depthvals, doubl
122122

123123
// C++ version of depth2Kbb function
124124
// [[Rcpp::export]]
125-
Rcpp::NumericMatrix rcpp_depth2Kbb(const Rcpp::NumericMatrix & depthvals, const double alph = 9999) {
125+
Rcpp::NumericMatrix rcpp_depth2Kbb(const Rcpp::NumericMatrix & depthvals, int nThreads, const double alph = 9999) {
126+
// set up number of threads
127+
nThreads = check_nThreads(nThreads);
126128
// create matrix for storing the result
127129
Rcpp::NumericMatrix result(depthvals.rows(), depthvals.cols());
128130
// size of the matrix
129131
const long size = depthvals.rows() * depthvals.cols();
130132
// precompute factor
131133
const double factor = 1.0/R::beta(alph, alph);
132134
// loop over the elements in parallel
133-
#pragma omp parallel for
135+
#pragma omp parallel for num_threads(nThreads)
134136
for (long i = 0; i < size; i++) {
135137
result[i] = R::beta(alph, depthvals[i] + alph) * factor;
136138
}

0 commit comments

Comments
 (0)