Skip to content

Commit edfdfc7

Browse files
committed
Export and document threading helpers
1 parent d23115c commit edfdfc7

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Imports: Rcpp (>= 0.11.0), stats, utils
3535
Suggests: Matrix, inline, tinytest, pkgKitten, microbenchmark
3636
URL: https://github.com/RcppCore/RcppEigen, https://dirk.eddelbuettel.com/code/rcpp.eigen.html
3737
BugReports: https://github.com/RcppCore/RcppEigen/issues
38+
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ useDynLib("RcppEigen", .registration=TRUE)
22

33
importFrom("Rcpp", "evalCpp")
44
importFrom("utils", "packageDescription", "package.skeleton")
5-
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt")
5+
importFrom("stats", "model.frame", "model.matrix", "model.response", "fitted", "coef", "printCoefmat", "pt", "na.omit")
66
export("fastLm",
77
"fastLmPure",
8-
"RcppEigen.package.skeleton"
8+
"RcppEigen.package.skeleton",
9+
"EigenNbThreads",
10+
"EigenSetNbThreads",
11+
"RcppEigen_throttle_cores",
12+
"RcppEigen_reset_cores"
913
)
1014

1115
S3method("fastLm", "default")

R/RcppExports.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ Eigen_SSE <- function() {
1313
.Call(`_RcppEigen_Eigen_SSE`)
1414
}
1515

16+
#' @rdname RcppEigen_throttle_cores
1617
EigenNbThreads <- function() {
1718
.Call(`_RcppEigen_EigenNbThreads`)
1819
}
1920

21+
#' @rdname RcppEigen_throttle_cores
2022
EigenSetNbThreads <- function(n) {
2123
invisible(.Call(`_RcppEigen_EigenSetNbThreads`, n))
2224
}

R/init.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535
##' Helper functions to throttle use of cores by RcppEigen-internal code.
3636
##' On package load, the initial value is saved and used to reset the value.
3737
##' @param n Integer value of desired cores, default is two
38+
##' @return Only \code{EigenNbThreads()} returns a value, the current value of
39+
##' the number of cores used. The other functions are invoked for their side-effect
40+
##' of affecting the core count.
41+
##' @seealso \code{\link{RcppEigen-package}}
3842
RcppEigen_throttle_cores <- function(n) {
3943
if (missing(n)) n <- .pkgenv[["nb_threads"]]
4044
EigenSetNbThreads(n)
4145
}
4246

43-
##'@ rdname RcppEigen_throttle_cores
47+
##' @rdname RcppEigen_throttle_cores
4448
RcppEigen_reset_cores <- function() {
4549
EigenSetNbThreads(.pkgenv[["nb_threads"]])
4650
}

man/RcppEigen-package.Rd

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ Rcpp/Eigen bridge
1616
other packages. The C++ source code and the R source code in this
1717
package are for illustration only.
1818

19-
As described at the Eigen project's home page,
20-
\url{http://eigen.tuxfamily.org/index.php?title=Main_Page}, Eigen is a versatile, fast, reliable
21-
and elegant collection of C++ classes for linear algebra.
19+
As described at the \href{https://libeigen.gitlab.io/}{Eigen project home
20+
page} , Eigen is a a C++ template library for linear algebra: matrices,
21+
vectors, numerical solvers, and related algorithms.
22+
}
23+
\section{Threading}{
24+
The Eigen library can take advantage of OpenMP to execute computations in
25+
parallel via multi-threaded code. The number of cores uses can be set (or
26+
retrieved) explicitly via helper functions \code{EigenSetNbThreads()} and
27+
\code{EigenNbThreads()}. A default value is stored at package startup; it
28+
recognises R option value \code{Ncpus} and environment variable
29+
\code{OMP_THREAD_LIMITS}. Additional helper functions
30+
\code{RcppEigen_throttle_cores()} and \code{RcppEigen_reset_cores()} are
31+
available to (temporarily) lower the number of cores uses and to reset to
32+
the package default value set at startup.
33+
}
34+
\seealso{
35+
\code{\link{RcppEigen_throttle_cores}}
2236
}
2337
\references{
2438
Douglas Bates and Dirk Eddelbuettel (2013). Fast and Elegant Numerical

man/RcppEigen_throttle_cores.Rd

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppEigen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ bool Eigen_SSE() {
4949
return Rcpp::wrap(Eigen::SimdInstructionSetsInUse());
5050
}
5151

52+
//' @rdname RcppEigen_throttle_cores
5253
// [[Rcpp::export]]
5354
int EigenNbThreads() {
5455
return Eigen::nbThreads();
5556
}
5657

58+
//' @rdname RcppEigen_throttle_cores
5759
// [[Rcpp::export]]
5860
void EigenSetNbThreads(int n) {
5961
Eigen::setNbThreads(n);

0 commit comments

Comments
 (0)