Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Export and document threading helpers
  • Loading branch information
eddelbuettel committed Dec 28, 2025
commit edfdfc729354ebb7cd16e8e9cc911546bac06b0e
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Imports: Rcpp (>= 0.11.0), stats, utils
Suggests: Matrix, inline, tinytest, pkgKitten, microbenchmark
URL: https://github.com/RcppCore/RcppEigen, https://dirk.eddelbuettel.com/code/rcpp.eigen.html
BugReports: https://github.com/RcppCore/RcppEigen/issues
RoxygenNote: 6.0.1
8 changes: 6 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ useDynLib("RcppEigen", .registration=TRUE)

importFrom("Rcpp", "evalCpp")
importFrom("utils", "packageDescription", "package.skeleton")
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt")
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt", "na.omit")
export("fastLm",
"fastLmPure",
"RcppEigen.package.skeleton"
"RcppEigen.package.skeleton",
"EigenNbThreads",
"EigenSetNbThreads",
"RcppEigen_throttle_cores",
"RcppEigen_reset_cores"
)

S3method("fastLm", "default")
Expand Down
2 changes: 2 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ Eigen_SSE <- function() {
.Call(`_RcppEigen_Eigen_SSE`)
}

#' @rdname RcppEigen_throttle_cores
EigenNbThreads <- function() {
.Call(`_RcppEigen_EigenNbThreads`)
}

#' @rdname RcppEigen_throttle_cores
EigenSetNbThreads <- function(n) {
invisible(.Call(`_RcppEigen_EigenSetNbThreads`, n))
}
Expand Down
6 changes: 5 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
##' Helper functions to throttle use of cores by RcppEigen-internal code.
##' On package load, the initial value is saved and used to reset the value.
##' @param n Integer value of desired cores, default is two
##' @return Only \code{EigenNbThreads()} returns a value, the current value of
##' the number of cores used. The other functions are invoked for their side-effect
##' of affecting the core count.
##' @seealso \code{\link{RcppEigen-package}}
RcppEigen_throttle_cores <- function(n) {
if (missing(n)) n <- .pkgenv[["nb_threads"]]
EigenSetNbThreads(n)
}

##'@ rdname RcppEigen_throttle_cores
##' @rdname RcppEigen_throttle_cores
RcppEigen_reset_cores <- function() {
EigenSetNbThreads(.pkgenv[["nb_threads"]])
}
20 changes: 17 additions & 3 deletions man/RcppEigen-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ Rcpp/Eigen bridge
other packages. The C++ source code and the R source code in this
package are for illustration only.

As described at the Eigen project's home page,
\url{http://eigen.tuxfamily.org/index.php?title=Main_Page}, Eigen is a versatile, fast, reliable
and elegant collection of C++ classes for linear algebra.
As described at the \href{https://libeigen.gitlab.io/}{Eigen project home
page} , Eigen is a a C++ template library for linear algebra: matrices,
Comment thread
eddelbuettel marked this conversation as resolved.
Outdated
vectors, numerical solvers, and related algorithms.
}
\section{Threading}{
The Eigen library can take advantage of OpenMP to execute computations in
parallel via multi-threaded code. The number of cores uses can be set (or
retrieved) explicitly via helper functions \code{EigenSetNbThreads()} and
\code{EigenNbThreads()}. A default value is stored at package startup; it
recognises R option value \code{Ncpus} and environment variable
\code{OMP_THREAD_LIMITS}. Additional helper functions
Comment thread
eddelbuettel marked this conversation as resolved.
Outdated
\code{RcppEigen_throttle_cores()} and \code{RcppEigen_reset_cores()} are
available to (temporarily) lower the number of cores uses and to reset to
the package default value set at startup.
}
\seealso{
\code{\link{RcppEigen_throttle_cores}}
}
\references{
Douglas Bates and Dirk Eddelbuettel (2013). Fast and Elegant Numerical
Expand Down
32 changes: 32 additions & 0 deletions man/RcppEigen_throttle_cores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/RcppEigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ bool Eigen_SSE() {
return Rcpp::wrap(Eigen::SimdInstructionSetsInUse());
}

//' @rdname RcppEigen_throttle_cores
// [[Rcpp::export]]
int EigenNbThreads() {
return Eigen::nbThreads();
}

//' @rdname RcppEigen_throttle_cores
// [[Rcpp::export]]
void EigenSetNbThreads(int n) {
Eigen::setNbThreads(n);
Expand Down